Daniel J. Summers d067f8983f Changes for beta10 (#5)
- Add In/InArray support
- Add ORDER BY support for `Find` functions
- Update dependencies
- Implement fixes identified via static analysis

Reviewed-on: #5
2024-09-27 02:15:00 +00:00

61 lines
1.5 KiB
PHP

<?php
/**
* @author Daniel J. Summers <daniel@bitbadger.solutions>
* @license MIT
*/
declare(strict_types=1);
namespace BitBadger\PDODocument;
/**
* The types of comparison operators allowed for JSON fields
*/
enum Op
{
/** Equals (=) */
case Equal;
/** Greater Than (>) */
case Greater;
/** Greater Than or Equal To (>=) */
case GreaterOrEqual;
/** Less Than (<) */
case Less;
/** Less Than or Equal To (<=) */
case LessOrEqual;
/** Not Equal to (<>) */
case NotEqual;
/** Between (BETWEEN) */
case Between;
/** In (IN) */
case In;
/** In Array (PostgreSQL - ?|, SQLite - EXISTS / json_each / IN) */
case InArray;
/** Exists (IS NOT NULL) */
case Exists;
/** Does Not Exist (IS NULL) */
case NotExists;
/**
* Get the SQL representation of this operator
*
* @return string The operator to use in SQL statements
*/
public function toSQL(): string
{
return match ($this) {
Op::Equal => "=",
Op::Greater => ">",
Op::GreaterOrEqual => ">=",
Op::Less => "<",
Op::LessOrEqual => "<=",
Op::NotEqual => "<>",
Op::Between => "BETWEEN",
Op::In => "IN",
Op::InArray => "??|", // The actual operator is ?|, but needs to be escaped by doubling
Op::Exists => "IS NOT NULL",
Op::NotExists => "IS NULL",
};
}
}