* @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", }; } }