repo
stringlengths
7
63
file_url
stringlengths
81
284
file_path
stringlengths
5
200
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:02:33
2026-01-05 05:24:06
truncated
bool
2 classes
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/workbench/routes/web.php
workbench/routes/web.php
<?php use Illuminate\Support\Facades\Route; /* |-------------------------------------------------------------------------- | Web Routes |-------------------------------------------------------------------------- | | Here is where you can register web routes for your application. These | routes are loaded by the RouteServiceProvider and all of them will | be assigned to the "web" middleware group. Make something great! | */ Route::get('/', function () { return view('welcome'); });
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/workbench/routes/api.php
workbench/routes/api.php
<?php use Illuminate\Http\Request; use Illuminate\Support\Facades\Route; /* |-------------------------------------------------------------------------- | API Routes |-------------------------------------------------------------------------- | | Here is where you can register API routes for your application. These | routes are loaded by the RouteServiceProvider and all of them will | be assigned to the "api" middleware group. Make something great! | */ // Route::middleware('auth:sanctum')->get('/user', function (Request $request) { // return $request->user(); // });
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/workbench/routes/console.php
workbench/routes/console.php
<?php use Illuminate\Foundation\Inspiring; use Illuminate\Support\Facades\Artisan; /* |-------------------------------------------------------------------------- | Console Routes |-------------------------------------------------------------------------- | | This file is where you may define all of your Closure based console | commands. Each Closure is bound to a command instance allowing a | simple approach to interacting with each command's IO methods. | */ // Artisan::command('inspire', function () { // $this->comment(Inspiring::quote()); // })->purpose('Display an inspiring quote');
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/workbench/database/migrations/2023_12_17_070618_create_books_table.php
workbench/database/migrations/2023_12_17_070618_create_books_table.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class() extends Migration { /** * Run the migrations. */ public function up(): void { Schema::create('books', function (Blueprint $table) { $table->id(); $table->string('title'); $table->text('description')->nullable(); $table->unsignedBigInteger('author_id'); $table->decimal('price', 8, 2); $table->unsignedInteger('year'); $table->timestamps(); $table->foreign('author_id')->references('id')->on('authors')->onDelete('cascade'); }); } /** * Reverse the migrations. */ public function down(): void { Schema::dropIfExists('books'); } };
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/workbench/database/migrations/2023_12_17_070147_create_authors_table.php
workbench/database/migrations/2023_12_17_070147_create_authors_table.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class() extends Migration { /** * Run the migrations. */ public function up(): void { Schema::create('authors', function (Blueprint $table) { $table->id(); $table->string('first_name'); $table->string('last_name'); $table->string('email')->unique(); $table->timestamps(); }); } /** * Reverse the migrations. */ public function down(): void { Schema::dropIfExists('authors'); } };
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/workbench/database/seeders/DatabaseSeeder.php
workbench/database/seeders/DatabaseSeeder.php
<?php namespace Workbench\Database\Seeders; use Illuminate\Database\Seeder; class DatabaseSeeder extends Seeder { /** * Run the database seeds. */ public function run(): void { // } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/DBFunction.php
src/DBFunction.php
<?php namespace sbamtr\LaravelQueryEnrich; use DateTime; use Illuminate\Database\Eloquent\Builder as EloquentBuilder; use Illuminate\Database\Query\Builder as QueryBuilder; use Illuminate\Database\Query\Expression; use Illuminate\Support\Facades\DB; use sbamtr\LaravelQueryEnrich\Exception\DatabaseNotSupportedException; /** * Abstract class representing a database function as an SQL expression. * * This class is used to represent SQL functions in a database-agnostic way and * includes methods for converting to SQL strings, configuring function behavior, * and escaping parameters for safe SQL execution. */ abstract class DBFunction extends Expression { public function __construct() { } /** * Indicates if the function result is a boolean value. * * @var bool */ protected const IS_BOOLEAN = false; /** * The alias to use for the function in an SQL query. * * @var string */ protected ?string $alias = null; /** * An array to keep track of SQLite configured functions. * * @var array */ protected static array $sqliteConfiguredFunctions = []; /** * Convert the function to an SQL string. * * @return string */ abstract protected function getQuery(): string; /** * Configure the function behavior specifically for SQLite. * * This method is intended to be overridden by subclasses to provide SQLite-specific configurations. * * @return void */ public function configureForSqlite(): void { // Write sqlite function configurations here } /** * Configure the function behavior for SQLite, ensuring it is done only once. * * If the function has already been configured for SQLite, it skips the configuration. * * @return void */ public function configureForSqliteOnce(): void { if (in_array(static::class, self::$sqliteConfiguredFunctions)) { return; } self::$sqliteConfiguredFunctions[] = static::class; $this->configureForSqlite(); } /** * Get the first character used to surround database identifiers. * * @return string */ public function getFirstSurroundingCharacter(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: return '`'; case EDatabaseEngine::PostgreSQL: case EDatabaseEngine::SQLite: return '"'; case EDatabaseEngine::SQLServer: return '['; } } /** * Get the last character used to surround database identifiers. * * @return string */ public function getLastSurroundingCharacter(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: return '`'; case EDatabaseEngine::PostgreSQL: case EDatabaseEngine::SQLite: return '"'; case EDatabaseEngine::SQLServer: return ']'; } } /** * Get the database engine used by the connection. * * @throws DatabaseNotSupportedException If the database engine is unknown. * * @return EDatabaseEngine */ public function getDatabaseEngine(): EDatabaseEngine { $driver = config('database.connections')[config('database.default')]['driver']; switch ($driver) { case 'mysql': case 'mariadb': return EDatabaseEngine::MySQL; case 'pgsql': return EDatabaseEngine::PostgreSQL; case 'sqlite': return EDatabaseEngine::SQLite; case 'sqlsrv': return EDatabaseEngine::SQLServer; default: throw new DatabaseNotSupportedException('Unknown database engine'); } } /** * Escape a parameter for safe inclusion in an SQL query. * * @param mixed $parameter The parameter to escape. * * @return mixed The escaped parameter. */ protected function escape(mixed $parameter): mixed { if (is_numeric($parameter)) { return $parameter + 0; } if ($parameter === null) { return 'null'; } if ($parameter instanceof DBFunction) { return $parameter->toSql(); } if ($parameter instanceof EloquentBuilder || $parameter instanceof QueryBuilder) { return '('.$parameter->toRawSql().')'; } if (is_array($parameter)) { $queryGrammar = DB::connection()->getQueryGrammar(); foreach ($parameter as &$value) { $value = $queryGrammar->escape(enum_value($value)); } return $parameter; } if ($parameter instanceof DateTime || is_string($parameter)) { $datetime = is_string($parameter) ? DateTime::createFromFormat('Y-m-d H:i:s', $parameter) : $parameter; if ($datetime) { $parameter = $datetime->format('Y-m-d H:i:s'); if ($this->getDatabaseEngine() == EDatabaseEngine::PostgreSQL) { $parameter = DB::escape($parameter); return "timestamp {$parameter}"; } } } if (is_object($parameter)) { $parameter = enum_value($parameter); } if (is_string($parameter)) { $parameter = addcslashes($parameter, '%'); } return DB::escape($parameter); } /** * Set the alias for the function and return the current instance. * * @param string $alias The alias to set. * * @return static */ public function as(string $alias): static { $this->alias = $alias; return $this; } /** * Convert the function to an SQL string with an optional alias. * * @return string */ public function toSql(): string { if ($this->getDatabaseEngine() == EDatabaseEngine::SQLite) { $this->configureForSqliteOnce(); } $sql = $this->getQuery(); $alias = $this->alias; $firstSurroundingCharacter = $this->getFirstSurroundingCharacter(); $lastSurroundingCharacter = $this->getLastSurroundingCharacter(); if ($alias !== null) { if ($this->getDatabaseEngine() == EDatabaseEngine::SQLServer && static::IS_BOOLEAN) { $sql = QE::case() ->when(QE::raw($sql)) ->then(1) ->else(0) ->getQuery(); } $sql .= " as $firstSurroundingCharacter$alias$lastSurroundingCharacter"; } return $sql; } public function __toString(): string { return $this->toSql(); } public function getValue(...$parameters) { return $this->toSql(); } /** * Get the SQL string for a function call with optional parameters. * * @param string $function The function name. * @param mixed $parameters The function parameters. * * @return string */ public function getFunctionCallSql(string $function, ?array $parameters = null): string { if ($parameters === null) { return "$function()"; } $parametersCount = count($parameters); for ($i = 0; $i < $parametersCount; $i++) { $parameters[$i] = $this->escape($parameters[$i]); } $implodedParameters = implode(', ', $parameters); return "$function($implodedParameters)"; } /** * Get the SQL string for an expression with parameters separated by an operator. * * @param string $operator The operator to separate parameters. * @param mixed $parameters The parameters for the expression. * * @return string */ public function getOperatorSeparatedSql(string $operator, array $parameters): string { $parametersCount = count($parameters); for ($i = 0; $i < $parametersCount; $i++) { $parameters[$i] = $this->escape($parameters[$i]); } $implodedParameters = implode(" $operator ", $parameters); return "($implodedParameters)"; } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/QE.php
src/QE.php
<?php namespace sbamtr\LaravelQueryEnrich; use Illuminate\Database\Eloquent\Builder as EloquentBuilder; use Illuminate\Database\Query\Builder as QueryBuilder; /** * @method static Column c(string $name) Retrieves a reference to a specific database column. * @method static Raw raw(string $sql, array $bindings = []) Represents a raw SQL expression with bindings. * @method static Advanced\CaseExpression\CaseWhenChain case() Creates a case expression for handling conditional logic. * @method static Advanced\Coalesce coalesce(...$parameters) Returns the first non-null value in a list. * @method static Advanced\Exists exists(QueryBuilder|EloquentBuilder $query) Checks if a subquery returns any results using the EXISTS condition. * @method static Advanced\_If if (DBFunction $condition, $valueIfTrue, $valueIfFalse) Implements an IF condition to introduce branching. * @method static Advanced\IsNull isNull($parameter) Checks if a value is NULL. * @method static Condition\Condition condition(mixed $parameter1, string $operator = null, mixed $parameter2 = null) Creates a condition. * @method static Operator\_And and (...$parameters) Combines multiple conditions with logical AND . * @method static Operator\_Or or (...$parameters) Combines multiple conditions with logical OR . * @method static Operator\Not not($parameter) Negates a condition with logical NOT. * @method static Date\AddDate addDate($subject, $value, Date\Unit $interval = Date\Unit::DAY) Adds a specific value to a date/datetime. * @method static Date\CurrentDate currentDate() Retrieves the current date. * @method static Date\CurrentTime currentTime() Retrieves the current time. * @method static Date\Date date($parameter) Extracts the date part from a datetime expression. * @method static Date\DateDiff dateDiff($date1, $date2) Returns the number of days between two date values. * @method static Date\DayOfWeek dayOfWeek($parameter) Returns the weekday index for a given date/datetime. * @method static Date\Hour hour($parameter) Returns the hour part for a given time/datetime. * @method static Date\Minute minute($parameter) Returns the minute part for a given time/datetime. * @method static Date\Month month($parameter) Returns the month part for a given date/datetime. * @method static Date\MonthName monthName($parameter) Returns the name of the month for a given date/datetime. * @method static Date\Now now() Returns the current date and time. * @method static Date\Second second($parameter) Returns the seconds part of a time/datetime. * @method static Date\SubDate subDate($subject, $value, Date\Unit $interval = Date\Unit::DAY) Subtracts a time/date interval from a date and then returns the date. * @method static Date\Time time($parameter) Extracts the time part from a given time/datetime. * @method static Date\Year year($parameter) Returns the week number for a given date/datetime. * @method static Numeric\Abs abs($parameter) Returns the absolute value of a number. * @method static Numeric\Acos acos($parameter) Returns the arc cosine of a number. * @method static Numeric\Add add(...$parameters) Adds multiple numeric parameters. * @method static Numeric\Asin asin($parameter) Returns the arc sine of a number. * @method static Numeric\Atan atan($parameter) Returns the arc tangent of a number. * @method static Numeric\Atan2 atan2($y, $x) Returns the arc tangent of two numbers. * @method static Numeric\Avg avg($parameter) Returns the average value of an expression. * @method static Numeric\Ceil ceil($parameter) Returns the smallest integer value that is >= to a number. * @method static Numeric\Cos cos($parameter) Returns the cosine of a number. * @method static Numeric\Cot cot($parameter) Returns the cotangent of a number. * @method static Numeric\Count count($parameter = '*') Returns the number of records returned by a select query. * @method static Numeric\DegreesToRadian degreesToRadian($parameter) Converts a degree value into radians. * @method static Numeric\Divide divide(...$parameters) Divide the first numeric parameter by subsequent numeric parameters. * @method static Numeric\Exp exp($parameter) Returns e raised to the power of a specified number. * @method static Numeric\Floor floor($parameter) Returns the largest integer value that is <= to a number. * @method static Numeric\Greatest greatest(...$parameters) Returns the greatest value of the list of arguments. * @method static Numeric\Least least(...$parameters) Returns the smallest value of the list of arguments. * @method static Numeric\Ln ln($parameter) Returns the natural logarithm of a number. * @method static Numeric\Log log($number, $base = 2) Returns the logarithm of a number * @method static Numeric\Max max($parameter) Returns the maximum value in a set of values. * @method static Numeric\Min min($parameter) Returns the minimum value in a set of values. * @method static Numeric\Mod mod($x, $y) Returns the remainder of a number divided by another number. * @method static Numeric\Multiply multiply(...$parameters) Multiply multiple numeric parameters. * @method static Numeric\PI pi() Returns the value of PI. * @method static Numeric\Pow pow($x, $y) Returns the value of a number raised to the power of another number. * @method static Numeric\RadianToDegrees radianToDegrees($parameter) Converts a value in radians to degrees. * @method static Numeric\Rand rand($seed = null) Returns a random number. * @method static Numeric\Round round($parameter, $decimals = 0) Rounds a number to a specified number of decimal places. * @method static Numeric\Sign sign($parameter) Returns the sign of a number. * @method static Numeric\Sin sin($parameter) Returns the sine of a number. * @method static Numeric\Sqrt sqrt($parameter) Returns the square root of a number. * @method static Numeric\Subtract subtract(...$parameters) Subtracts multiple numeric parameters. * @method static Numeric\Sum sum($parameter) Calculates the sum of a set of values. * @method static Numeric\Tan tan($parameter) Returns the tangent of a number. * @method static String\Concat concat(...$parameters) Adds two or more expressions together. * @method static String\ConcatWS concatWS($separator, ...$parameters) Adds two or more expressions together with a separator. * @method static String\contains contains($haystack, $needle) Determines if a given string contains a given substring. * @method static String\EndsWith endsWith($haystack, $needle) Determines if a given string ends with a given substring. * @method static String\Left left($string, $numberOfChars) Extracts a number of characters from a string (starting from left). * @method static String\Length length($parameter) Returns the length of a string. * @method static String\Lower lower($parameter) Converts a string to lower-case * @method static String\Ltrim ltrim($parameter) Removes leading spaces from a string. * @method static String\MD5 md5($parameter) Calculates the MD5 hash for a given parameter. * @method static String\PadLeft padLeft($string, $length, $pad = ' ') Left-pads a string with another string, to a certain length. * @method static String\PadRight padRight($string, $length, $pad = ' ') Right-pads a string with another string, to a certain length. * @method static String\Position position($subString, $string) Finds the position of a substring within a string. * @method static String\Repeat repeat($parameter, $number) Repeats a string a specified number of times. * @method static String\Replace replace($string, $substring, $newString) Replaces occurrences of a substring with a new string. * @method static String\Reverse reverse($parameter) Reverses the characters of a string. * @method static String\Right right($string, $numberOfChars) Extracts a number of characters from a string (starting from right). * @method static String\Rtrim rtrim($parameter) Removes trailing spaces from a string. * @method static String\Space space($parameter) Returns a string consisting of a specified number of spaces. * @method static String\StartsWith startsWith($haystack, $needle) Determines if a given string starts with a given substring. * @method static String\Substr substr($string, $start, $length = null) Extracts a substring from a string starting at a specified position with optional length. * @method static String\Trim trim($parameter) Removes leading and trailing spaces from a string. * @method static String\Upper upper($parameter) Converts a string to upper-case. */ class QE { const DATABASE_FUNCTIONS = [ 'c' => 'sbamtr\LaravelQueryEnrich\Column', 'raw' => 'sbamtr\LaravelQueryEnrich\Raw', 'case' => 'sbamtr\LaravelQueryEnrich\Advanced\CaseExpression\CaseWhenChain', 'if' => 'sbamtr\LaravelQueryEnrich\Advanced\_If', 'coalesce' => 'sbamtr\LaravelQueryEnrich\Advanced\Coalesce', 'isNull' => 'sbamtr\LaravelQueryEnrich\Advanced\IsNull', 'exists' => 'sbamtr\LaravelQueryEnrich\Advanced\Exists', 'and' => 'sbamtr\LaravelQueryEnrich\Operator\_And', 'or' => 'sbamtr\LaravelQueryEnrich\Operator\_Or', 'not' => 'sbamtr\LaravelQueryEnrich\Operator\Not', 'condition' => 'sbamtr\LaravelQueryEnrich\Condition\Condition', 'addDate' => 'sbamtr\LaravelQueryEnrich\Date\AddDate', 'currentDate' => 'sbamtr\LaravelQueryEnrich\Date\CurrentDate', 'currentTime' => 'sbamtr\LaravelQueryEnrich\Date\CurrentTime', 'date' => 'sbamtr\LaravelQueryEnrich\Date\Date', 'dateDiff' => 'sbamtr\LaravelQueryEnrich\Date\DateDiff', 'dayOfWeek' => 'sbamtr\LaravelQueryEnrich\Date\DayOfWeek', 'hour' => 'sbamtr\LaravelQueryEnrich\Date\Hour', 'minute' => 'sbamtr\LaravelQueryEnrich\Date\Minute', 'month' => 'sbamtr\LaravelQueryEnrich\Date\Month', 'monthName' => 'sbamtr\LaravelQueryEnrich\Date\MonthName', 'now' => 'sbamtr\LaravelQueryEnrich\Date\Now', 'second' => 'sbamtr\LaravelQueryEnrich\Date\Second', 'subDate' => 'sbamtr\LaravelQueryEnrich\Date\SubDate', 'time' => 'sbamtr\LaravelQueryEnrich\Date\Time', 'year' => 'sbamtr\LaravelQueryEnrich\Date\Year', 'abs' => 'sbamtr\LaravelQueryEnrich\Numeric\Abs', 'acos' => 'sbamtr\LaravelQueryEnrich\Numeric\Acos', 'add' => 'sbamtr\LaravelQueryEnrich\Numeric\Add', 'asin' => 'sbamtr\LaravelQueryEnrich\Numeric\Asin', 'atan' => 'sbamtr\LaravelQueryEnrich\Numeric\Atan', 'atan2' => 'sbamtr\LaravelQueryEnrich\Numeric\Atan2', 'avg' => 'sbamtr\LaravelQueryEnrich\Numeric\Avg', 'ceil' => 'sbamtr\LaravelQueryEnrich\Numeric\Ceil', 'cos' => 'sbamtr\LaravelQueryEnrich\Numeric\Cos', 'cot' => 'sbamtr\LaravelQueryEnrich\Numeric\Cot', 'count' => 'sbamtr\LaravelQueryEnrich\Numeric\Count', 'radianToDegrees' => 'sbamtr\LaravelQueryEnrich\Numeric\RadianToDegrees', 'divide' => 'sbamtr\LaravelQueryEnrich\Numeric\Divide', 'exp' => 'sbamtr\LaravelQueryEnrich\Numeric\Exp', 'floor' => 'sbamtr\LaravelQueryEnrich\Numeric\Floor', 'greatest' => 'sbamtr\LaravelQueryEnrich\Numeric\Greatest', 'least' => 'sbamtr\LaravelQueryEnrich\Numeric\Least', 'ln' => 'sbamtr\LaravelQueryEnrich\Numeric\Ln', 'log' => 'sbamtr\LaravelQueryEnrich\Numeric\Log', 'max' => 'sbamtr\LaravelQueryEnrich\Numeric\Max', 'min' => 'sbamtr\LaravelQueryEnrich\Numeric\Min', 'mod' => 'sbamtr\LaravelQueryEnrich\Numeric\Mod', 'multiply' => 'sbamtr\LaravelQueryEnrich\Numeric\Multiply', 'pi' => 'sbamtr\LaravelQueryEnrich\Numeric\PI', 'pow' => 'sbamtr\LaravelQueryEnrich\Numeric\Pow', 'degreesToRadian' => 'sbamtr\LaravelQueryEnrich\Numeric\DegreesToRadian', 'rand' => 'sbamtr\LaravelQueryEnrich\Numeric\Rand', 'round' => 'sbamtr\LaravelQueryEnrich\Numeric\Round', 'sign' => 'sbamtr\LaravelQueryEnrich\Numeric\Sign', 'sin' => 'sbamtr\LaravelQueryEnrich\Numeric\Sin', 'sqrt' => 'sbamtr\LaravelQueryEnrich\Numeric\Sqrt', 'subtract' => 'sbamtr\LaravelQueryEnrich\Numeric\Subtract', 'sum' => 'sbamtr\LaravelQueryEnrich\Numeric\Sum', 'tan' => 'sbamtr\LaravelQueryEnrich\Numeric\Tan', 'concat' => 'sbamtr\LaravelQueryEnrich\String\Concat', 'concatWS' => 'sbamtr\LaravelQueryEnrich\String\ConcatWS', 'contains' => 'sbamtr\LaravelQueryEnrich\String\Contains', 'endsWith' => 'sbamtr\LaravelQueryEnrich\String\EndsWith', 'left' => 'sbamtr\LaravelQueryEnrich\String\Left', 'length' => 'sbamtr\LaravelQueryEnrich\String\Length', 'lower' => 'sbamtr\LaravelQueryEnrich\String\Lower', 'ltrim' => 'sbamtr\LaravelQueryEnrich\String\Ltrim', 'md5' => 'sbamtr\LaravelQueryEnrich\String\MD5', 'padLeft' => 'sbamtr\LaravelQueryEnrich\String\PadLeft', 'padRight' => 'sbamtr\LaravelQueryEnrich\String\PadRight', 'position' => 'sbamtr\LaravelQueryEnrich\String\Position', 'repeat' => 'sbamtr\LaravelQueryEnrich\String\Repeat', 'replace' => 'sbamtr\LaravelQueryEnrich\String\Replace', 'reverse' => 'sbamtr\LaravelQueryEnrich\String\Reverse', 'right' => 'sbamtr\LaravelQueryEnrich\String\Right', 'rtrim' => 'sbamtr\LaravelQueryEnrich\String\Rtrim', 'space' => 'sbamtr\LaravelQueryEnrich\String\Space', 'startsWith' => 'sbamtr\LaravelQueryEnrich\String\StartsWith', 'substr' => 'sbamtr\LaravelQueryEnrich\String\Substr', 'trim' => 'sbamtr\LaravelQueryEnrich\String\Trim', 'upper' => 'sbamtr\LaravelQueryEnrich\String\Upper', ]; public static function __callStatic(string $name, array $arguments) { $class = self::DATABASE_FUNCTIONS[$name]; return new $class(...$arguments); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/helpers.php
src/helpers.php
<?php namespace sbamtr\LaravelQueryEnrich; /** * Create a reference to a database column. * * @param string $name The name of the database column. * * @return Column A Column instance representing the specified column. */ function c(string $name): Column { return new Column($name); } /** * @template TValue * * @param TValue $value * * @return ($value is \BackedEnum ? int|string : ($value is \UnitEnum ? string : TValue)) */ function enum_value($value) { return match (true) { $value instanceof \BackedEnum => $value->value, $value instanceof \UnitEnum => $value->name, default => $value, }; }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Raw.php
src/Raw.php
<?php namespace sbamtr\LaravelQueryEnrich; use Illuminate\Support\Str; use sbamtr\LaravelQueryEnrich\Exception\InvalidArgumentException; /** * Represents a raw SQL expression. * * @extends DBFunction */ class Raw extends DBFunction { /** * @var string The raw SQL string. */ private string $sql; /** * @var array The array of parameter bindings. */ private array $bindings; /** * Raw constructor. * * @param string $sql The raw SQL string. * @param array $bindings The array of parameter bindings. * * @throws InvalidArgumentException If the number of placeholders in the SQL string * does not match the number of bindings. */ public function __construct(string $sql, array $bindings = []) { // Validate the number of placeholders and bindings $questionMarksCount = Str::substrCount($sql, '?'); $bindingsCount = count($bindings); if ($questionMarksCount !== $bindingsCount) { throw new InvalidArgumentException('Invalid parameter number'); } $this->sql = $sql; $this->bindings = $bindings; } /** * Get the raw SQL string with bindings applied. * * @return string The raw SQL string. */ protected function getQuery(): string { $sql = $this->sql; $bindings = $this->bindings; // Replace placeholders with escaped bindings foreach ($bindings as $binding) { $binding = $this->escape($binding); $sql = Str::replaceFirst('?', $binding, $sql); } return $sql; } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/EDatabaseEngine.php
src/EDatabaseEngine.php
<?php namespace sbamtr\LaravelQueryEnrich; enum EDatabaseEngine { case MySQL; case PostgreSQL; case SQLite; case SQLServer; }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/QueryEnrichServiceProvider.php
src/QueryEnrichServiceProvider.php
<?php namespace sbamtr\LaravelQueryEnrich; use Illuminate\Support\ServiceProvider; class QueryEnrichServiceProvider extends ServiceProvider { public function boot() { } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Column.php
src/Column.php
<?php namespace sbamtr\LaravelQueryEnrich; /** * Retrieves a reference to a specific database column. */ class Column extends DBFunction { private string $name; public function __construct(string $name) { $this->name = $name; } protected function getQuery(): string { $firstSurroundingCharacter = $this->getFirstSurroundingCharacter(); $lastSurroundingCharacter = $this->getLastSurroundingCharacter(); return $firstSurroundingCharacter.str_replace( '.', "$lastSurroundingCharacter.$firstSurroundingCharacter", $this->name ).$lastSurroundingCharacter; } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Date/CurrentTime.php
src/Date/CurrentTime.php
<?php namespace sbamtr\LaravelQueryEnrich\Date; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; use sbamtr\LaravelQueryEnrich\QE; /** * Retrieves the current time. */ class CurrentTime extends DBFunction { protected function getQuery(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: return $this->getFunctionCallSql('current_time'); case EDatabaseEngine::PostgreSQL: return 'localtime::time(0)'; case EDatabaseEngine::SQLite: return $this->getFunctionCallSql('time'); case EDatabaseEngine::SQLServer: return QE::time( QE::raw($this->getFunctionCallSql('getdate')) )->getQuery(); } } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Date/DayOfWeek.php
src/Date/DayOfWeek.php
<?php namespace sbamtr\LaravelQueryEnrich\Date; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; use sbamtr\LaravelQueryEnrich\QE; /** * Returns the weekday index for a given date/datetime. */ class DayOfWeek extends DBFunction { private mixed $parameter; public function __construct($parameter) { $this->parameter = $parameter; } protected function getQuery(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: return $this->getFunctionCallSql('dayofweek', [$this->parameter]).'-1'; case EDatabaseEngine::PostgreSQL: $parameter = $this->escape($this->parameter); return "extract(dow from $parameter)"; case EDatabaseEngine::SQLite: return $this->getFunctionCallSql('strftime', [QE::raw("'%w'"), $this->parameter]); case EDatabaseEngine::SQLServer: return $this->getFunctionCallSql('datepart', [QE::raw('weekday'), $this->parameter]).'-1'; } } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Date/Month.php
src/Date/Month.php
<?php namespace sbamtr\LaravelQueryEnrich\Date; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; use sbamtr\LaravelQueryEnrich\QE; /** * Returns the month part for a given date/datetime. */ class Month extends DBFunction { private mixed $parameter; public function __construct(mixed $parameter) { $this->parameter = $parameter; } protected function getQuery(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: return $this->getFunctionCallSql('month', [$this->parameter]); case EDatabaseEngine::PostgreSQL: $parameter = $this->escape($this->parameter); return "extract(month from $parameter)"; case EDatabaseEngine::SQLite: return $this->getFunctionCallSql('strftime', [QE::raw("'%m'"), $this->parameter]); case EDatabaseEngine::SQLServer: return $this->getFunctionCallSql('datepart', [QE::raw('month'), $this->parameter]); } } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Date/CurrentDate.php
src/Date/CurrentDate.php
<?php namespace sbamtr\LaravelQueryEnrich\Date; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; use sbamtr\LaravelQueryEnrich\QE; /** * Retrieves the current date. */ class CurrentDate extends DBFunction { protected function getQuery(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: return $this->getFunctionCallSql('current_date'); case EDatabaseEngine::PostgreSQL: return 'current_date'; case EDatabaseEngine::SQLite: return $this->getFunctionCallSql('date'); case EDatabaseEngine::SQLServer: return QE::date( QE::raw($this->getFunctionCallSql('getdate')) )->getQuery(); } } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Date/MonthName.php
src/Date/MonthName.php
<?php namespace sbamtr\LaravelQueryEnrich\Date; use Carbon\Carbon; use Illuminate\Support\Facades\DB; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; use sbamtr\LaravelQueryEnrich\QE; /** * Returns the name of the month for a given date/datetime. */ class MonthName extends DBFunction { private mixed $parameter; public function __construct(mixed $parameter) { $this->parameter = $parameter; } protected function getQuery(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: case EDatabaseEngine::SQLite: return $this->getFunctionCallSql('monthname', [$this->parameter]); case EDatabaseEngine::PostgreSQL: $parameter = $this->escape($this->parameter); return "initcap(trim(to_char($parameter, 'month')))"; case EDatabaseEngine::SQLServer: return $this->getFunctionCallSql('datename', [QE::raw('month'), $this->parameter]); } } public function configureForSqlite(): void { DB::connection()->getPdo()->sqliteCreateFunction('monthname', function ($parameter) { return Carbon::parse($parameter)->monthName; }, 1); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Date/Hour.php
src/Date/Hour.php
<?php namespace sbamtr\LaravelQueryEnrich\Date; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; use sbamtr\LaravelQueryEnrich\QE; /** * Returns the hour part for a given time/datetime. */ class Hour extends DBFunction { private mixed $parameter; public function __construct(mixed $parameter) { $this->parameter = $parameter; } protected function getQuery(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: return $this->getFunctionCallSql('hour', [$this->parameter]); case EDatabaseEngine::PostgreSQL: $parameter = $this->escape($this->parameter); return "extract(hour from $parameter)"; case EDatabaseEngine::SQLite: return $this->getFunctionCallSql('strftime', [QE::raw("'%H'"), $this->parameter]); case EDatabaseEngine::SQLServer: return $this->getFunctionCallSql('datepart', [QE::raw('hour'), $this->parameter]); } } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Date/Date.php
src/Date/Date.php
<?php namespace sbamtr\LaravelQueryEnrich\Date; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; /** * Extracts the date part from a date/datetime expression. */ class Date extends DBFunction { private mixed $parameter; public function __construct(mixed $parameter) { $this->parameter = $parameter; } protected function getQuery(): string { if ($this->getDatabaseEngine() == EDatabaseEngine::SQLServer) { $parameter = $this->escape($this->parameter); return "cast($parameter as date)"; } return $this->getFunctionCallSql('date', [$this->parameter]); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Date/Time.php
src/Date/Time.php
<?php namespace sbamtr\LaravelQueryEnrich\Date; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; /** * Extracts the time part from a given time/datetime. */ class Time extends DBFunction { private mixed $parameter; public function __construct(mixed $parameter) { $this->parameter = $parameter; } protected function getQuery(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: case EDatabaseEngine::SQLite: return $this->getFunctionCallSql('time', [$this->parameter]); case EDatabaseEngine::PostgreSQL: $parameter = $this->escape($this->parameter); return "$parameter::time"; case EDatabaseEngine::SQLServer: $parameter = $this->escape($this->parameter); return "cast($parameter as time(0))"; } } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Date/DateDiff.php
src/Date/DateDiff.php
<?php namespace sbamtr\LaravelQueryEnrich\Date; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; use sbamtr\LaravelQueryEnrich\QE; /** * Returns the number of days between two date values. */ class DateDiff extends DBFunction { private mixed $date1; private mixed $date2; public function __construct(mixed $date1, mixed $date2) { $this->date1 = $date1; $this->date2 = $date2; } protected function getQuery(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: return $this->getFunctionCallSql('datediff', [$this->date1, $this->date2]); case EDatabaseEngine::SQLServer: return $this->getFunctionCallSql('datediff', [QE::raw('day'), $this->date2, $this->date1]); case EDatabaseEngine::PostgreSQL: $date1 = $this->escape($this->date1); $date2 = $this->escape($this->date2); return "DATE_PART('day', $date1::timestamp - $date2::timestamp)"; case EDatabaseEngine::SQLite: $date1 = $this->escape($this->date1); $date2 = $this->escape($this->date2); return "julianday($date1) - julianday($date2)"; } } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Date/Second.php
src/Date/Second.php
<?php namespace sbamtr\LaravelQueryEnrich\Date; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; use sbamtr\LaravelQueryEnrich\QE; /** * Returns the seconds part of a time/datetime. */ class Second extends DBFunction { private mixed $parameter; public function __construct(mixed $parameter) { $this->parameter = $parameter; } protected function getQuery(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: return $this->getFunctionCallSql('second', [$this->parameter]); case EDatabaseEngine::PostgreSQL: $parameter = $this->escape($this->parameter); return "extract(second from $parameter)"; case EDatabaseEngine::SQLite: return $this->getFunctionCallSql('strftime', [QE::raw("'%S'"), $this->parameter]); case EDatabaseEngine::SQLServer: return $this->getFunctionCallSql('datepart', [QE::raw('second'), $this->parameter]); } } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Date/Now.php
src/Date/Now.php
<?php namespace sbamtr\LaravelQueryEnrich\Date; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; /** * Returns the current date and time. */ class Now extends DBFunction { protected function getQuery(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: return $this->getFunctionCallSql('now'); case EDatabaseEngine::SQLServer: return $this->getFunctionCallSql('getdate'); case EDatabaseEngine::SQLite: return $this->getFunctionCallSql('datetime'); case EDatabaseEngine::PostgreSQL: return 'localtimestamp::timestamp(0)'; } } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Date/SubDate.php
src/Date/SubDate.php
<?php namespace sbamtr\LaravelQueryEnrich\Date; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; use sbamtr\LaravelQueryEnrich\QE; use function sbamtr\LaravelQueryEnrich\enum_value; /** * Subtracts a time/date interval from a date and then returns the date. */ class SubDate extends DBFunction { private mixed $subject; private mixed $_value; private Unit $interval; public function __construct(mixed $subject, mixed $value, Unit $interval = Unit::DAY) { $this->subject = $subject; $this->_value = $value; $this->interval = $interval; } protected function getQuery(): string { $subject = $this->subject; $value = $this->_value; $interval = $this->interval; if ($this->getDatabaseEngine() == EDatabaseEngine::SQLite || $this->getDatabaseEngine() == EDatabaseEngine::PostgreSQL ) { if ($interval == Unit::WEEK) { $interval = Unit::DAY; $value *= 7; } elseif ($interval == Unit::QUARTER) { $interval = Unit::MONTH; $value *= 3; } } $subject = $this->escape($subject); $value = $this->escape($value); $escapedInterval = enum_value($interval); switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: return "subdate($subject, INTERVAL $value $escapedInterval)"; case EDatabaseEngine::PostgreSQL: return "($subject - INTERVAL '$value $escapedInterval')"; case EDatabaseEngine::SQLite: case EDatabaseEngine::SQLServer: return QE::addDate($this->subject, -1 * $this->_value, $this->interval); } } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Date/Unit.php
src/Date/Unit.php
<?php namespace sbamtr\LaravelQueryEnrich\Date; enum Unit: string { case SECOND = 'second'; case MINUTE = 'minute'; case HOUR = 'hour'; case DAY = 'day'; case WEEK = 'week'; case MONTH = 'month'; case QUARTER = 'quarter'; case YEAR = 'year'; }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Date/AddDate.php
src/Date/AddDate.php
<?php namespace sbamtr\LaravelQueryEnrich\Date; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; use sbamtr\LaravelQueryEnrich\QE; use function sbamtr\LaravelQueryEnrich\enum_value; /** * Adds a specific value to a date/datetime. */ class AddDate extends DBFunction { private mixed $subject; private mixed $_value; private Unit $interval; public function __construct(mixed $subject, mixed $value, Unit $interval = Unit::DAY) { $this->subject = $subject; $this->_value = $value; $this->interval = $interval; } protected function getQuery(): string { $subject = $this->subject; $value = $this->_value; $interval = $this->interval; if ($this->getDatabaseEngine() == EDatabaseEngine::SQLite || $this->getDatabaseEngine() == EDatabaseEngine::PostgreSQL ) { if ($interval == Unit::WEEK) { $interval = Unit::DAY; $value *= 7; } elseif ($interval == Unit::QUARTER) { $interval = Unit::MONTH; $value *= 3; } } $subject = $this->escape($subject); $value = $this->escape($value); $escapedInterval = enum_value($interval); switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: return "adddate($subject, INTERVAL $value $escapedInterval)"; case EDatabaseEngine::PostgreSQL: return "($subject + INTERVAL '$value $escapedInterval')"; case EDatabaseEngine::SQLite: return "datetime($subject,'$value $escapedInterval')"; case EDatabaseEngine::SQLServer: return $this->getFunctionCallSql( 'convert', [ QE::raw($this->getFunctionCallSql('datetime2', [0])), QE::raw($this->getFunctionCallSql('dateadd', [QE::raw($escapedInterval), $this->_value, $this->subject])), ] ); } } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Date/Minute.php
src/Date/Minute.php
<?php namespace sbamtr\LaravelQueryEnrich\Date; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; use sbamtr\LaravelQueryEnrich\QE; /** * Returns the minute part for a given time/datetime. */ class Minute extends DBFunction { private mixed $parameter; public function __construct(mixed $parameter) { $this->parameter = $parameter; } protected function getQuery(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: return $this->getFunctionCallSql('minute', [$this->parameter]); case EDatabaseEngine::PostgreSQL: $parameter = $this->escape($this->parameter); return "extract(minute from $parameter)"; case EDatabaseEngine::SQLite: return $this->getFunctionCallSql('strftime', [QE::raw("'%M'"), $this->parameter]); case EDatabaseEngine::SQLServer: return $this->getFunctionCallSql('datepart', [QE::raw('minute'), $this->parameter]); } } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Date/Year.php
src/Date/Year.php
<?php namespace sbamtr\LaravelQueryEnrich\Date; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; use sbamtr\LaravelQueryEnrich\QE; /** * Returns the week number for a given date/datetime. */ class Year extends DBFunction { private mixed $parameter; public function __construct(mixed $parameter) { $this->parameter = $parameter; } protected function getQuery(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: return $this->getFunctionCallSql('year', [$this->parameter]); case EDatabaseEngine::PostgreSQL: $parameter = $this->escape($this->parameter); return "extract(year from $parameter)"; case EDatabaseEngine::SQLite: return $this->getFunctionCallSql('strftime', [QE::raw("'%Y'"), $this->parameter]); case EDatabaseEngine::SQLServer: return $this->getFunctionCallSql('datepart', [QE::raw('year'), $this->parameter]); } } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Exception/DatabaseNotSupportedException.php
src/Exception/DatabaseNotSupportedException.php
<?php namespace sbamtr\LaravelQueryEnrich\Exception; use RuntimeException; class DatabaseNotSupportedException extends RuntimeException { }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Exception/InvalidArgumentException.php
src/Exception/InvalidArgumentException.php
<?php namespace sbamtr\LaravelQueryEnrich\Exception; class InvalidArgumentException extends \InvalidArgumentException { }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Operator/_And.php
src/Operator/_And.php
<?php namespace sbamtr\LaravelQueryEnrich\Operator; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Combines multiple conditions with logical AND. */ class _And extends DBFunction { private array $parameters; public function __construct(...$parameters) { $this->parameters = $parameters; } protected function getQuery(): string { return $this->getOperatorSeparatedSql('and', $this->parameters); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Operator/Not.php
src/Operator/Not.php
<?php namespace sbamtr\LaravelQueryEnrich\Operator; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Negates a condition with logical NOT. */ class Not extends DBFunction { private mixed $parameter; public function __construct(mixed $parameter) { $this->parameter = $parameter; } protected function getQuery(): string { $parameter = $this->escape($this->parameter); return "not $parameter"; } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Operator/_Or.php
src/Operator/_Or.php
<?php namespace sbamtr\LaravelQueryEnrich\Operator; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Combines multiple conditions with logical OR . */ class _Or extends DBFunction { private array $parameters; public function __construct(...$parameters) { $this->parameters = $parameters; } protected function getQuery(): string { return $this->getOperatorSeparatedSql('or', $this->parameters); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Numeric/Sin.php
src/Numeric/Sin.php
<?php namespace sbamtr\LaravelQueryEnrich\Numeric; use Illuminate\Support\Facades\DB; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Returns the sine of a number. */ class Sin extends DBFunction { private mixed $parameter; public function __construct(mixed $parameter) { $this->parameter = $parameter; } protected function getQuery(): string { return $this->getFunctionCallSql('sin', [$this->parameter]); } public function configureForSqlite(): void { DB::connection()->getPdo()->sqliteCreateFunction('sin', 'sin', 1); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Numeric/DegreesToRadian.php
src/Numeric/DegreesToRadian.php
<?php namespace sbamtr\LaravelQueryEnrich\Numeric; use Illuminate\Support\Facades\DB; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; /** * Converts a degree value into radians. */ class DegreesToRadian extends DBFunction { private mixed $parameter; public function __construct(mixed $parameter) { $this->parameter = $parameter; } protected function getQuery(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: case EDatabaseEngine::PostgreSQL: case EDatabaseEngine::SQLite: return $this->getFunctionCallSql('radians', [$this->parameter]); case EDatabaseEngine::SQLServer: $parameter = $this->escape($this->parameter); return "$parameter * (pi() / 180)"; } } public function configureForSqlite(): void { DB::connection()->getPdo()->sqliteCreateFunction('radians', 'deg2rad', 1); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Numeric/Greatest.php
src/Numeric/Greatest.php
<?php namespace sbamtr\LaravelQueryEnrich\Numeric; use Illuminate\Support\Facades\DB; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; /** * Returns the greatest value of the list of arguments. */ class Greatest extends DBFunction { private array $parameters; public function __construct(...$parameters) { $this->parameters = $parameters; } protected function getQuery(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: case EDatabaseEngine::PostgreSQL: case EDatabaseEngine::SQLite: return $this->getFunctionCallSql('greatest', $this->parameters); case EDatabaseEngine::SQLServer: $parameters = $this->escape($this->parameters); $parametersString = '('.implode('),(', $parameters).')'; return "(select max(i) from (values $parametersString) AS T(i))"; } } public function configureForSqlite(): void { DB::connection()->getPdo()->sqliteCreateFunction('greatest', 'max'); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Numeric/Acos.php
src/Numeric/Acos.php
<?php namespace sbamtr\LaravelQueryEnrich\Numeric; use Illuminate\Support\Facades\DB; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Returns the arc cosine of a number. */ class Acos extends DBFunction { private $parameter; public function __construct($parameter) { $this->parameter = $parameter; } protected function getQuery(): string { return $this->getFunctionCallSql('acos', [$this->parameter]); } public function configureForSqlite(): void { DB::connection()->getPdo()->sqliteCreateFunction('acos', 'acos', 1); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Numeric/PI.php
src/Numeric/PI.php
<?php namespace sbamtr\LaravelQueryEnrich\Numeric; use Illuminate\Support\Facades\DB; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Returns the value of PI. */ class PI extends DBFunction { protected function getQuery(): string { return $this->getFunctionCallSql('pi'); } public function configureForSqlite(): void { DB::connection()->getPdo()->sqliteCreateFunction('pi', 'pi', 0); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Numeric/Mod.php
src/Numeric/Mod.php
<?php namespace sbamtr\LaravelQueryEnrich\Numeric; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Returns the remainder of a number divided by another number. */ class Mod extends DBFunction { private mixed $x; private mixed $y; public function __construct(mixed $x, mixed $y) { $this->x = $x; $this->y = $y; } protected function getQuery(): string { return $this->getOperatorSeparatedSql('%', [$this->x, $this->y]); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Numeric/Abs.php
src/Numeric/Abs.php
<?php namespace sbamtr\LaravelQueryEnrich\Numeric; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Returns the absolute value of a number. */ class Abs extends DBFunction { private mixed $parameter; public function __construct(mixed $parameter) { $this->parameter = $parameter; } protected function getQuery(): string { return $this->getFunctionCallSql('abs', [$this->parameter]); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Numeric/Rand.php
src/Numeric/Rand.php
<?php namespace sbamtr\LaravelQueryEnrich\Numeric; use Illuminate\Support\Facades\DB; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; use sbamtr\LaravelQueryEnrich\Exception\InvalidArgumentException; /** * Returns a random number. */ class Rand extends DBFunction { private mixed $seed; public function __construct(mixed $seed = null) { $this->seed = $seed; } protected function getQuery(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: case EDatabaseEngine::SQLServer: $function = 'rand'; break; case EDatabaseEngine::PostgreSQL: case EDatabaseEngine::SQLite: $function = 'random'; break; } if ($this->seed === null) { return $this->getFunctionCallSql($function); } if ($this->getDatabaseEngine() === EDatabaseEngine::PostgreSQL) { throw new InvalidArgumentException('Random function cannot have seed in postgresql database.'); } return $this->getFunctionCallSql($function, [$this->seed]); } public function configureForSqlite(): void { DB::connection()->getPdo()->sqliteCreateFunction('random', function ($seed) { srand($seed); return rand(); }, 1); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Numeric/Exp.php
src/Numeric/Exp.php
<?php namespace sbamtr\LaravelQueryEnrich\Numeric; use Illuminate\Support\Facades\DB; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Returns e raised to the power of a specified number. */ class Exp extends DBFunction { private mixed $parameter; public function __construct(mixed $parameter) { $this->parameter = $parameter; } protected function getQuery(): string { return $this->getFunctionCallSql('exp', [$this->parameter]); } public function configureForSqlite(): void { DB::connection()->getPdo()->sqliteCreateFunction('exp', 'exp', 1); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Numeric/Avg.php
src/Numeric/Avg.php
<?php namespace sbamtr\LaravelQueryEnrich\Numeric; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Returns the average value of an expression. */ class Avg extends DBFunction { private mixed $parameter; public function __construct(mixed $parameter) { $this->parameter = $parameter; } protected function getQuery(): string { return $this->getFunctionCallSql('avg', [$this->parameter]); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Numeric/Add.php
src/Numeric/Add.php
<?php namespace sbamtr\LaravelQueryEnrich\Numeric; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Adds multiple numeric parameters. */ class Add extends DBFunction { private array $parameters; public function __construct(...$parameters) { $this->parameters = $parameters; } protected function getQuery(): string { return $this->getOperatorSeparatedSql('+', $this->parameters); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Numeric/RadianToDegrees.php
src/Numeric/RadianToDegrees.php
<?php namespace sbamtr\LaravelQueryEnrich\Numeric; use Illuminate\Support\Facades\DB; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; /** * Converts a value in radians to degrees. */ class RadianToDegrees extends DBFunction { private mixed $parameter; public function __construct(mixed $parameter) { $this->parameter = $parameter; } protected function getQuery(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: case EDatabaseEngine::PostgreSQL: case EDatabaseEngine::SQLite: return $this->getFunctionCallSql('degrees', [$this->parameter]); case EDatabaseEngine::SQLServer: $parameter = $this->escape($this->parameter); return "$parameter * (180 / pi())"; } } public function configureForSqlite(): void { DB::connection()->getPdo()->sqliteCreateFunction('degrees', 'rad2deg', 1); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Numeric/Min.php
src/Numeric/Min.php
<?php namespace sbamtr\LaravelQueryEnrich\Numeric; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Returns the minimum value in a set of values. */ class Min extends DBFunction { private mixed $parameter; public function __construct(mixed $parameter) { $this->parameter = $parameter; } protected function getQuery(): string { return $this->getFunctionCallSql('min', [$this->parameter]); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Numeric/Sum.php
src/Numeric/Sum.php
<?php namespace sbamtr\LaravelQueryEnrich\Numeric; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Calculates the sum of a set of values. */ class Sum extends DBFunction { private mixed $parameter; public function __construct(mixed $parameter) { $this->parameter = $parameter; } protected function getQuery(): string { return $this->getFunctionCallSql('sum', [$this->parameter]); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Numeric/Log.php
src/Numeric/Log.php
<?php namespace sbamtr\LaravelQueryEnrich\Numeric; use Illuminate\Support\Facades\DB; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; /** * Returns the logarithm of a number. */ class Log extends DBFunction { private mixed $parameter; private mixed $base; public function __construct(mixed $parameter, mixed $base = 2) { $this->parameter = $parameter; $this->base = $base; } protected function getQuery(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: case EDatabaseEngine::PostgreSQL: case EDatabaseEngine::SQLite: return $this->getFunctionCallSql('log', [$this->base, $this->parameter]); case EDatabaseEngine::SQLServer: return $this->getFunctionCallSql('log', [$this->parameter, $this->base]); } } public function configureForSqlite(): void { DB::connection()->getPdo()->sqliteCreateFunction('log', function ($base, $parameter) { return log($parameter, $base); }, 2); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Numeric/Ln.php
src/Numeric/Ln.php
<?php namespace sbamtr\LaravelQueryEnrich\Numeric; use Illuminate\Support\Facades\DB; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; /** * Returns the natural logarithm of a number. */ class Ln extends DBFunction { private mixed $parameter; public function __construct(mixed $parameter) { $this->parameter = $parameter; } protected function getQuery(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: case EDatabaseEngine::PostgreSQL: case EDatabaseEngine::SQLite: return $this->getFunctionCallSql('ln', [$this->parameter]); case EDatabaseEngine::SQLServer: return $this->getFunctionCallSql('log', [$this->parameter]); } } public function configureForSqlite(): void { DB::connection()->getPdo()->sqliteCreateFunction('ln', 'log', 1); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Numeric/Divide.php
src/Numeric/Divide.php
<?php namespace sbamtr\LaravelQueryEnrich\Numeric; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Divide the first numeric parameter by subsequent numeric parameters. */ class Divide extends DBFunction { private array $parameters; public function __construct(...$parameters) { $this->parameters = $parameters; } protected function getQuery(): string { return $this->getOperatorSeparatedSql('/', $this->parameters); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Numeric/Multiply.php
src/Numeric/Multiply.php
<?php namespace sbamtr\LaravelQueryEnrich\Numeric; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Multiply multiple numeric parameters. */ class Multiply extends DBFunction { private array $parameters; public function __construct(...$parameters) { $this->parameters = $parameters; } protected function getQuery(): string { return $this->getOperatorSeparatedSql('*', $this->parameters); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Numeric/Sign.php
src/Numeric/Sign.php
<?php namespace sbamtr\LaravelQueryEnrich\Numeric; use Illuminate\Support\Facades\DB; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Returns the sign of a number. */ class Sign extends DBFunction { private mixed $parameter; public function __construct(mixed $parameter) { $this->parameter = $parameter; } protected function getQuery(): string { return $this->getFunctionCallSql('sign', [$this->parameter]); } public function configureForSqlite(): void { DB::connection()->getPdo()->sqliteCreateFunction('sign', function ($parameter) { return ($parameter > 0) - ($parameter < 0); }, 1); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Numeric/Least.php
src/Numeric/Least.php
<?php namespace sbamtr\LaravelQueryEnrich\Numeric; use Illuminate\Support\Facades\DB; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; /** * Returns the smallest value of the list of arguments. */ class Least extends DBFunction { private array $parameters; public function __construct(...$parameters) { $this->parameters = $parameters; } protected function getQuery(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: case EDatabaseEngine::PostgreSQL: case EDatabaseEngine::SQLite: return $this->getFunctionCallSql('least', $this->parameters); case EDatabaseEngine::SQLServer: $parameters = $this->escape($this->parameters); $parametersString = '('.implode('),(', $parameters).')'; return "(select min(i) from (values $parametersString) AS T(i))"; } } public function configureForSqlite(): void { DB::connection()->getPdo()->sqliteCreateFunction('least', 'min'); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Numeric/Cos.php
src/Numeric/Cos.php
<?php namespace sbamtr\LaravelQueryEnrich\Numeric; use Illuminate\Support\Facades\DB; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Returns the cosine of a number. */ class Cos extends DBFunction { private mixed $parameter; public function __construct(mixed $parameter) { $this->parameter = $parameter; } protected function getQuery(): string { return $this->getFunctionCallSql('cos', [$this->parameter]); } public function configureForSqlite(): void { DB::connection()->getPdo()->sqliteCreateFunction('cos', 'cos', 1); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Numeric/Asin.php
src/Numeric/Asin.php
<?php namespace sbamtr\LaravelQueryEnrich\Numeric; use Illuminate\Support\Facades\DB; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Returns the arc sine of a number. */ class Asin extends DBFunction { private $parameter; public function __construct($parameter) { $this->parameter = $parameter; } protected function getQuery(): string { return $this->getFunctionCallSql('asin', [$this->parameter]); } public function configureForSqlite(): void { DB::connection()->getPdo()->sqliteCreateFunction('asin', 'asin', 1); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Numeric/Sqrt.php
src/Numeric/Sqrt.php
<?php namespace sbamtr\LaravelQueryEnrich\Numeric; use Illuminate\Support\Facades\DB; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Returns the square root of a number. */ class Sqrt extends DBFunction { private $parameter; public function __construct($parameter) { $this->parameter = $parameter; } protected function getQuery(): string { return $this->getFunctionCallSql('sqrt', [$this->parameter]); } public function configureForSqlite(): void { DB::connection()->getPdo()->sqliteCreateFunction('sqrt', 'sqrt', 1); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Numeric/Tan.php
src/Numeric/Tan.php
<?php namespace sbamtr\LaravelQueryEnrich\Numeric; use Illuminate\Support\Facades\DB; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Returns the tangent of a number. */ class Tan extends DBFunction { private mixed $parameter; public function __construct(mixed $parameter) { $this->parameter = $parameter; } protected function getQuery(): string { return $this->getFunctionCallSql('tan', [$this->parameter]); } public function configureForSqlite(): void { DB::connection()->getPdo()->sqliteCreateFunction('tan', 'tan', 1); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Numeric/Max.php
src/Numeric/Max.php
<?php namespace sbamtr\LaravelQueryEnrich\Numeric; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Returns the maximum value in a set of values. */ class Max extends DBFunction { private mixed $parameter; public function __construct(mixed $parameter) { $this->parameter = $parameter; } protected function getQuery(): string { return $this->getFunctionCallSql('max', [$this->parameter]); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Numeric/Ceil.php
src/Numeric/Ceil.php
<?php namespace sbamtr\LaravelQueryEnrich\Numeric; use Illuminate\Support\Facades\DB; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; /** * Returns the smallest integer value that is >= to a number. */ class Ceil extends DBFunction { private mixed $parameter; public function __construct(mixed $parameter) { $this->parameter = $parameter; } protected function getQuery(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: case EDatabaseEngine::PostgreSQL: case EDatabaseEngine::SQLite: return $this->getFunctionCallSql('ceil', [$this->parameter]); case EDatabaseEngine::SQLServer: return $this->getFunctionCallSql('ceiling', [$this->parameter]); } } public function configureForSqlite(): void { DB::connection()->getPdo()->sqliteCreateFunction('ceil', 'ceil', 1); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Numeric/Count.php
src/Numeric/Count.php
<?php namespace sbamtr\LaravelQueryEnrich\Numeric; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\QE; /** * Returns the number of records returned by a select query. */ class Count extends DBFunction { private mixed $parameter; public function __construct(mixed $parameter = '*') { if ($parameter === '*') { $this->parameter = QE::raw('*'); } else { $this->parameter = $parameter; } } protected function getQuery(): string { return $this->getFunctionCallSql('count', [$this->parameter]); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Numeric/Subtract.php
src/Numeric/Subtract.php
<?php namespace sbamtr\LaravelQueryEnrich\Numeric; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Subtracts multiple numeric parameters. */ class Subtract extends DBFunction { private array $parameters; public function __construct(...$parameters) { $this->parameters = $parameters; } protected function getQuery(): string { return $this->getOperatorSeparatedSql('-', $this->parameters); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Numeric/Pow.php
src/Numeric/Pow.php
<?php namespace sbamtr\LaravelQueryEnrich\Numeric; use Illuminate\Support\Facades\DB; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; /** * Returns the value of a number raised to the power of another number. */ class Pow extends DBFunction { private mixed $x; private mixed $y; public function __construct(mixed $x, mixed $y) { $this->x = $x; $this->y = $y; } protected function getQuery(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: case EDatabaseEngine::PostgreSQL: case EDatabaseEngine::SQLite: return $this->getFunctionCallSql('pow', [$this->x, $this->y]); case EDatabaseEngine::SQLServer: return $this->getFunctionCallSql('power', [$this->x, $this->y]); } } public function configureForSqlite(): void { DB::connection()->getPdo()->sqliteCreateFunction('pow', 'pow', 2); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Numeric/Cot.php
src/Numeric/Cot.php
<?php namespace sbamtr\LaravelQueryEnrich\Numeric; use Illuminate\Support\Facades\DB; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Returns the cotangent of a number. */ class Cot extends DBFunction { private mixed $parameter; public function __construct(mixed $parameter) { $this->parameter = $parameter; } protected function getQuery(): string { return $this->getFunctionCallSql('cot', [$this->parameter]); } public function configureForSqlite(): void { DB::connection()->getPdo()->sqliteCreateFunction('cot', function ($parameter) { return 1 / tan($parameter); }, 1); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Numeric/Floor.php
src/Numeric/Floor.php
<?php namespace sbamtr\LaravelQueryEnrich\Numeric; use Illuminate\Support\Facades\DB; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Returns the largest integer value that is <= to a number. */ class Floor extends DBFunction { private mixed $parameter; public function __construct(mixed $parameter) { $this->parameter = $parameter; } protected function getQuery(): string { return $this->getFunctionCallSql('floor', [$this->parameter]); } public function configureForSqlite(): void { DB::connection()->getPdo()->sqliteCreateFunction('floor', 'floor', 1); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Numeric/Atan.php
src/Numeric/Atan.php
<?php namespace sbamtr\LaravelQueryEnrich\Numeric; use Illuminate\Support\Facades\DB; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Returns the arc tangent of a number. */ class Atan extends DBFunction { private $parameter; public function __construct($parameter) { $this->parameter = $parameter; } protected function getQuery(): string { return $this->getFunctionCallSql('atan', [$this->parameter]); } public function configureForSqlite(): void { DB::connection()->getPdo()->sqliteCreateFunction('atan', 'atan', 1); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Numeric/Atan2.php
src/Numeric/Atan2.php
<?php namespace sbamtr\LaravelQueryEnrich\Numeric; use Illuminate\Support\Facades\DB; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; /** * Returns the arc tangent of two numbers. */ class Atan2 extends DBFunction { private $y; private $x; public function __construct($y, $x) { $this->y = $y; $this->x = $x; } protected function getQuery(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: case EDatabaseEngine::PostgreSQL: case EDatabaseEngine::SQLite: return $this->getFunctionCallSql('atan2', [$this->y, $this->x]); case EDatabaseEngine::SQLServer: return $this->getFunctionCallSql('atn2', [$this->y, $this->x]); } } public function configureForSqlite(): void { DB::connection()->getPdo()->sqliteCreateFunction('atan2', 'atan2', 2); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Numeric/Round.php
src/Numeric/Round.php
<?php namespace sbamtr\LaravelQueryEnrich\Numeric; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; use sbamtr\LaravelQueryEnrich\QE; /** * Rounds a number to a specified number of decimal places. */ class Round extends DBFunction { private mixed $parameter; private mixed $decimals; public function __construct(mixed $parameter, mixed $decimals = 0) { $this->parameter = $parameter; $this->decimals = $decimals; } protected function getQuery(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: case EDatabaseEngine::PostgreSQL: case EDatabaseEngine::SQLite: return $this->getFunctionCallSql('round', [$this->parameter, $this->decimals]); case EDatabaseEngine::SQLServer: return $this->getFunctionCallSql('round', [QE::multiply(1.0, $this->parameter), $this->decimals]); } } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Advanced/Exists.php
src/Advanced/Exists.php
<?php namespace sbamtr\LaravelQueryEnrich\Advanced; use Illuminate\Database\Eloquent\Builder as EloquentBuilder; use Illuminate\Database\Query\Builder as QueryBuilder; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Checks if a subquery returns any results using the EXISTS condition. */ class Exists extends DBFunction { protected const IS_BOOLEAN = true; private QueryBuilder|EloquentBuilder $query; public function __construct($query) { $this->query = $query; } protected function getQuery(): string { return 'exists '.$this->escape($this->query); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Advanced/_If.php
src/Advanced/_If.php
<?php namespace sbamtr\LaravelQueryEnrich\Advanced; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; use sbamtr\LaravelQueryEnrich\QE; /** * Implements an IF condition to introduce branching. */ class _If extends DBFunction { private DBFunction $condition; private mixed $valueIfTrue; private mixed $valueIfFalse; public function __construct(DBFunction $condition, mixed $valueIfTrue, mixed $valueIfFalse) { $this->condition = $condition; $this->valueIfTrue = $valueIfTrue; $this->valueIfFalse = $valueIfFalse; } protected function getQuery(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::SQLServer: return $this->getFunctionCallSql('iif', [$this->condition, $this->valueIfTrue, $this->valueIfFalse]); case EDatabaseEngine::MySQL: return $this->getFunctionCallSql('if', [$this->condition, $this->valueIfTrue, $this->valueIfFalse]); case EDatabaseEngine::PostgreSQL: case EDatabaseEngine::SQLite: return QE::case()->when($this->condition)->then($this->valueIfTrue)->else($this->valueIfFalse); } } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Advanced/IsNull.php
src/Advanced/IsNull.php
<?php namespace sbamtr\LaravelQueryEnrich\Advanced; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; /** * Checks if a value is NULL. */ class IsNull extends DBFunction { protected const IS_BOOLEAN = true; private mixed $parameter; public function __construct(mixed $parameter) { $this->parameter = $parameter; } protected function getQuery(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: return $this->getFunctionCallSql('isnull', [$this->parameter]); case EDatabaseEngine::PostgreSQL: case EDatabaseEngine::SQLite: case EDatabaseEngine::SQLServer: return $this->escape($this->parameter).' is null'; } } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Advanced/Coalesce.php
src/Advanced/Coalesce.php
<?php namespace sbamtr\LaravelQueryEnrich\Advanced; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Returns the first non-null value in a list. */ class Coalesce extends DBFunction { private array $parameters; public function __construct(...$parameters) { $this->parameters = $parameters; } protected function getQuery(): string { return $this->getFunctionCallSql('coalesce', $this->parameters); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Advanced/CaseExpression/When.php
src/Advanced/CaseExpression/When.php
<?php namespace sbamtr\LaravelQueryEnrich\Advanced\CaseExpression; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Represents a WHEN clause within a SQL CASE expression. * * This class encapsulates the logic for a single WHEN...THEN pair in a CASE statement, * allowing for construction of complex conditional logic in SQL queries. */ class When extends DBFunction { /** * The condition for this WHEN clause. * * @var mixed */ public mixed $condition; /** * The result to return if the condition is met. * * @var mixed */ public mixed $then; /** * Constructor for the When class. * * Initializes a new WHEN clause with the given condition and result. * * @param mixed $condition The condition for the WHEN clause. * @param mixed $then The result for the THEN clause. */ public function __construct(mixed $condition, mixed $then) { $this->condition = $condition; $this->then = $then; } /** * Convert the WHEN clause to a SQL string. * * Constructs the SQL representation of this WHEN clause, including the condition * and the result, properly escaped to prevent SQL injection. * * @return string The SQL representation of the WHEN clause. */ protected function getQuery(): string { $condition = $this->escape($this->condition); $then = $this->escape($this->then); return "when $condition then $then"; } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Advanced/CaseExpression/CaseWhenChain.php
src/Advanced/CaseExpression/CaseWhenChain.php
<?php namespace sbamtr\LaravelQueryEnrich\Advanced\CaseExpression; use Illuminate\Support\Arr; use sbamtr\LaravelQueryEnrich\Condition\ConditionParser; use sbamtr\LaravelQueryEnrich\DBFunction; /** * This class allows chaining of WHEN...THEN clauses and an optional ELSE clause * to create complex conditional logic within SQL queries. */ class CaseWhenChain extends DBFunction { /** * The internal CASE expression being built. * * @var _Case */ private _Case $case; /** * Constructor for the CaseWhenChain class. * * Initializes a new internal CASE expression. */ public function __construct() { $this->case = new _Case(); } /** * Add a WHEN clause to the CASE expression. * * @param mixed ...$condition The condition for the WHEN clause. * * @return CaseWhenChain Returns the current instance for method chaining. */ public function when(mixed ...$condition): CaseWhenChain { $condition = ConditionParser::parse($condition); $when = new When($condition, null); $this->case->whens[] = $when; return $this; } /** * Add a THEN result to the last WHEN clause of the CASE expression. * * @param mixed $result The result for the THEN clause. * * @return CaseWhenChain Returns the current instance for method chaining. */ public function then(mixed $result): CaseWhenChain { $lastWhen = Arr::last($this->case->whens); $lastWhen->then = $result; return $this; } /** * Add an ELSE result to the CASE expression. * * @param mixed $result The result for the ELSE clause. * * @return CaseWhenChain Returns the current instance for method chaining. */ public function else(mixed $result): CaseWhenChain { $this->case->else = $result; return $this; } /** * Convert the CASE expression to a SQL string. * * @return string The SQL representation of the CASE expression. */ protected function getQuery(): string { return $this->case->getQuery(); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Advanced/CaseExpression/_Case.php
src/Advanced/CaseExpression/_Case.php
<?php namespace sbamtr\LaravelQueryEnrich\Advanced\CaseExpression; use sbamtr\LaravelQueryEnrich\DBFunction; /** * This class allows for the construction of a CASE expression in SQL, which is used to create conditional statements * within an SQL query. It can define multiple WHEN conditions and an ELSE result. */ class _Case extends DBFunction { /** * An array of WHEN clauses. * * @var When[] */ public array $whens; /** * The result to return if no WHEN condition is matched. * * @var mixed */ public mixed $else; /** * Constructor for the CASE expression class. * * @param array $whens An array of WHEN conditions for the CASE expression. * @param mixed $else The result to return if no WHEN condition is matched (optional). */ public function __construct(array $whens = [], mixed $else = null) { $this->whens = $whens; $this->else = $else; } /** * Convert the CASE expression to a SQL string. * * This method constructs the SQL string for the CASE expression by iterating over the WHEN clauses and * optionally adding an ELSE clause. * * @return string The SQL representation of the CASE expression. */ protected function getQuery(): string { $whens = $this->whens; $sql = 'case '; foreach ($whens as $when) { $when = $this->escape($when); $sql .= $when.' '; } if (isset($this->else)) { $sql .= 'else '.$this->escape($this->else).' '; } $sql .= 'end'; return $sql; } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/String/Space.php
src/String/Space.php
<?php namespace sbamtr\LaravelQueryEnrich\String; use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; use sbamtr\LaravelQueryEnrich\QE; /** * Returns a string consisting of a specified number of spaces. */ class Space extends DBFunction { private mixed $number; public function __construct(mixed $number) { $this->number = $number; } protected function getQuery(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: case EDatabaseEngine::SQLite: case EDatabaseEngine::SQLServer: return $this->getFunctionCallSql('space', [$this->number]); case EDatabaseEngine::PostgreSQL: return QE::repeat(' ', $this->number); } } public function configureForSqlite(): void { DB::connection()->getPdo()->sqliteCreateFunction('space', function ($number) { return Str::repeat(' ', $number); }, 1); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/String/MD5.php
src/String/MD5.php
<?php namespace sbamtr\LaravelQueryEnrich\String; use Illuminate\Support\Facades\DB; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; use sbamtr\LaravelQueryEnrich\QE; /** * Calculates the MD5 hash for a given parameter. */ class MD5 extends DBFunction { private mixed $parameter; public function __construct(mixed $parameter) { $this->parameter = $parameter; } protected function getQuery(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: case EDatabaseEngine::PostgreSQL: case EDatabaseEngine::SQLite: return $this->getFunctionCallSql('md5', [$this->parameter]); case EDatabaseEngine::SQLServer: return QE::raw("lower(convert(varchar(32), hashbytes('md5', ?), 2))", [$this->parameter]); } } public function configureForSqlite(): void { DB::connection()->getPdo()->sqliteCreateFunction('md5', 'md5', 1); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/String/Substr.php
src/String/Substr.php
<?php namespace sbamtr\LaravelQueryEnrich\String; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; use sbamtr\LaravelQueryEnrich\QE; /** * Extracts a substring from a string starting at a specified position with optional length. */ class Substr extends DBFunction { private mixed $string; private mixed $start; private mixed $length; public function __construct(mixed $string, mixed $start, mixed $length = null) { $this->string = $string; $this->start = $start; $this->length = $length; } protected function getQuery(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: case EDatabaseEngine::PostgreSQL: case EDatabaseEngine::SQLite: if ($this->length === null) { return $this->getFunctionCallSql('substr', [$this->string, $this->start]); } return $this->getFunctionCallSql('substr', [$this->string, $this->start, $this->length]); case EDatabaseEngine::SQLServer: if ($this->length === null) { return $this->getFunctionCallSql('stuff', [$this->string, 1, QE::subtract($this->start, 1), '']); } return $this->getFunctionCallSql('substring', [$this->string, $this->start, $this->length]); } } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/String/Trim.php
src/String/Trim.php
<?php namespace sbamtr\LaravelQueryEnrich\String; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Removes leading and trailing spaces from a string. */ class Trim extends DBFunction { private mixed $parameter; public function __construct(mixed $parameter) { $this->parameter = $parameter; } protected function getQuery(): string { return $this->getFunctionCallSql('trim', [$this->parameter]); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/String/StartsWith.php
src/String/StartsWith.php
<?php namespace sbamtr\LaravelQueryEnrich\String; use Illuminate\Support\Facades\DB; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\QE; /** * Determines if a given string starts with a given substring. */ class StartsWith extends DBFunction { protected const IS_BOOLEAN = true; private mixed $haystack; private mixed $needle; public function __construct(mixed $haystack, mixed $needle) { $this->haystack = $haystack; $this->needle = $needle; } protected function getQuery(): string { $haystack = $this->escape($this->haystack); $needle = QE::concat($this->needle, QE::raw(DB::escape('%'))); return "$haystack like $needle"; } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/String/Lower.php
src/String/Lower.php
<?php namespace sbamtr\LaravelQueryEnrich\String; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Converts a string to lower-case. */ class Lower extends DBFunction { private mixed $string; public function __construct(mixed $string) { $this->string = $string; } protected function getQuery(): string { return $this->getFunctionCallSql('lower', [$this->string]); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/String/PadLeft.php
src/String/PadLeft.php
<?php namespace sbamtr\LaravelQueryEnrich\String; use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; /** * Left-pads a string with another string, to a certain length. */ class PadLeft extends DBFunction { private mixed $string; private mixed $length; private mixed $pad; public function __construct(mixed $string, mixed $length, mixed $pad = ' ') { $this->string = $string; $this->length = $length; $this->pad = $pad; } protected function getQuery(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: case EDatabaseEngine::PostgreSQL: case EDatabaseEngine::SQLite: return $this->getFunctionCallSql('lpad', [$this->string, $this->length, $this->pad]); case EDatabaseEngine::SQLServer: $string = $this->escape($this->string); $length = $this->escape($this->length); $pad = $this->escape($this->pad); return "left(replicate($pad, $length), $length - len($string)) + $string"; } } public function configureForSqlite(): void { DB::connection()->getPdo()->sqliteCreateFunction('lpad', function ($string, $length, $pad) { return Str::padLeft($string, $length, $pad); }, 3); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/String/Replace.php
src/String/Replace.php
<?php namespace sbamtr\LaravelQueryEnrich\String; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Replaces occurrences of a substring with a new string. */ class Replace extends DBFunction { private mixed $string; private mixed $substring; private mixed $newString; public function __construct(mixed $string, mixed $substring, mixed $newString) { $this->string = $string; $this->substring = $substring; $this->newString = $newString; } protected function getQuery(): string { return $this->getFunctionCallSql('replace', [$this->string, $this->substring, $this->newString]); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/String/Right.php
src/String/Right.php
<?php namespace sbamtr\LaravelQueryEnrich\String; use Illuminate\Support\Facades\DB; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; /** * Extracts a number of characters from a string (starting from right). */ class Right extends DBFunction { private mixed $string; private mixed $numberOfChars; public function __construct(mixed $string, mixed $numberOfChars) { $this->string = $string; $this->numberOfChars = $numberOfChars; } protected function getQuery(): string { if ($this->getDatabaseEngine() == EDatabaseEngine::SQLite) { return $this->getFunctionCallSql('rightstr', [$this->string, $this->numberOfChars]); } return $this->getFunctionCallSql('right', [$this->string, $this->numberOfChars]); } public function configureForSqlite(): void { DB::connection()->getPdo()->sqliteCreateFunction('rightstr', function ($string, $numberOfChars) { return substr($string, -1 * $numberOfChars); }, 2); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/String/Repeat.php
src/String/Repeat.php
<?php namespace sbamtr\LaravelQueryEnrich\String; use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; /** * Repeats a string a specified number of times. */ class Repeat extends DBFunction { private mixed $parameter; private mixed $number; public function __construct(mixed $parameter, mixed $number) { $this->parameter = $parameter; $this->number = $number; } protected function getQuery(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: case EDatabaseEngine::PostgreSQL: case EDatabaseEngine::SQLite: return $this->getFunctionCallSql('repeat', [$this->parameter, $this->number]); case EDatabaseEngine::SQLServer: return $this->getFunctionCallSql('replicate', [$this->parameter, $this->number]); } } public function configureForSqlite(): void { DB::connection()->getPdo()->sqliteCreateFunction('repeat', function ($parameter, $number) { return Str::repeat($parameter, $number); }, 2); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/String/Length.php
src/String/Length.php
<?php namespace sbamtr\LaravelQueryEnrich\String; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; /** * Returns the length of a string. */ class Length extends DBFunction { private mixed $string; public function __construct(mixed $string) { $this->string = $string; } protected function getQuery(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: case EDatabaseEngine::PostgreSQL: case EDatabaseEngine::SQLite: return $this->getFunctionCallSql('length', [$this->string]); case EDatabaseEngine::SQLServer: return $this->getFunctionCallSql('len', [$this->string]); } } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/String/ConcatWS.php
src/String/ConcatWS.php
<?php namespace sbamtr\LaravelQueryEnrich\String; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; use sbamtr\LaravelQueryEnrich\QE; /** * Adds two or more expressions together with a separator. */ class ConcatWS extends DBFunction { private mixed $separator; private array $parameters; public function __construct(mixed $separator, ...$parameters) { $this->separator = $separator; $this->parameters = $parameters; } protected function getQuery(): string { if ($this->getDatabaseEngine() == EDatabaseEngine::SQLite) { $parameters = []; foreach ($this->parameters as $parameter) { $parameters[] = $parameter; $parameters[] = $this->separator; } array_pop($parameters); return QE::concat(...$parameters)->getQuery(); } return $this->getFunctionCallSql('concat_ws', [$this->separator, ...$this->parameters]); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/String/Reverse.php
src/String/Reverse.php
<?php namespace sbamtr\LaravelQueryEnrich\String; use Illuminate\Support\Facades\DB; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Reverses the characters of a string. */ class Reverse extends DBFunction { private mixed $parameter; public function __construct(mixed $parameter) { $this->parameter = $parameter; } protected function getQuery(): string { return $this->getFunctionCallSql('reverse', [$this->parameter]); } public function configureForSqlite(): void { DB::connection()->getPdo()->sqliteCreateFunction('reverse', 'strrev', 1); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/String/Position.php
src/String/Position.php
<?php namespace sbamtr\LaravelQueryEnrich\String; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; /** * Finds the position of a substring within a string. */ class Position extends DBFunction { private mixed $subString; private mixed $string; public function __construct(mixed $subString, mixed $string) { $this->subString = $subString; $this->string = $string; } protected function getQuery(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::SQLite: return $this->getFunctionCallSql('instr', [$this->string, $this->subString]); case EDatabaseEngine::MySQL: case EDatabaseEngine::PostgreSQL: $subString = $this->escape($this->subString); $string = $this->escape($this->string); return "POSITION($subString IN $string)"; case EDatabaseEngine::SQLServer: return $this->getFunctionCallSql('charindex', [$this->subString, $this->string]); } } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/String/Rtrim.php
src/String/Rtrim.php
<?php namespace sbamtr\LaravelQueryEnrich\String; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Removes trailing spaces from a string. */ class Rtrim extends DBFunction { private mixed $parameter; public function __construct(mixed $parameter) { $this->parameter = $parameter; } protected function getQuery(): string { return $this->getFunctionCallSql('ltrim', [$this->parameter]); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/String/Contains.php
src/String/Contains.php
<?php namespace sbamtr\LaravelQueryEnrich\String; use Illuminate\Support\Facades\DB; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\QE; /** * Determines if a given string contains a given substring. */ class Contains extends DBFunction { protected const IS_BOOLEAN = true; private mixed $haystack; private mixed $needle; public function __construct(mixed $haystack, mixed $needle) { $this->haystack = $haystack; $this->needle = $needle; } protected function getQuery(): string { $haystack = $this->escape($this->haystack); $needle = QE::concat(QE::raw(DB::escape('%')), $this->needle, QE::raw(DB::escape('%'))); return "$haystack like $needle"; } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/String/PadRight.php
src/String/PadRight.php
<?php namespace sbamtr\LaravelQueryEnrich\String; use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; /** * Right-pads a string with another string, to a certain length. */ class PadRight extends DBFunction { private mixed $string; private mixed $length; private mixed $pad; public function __construct(mixed $string, mixed $length, mixed $pad = ' ') { $this->string = $string; $this->length = $length; $this->pad = $pad; } protected function getQuery(): string { switch ($this->getDatabaseEngine()) { case EDatabaseEngine::MySQL: case EDatabaseEngine::PostgreSQL: case EDatabaseEngine::SQLite: return $this->getFunctionCallSql('rpad', [$this->string, $this->length, $this->pad]); case EDatabaseEngine::SQLServer: $string = $this->escape($this->string); $length = $this->escape($this->length); $pad = $this->escape($this->pad); return "$string + left(replicate($pad, $length), $length - len($string))"; } } public function configureForSqlite(): void { DB::connection()->getPdo()->sqliteCreateFunction('rpad', function ($string, $length, $pad) { return Str::padRight($string, $length, $pad); }, 3); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/String/Ltrim.php
src/String/Ltrim.php
<?php namespace sbamtr\LaravelQueryEnrich\String; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Removes leading spaces from a string. */ class Ltrim extends DBFunction { private mixed $parameter; public function __construct(mixed $parameter) { $this->parameter = $parameter; } protected function getQuery(): string { return $this->getFunctionCallSql('ltrim', [$this->parameter]); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/String/EndsWith.php
src/String/EndsWith.php
<?php namespace sbamtr\LaravelQueryEnrich\String; use Illuminate\Support\Facades\DB; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\QE; /** * Determines if a given string end with a given substring. */ class EndsWith extends DBFunction { protected const IS_BOOLEAN = true; private mixed $haystack; private mixed $needle; public function __construct(mixed $haystack, mixed $needle) { $this->haystack = $haystack; $this->needle = $needle; } protected function getQuery(): string { $haystack = $this->escape($this->haystack); $needle = QE::concat(QE::raw(DB::escape('%')), $this->needle); return "$haystack like $needle"; } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/String/Upper.php
src/String/Upper.php
<?php namespace sbamtr\LaravelQueryEnrich\String; use sbamtr\LaravelQueryEnrich\DBFunction; /** * Converts a string to upper-case. */ class Upper extends DBFunction { private mixed $string; public function __construct(mixed $string) { $this->string = $string; } protected function getQuery(): string { return $this->getFunctionCallSql('upper', [$this->string]); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/String/Left.php
src/String/Left.php
<?php namespace sbamtr\LaravelQueryEnrich\String; use Illuminate\Support\Facades\DB; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; /** * Extracts a number of characters from a string (starting from left). */ class Left extends DBFunction { private mixed $string; private mixed $numberOfChars; public function __construct(mixed $string, mixed $numberOfChars) { $this->string = $string; $this->numberOfChars = $numberOfChars; } protected function getQuery(): string { if ($this->getDatabaseEngine() == EDatabaseEngine::SQLite) { return $this->getFunctionCallSql('leftstr', [$this->string, $this->numberOfChars]); } return $this->getFunctionCallSql('left', [$this->string, $this->numberOfChars]); } public function configureForSqlite(): void { DB::connection()->getPdo()->sqliteCreateFunction('leftstr', function ($string, $numberOfChars) { return substr($string, 0, $numberOfChars); }, 2); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/String/Concat.php
src/String/Concat.php
<?php namespace sbamtr\LaravelQueryEnrich\String; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\EDatabaseEngine; /** * Adds two or more expressions together. */ class Concat extends DBFunction { private array $parameters; public function __construct(...$parameters) { $this->parameters = $parameters; } protected function getQuery(): string { if ($this->getDatabaseEngine() == EDatabaseEngine::SQLite) { return $this->getOperatorSeparatedSql('||', $this->parameters); } return $this->getFunctionCallSql('concat', $this->parameters); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Condition/ConditionChain.php
src/Condition/ConditionChain.php
<?php namespace sbamtr\LaravelQueryEnrich\Condition; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\Operator\_And; /** * Represents a chain of conditions for use in queries. * This class helps in building complex query conditions using logical operators. */ class ConditionChain extends DBFunction { /** * Array of conditions that form the chain. * * @var array */ private array $conditions; /** * Constructs a new condition chain. * * @param array $conditions The conditions that form the chain. */ public function __construct(array $conditions) { $this->conditions = $conditions; } /** * Converts the condition chain to SQL. * * @return string The SQL representation of the condition chain. */ protected function getQuery(): string { $conditions = $this->conditions; $and = new _And(...$conditions); return $and->getQuery(); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Condition/ConditionParser.php
src/Condition/ConditionParser.php
<?php namespace sbamtr\LaravelQueryEnrich\Condition; use sbamtr\LaravelQueryEnrich\Advanced\IsNull; use sbamtr\LaravelQueryEnrich\Exception\InvalidArgumentException; use sbamtr\LaravelQueryEnrich\Raw; /** * Responsible for parsing conditions for use in queries. * This class takes an array of conditions and returns an instance of Condition, ConditionChain, or Raw depending on the input. */ class ConditionParser { /** * Parses an array of conditions. * * @param non-empty-array $conditions An array of conditions. * * @throws InvalidArgumentException If the input is invalid. * * @return Condition|ConditionChain|Raw Depending on the input, this method returns an instance of Condition, ConditionChain, or Raw. */ public static function parse(array $conditions): Condition|ConditionChain|IsNull|Raw { $count = count($conditions); $condition = reset($conditions); if ($count === 1 && $condition instanceof Raw || $condition instanceof IsNull) { return $condition; } if ($condition instanceof Condition) { return new ConditionChain($conditions); } if ($count === 2 || $count === 3) { return new Condition(...$conditions); } throw new InvalidArgumentException('Invalid condition'); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false
SiavashBamshadnia/Laravel-Query-Enrich
https://github.com/SiavashBamshadnia/Laravel-Query-Enrich/blob/bafb849ed83b7c816d9a94a0d71651821db780a0/src/Condition/Condition.php
src/Condition/Condition.php
<?php namespace sbamtr\LaravelQueryEnrich\Condition; use sbamtr\LaravelQueryEnrich\DBFunction; use sbamtr\LaravelQueryEnrich\Exception\InvalidArgumentException; /** * Represents a condition for use in queries. * This class helps in building complex query conditions using logical operators. */ class Condition extends DBFunction { protected const IS_BOOLEAN = true; /** * Valid operators that can be used in the condition. * * @var array */ private const VALID_OPERATORS = ['=', '<>', '!=', 'like', 'not like', '<', '>', '<=', '>=', 'is', 'is not', 'in', 'not in']; /** * Operators that accept arrays as parameters. * * @var array */ private const ARRAY_OPERATORS = ['in', 'not in']; /** * First parameter of the condition. * * @var mixed */ private mixed $parameter1; /** * Operator of the condition. * * @var string */ private string $operator; /** * Second parameter of the condition. * * @var mixed */ private mixed $parameter2; /** * Constructs a new condition. * * @param mixed $parameter1 The first parameter of the condition. * @param string $operator The operator of the condition. Default is '='. * @param mixed $parameter2 The second parameter of the condition. * * @throws InvalidArgumentException If the operator is not valid. */ public function __construct(mixed $parameter1, mixed $operator = null, mixed $parameter2 = null) { if (func_num_args() === 2) { $parameter2 = $operator; $operator = '='; } if (!$this->isOperatorValid($operator)) { throw new InvalidArgumentException('The operator '.$operator.' is not supported'); } $this->parameter1 = $parameter1; $this->operator = $operator; $this->parameter2 = $parameter2; } protected function getQuery(): string { $parameter1 = $this->escape($this->parameter1); $parameter2 = $this->escape($this->parameter2); $operator = $this->operator; $operator = strtolower($operator); if (in_array($operator, self::ARRAY_OPERATORS)) { $parameter2 = '('.implode(',', $parameter2).')'; return "$parameter1 $operator $parameter2"; } return "$parameter1 $operator $parameter2"; } /** * Checks if the operator is valid. * * @param string $operator The operator to check. * * @return bool True if the operator is valid, false otherwise. */ private function isOperatorValid(string $operator): bool { return in_array($operator, self::VALID_OPERATORS); } }
php
MIT
bafb849ed83b7c816d9a94a0d71651821db780a0
2026-01-05T04:51:45.342665Z
false