kennyyuen / shark-query-expression
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Forks: 0
pkg:composer/kennyyuen/shark-query-expression
Requires
- php: ^8.3
- nette/tokenizer: ^3.1
Requires (Dev)
- phpunit/phpunit: ^11.5
This package is auto-updated.
Last update: 2025-10-29 03:18:52 UTC
README
The query-expression is a PHP library designed to convert a set of expression to query.
Installation
You can install the library via Composer:
composer require kennyyuen/shark-query-expression
Query Support
- MySQL
Usage
To use the query-expression, include the autoload file generated by Composer:
<?php
require 'vendor/autoload.php';
use Shark\Extensions\QueryExpression\Evaluator;
use Shark\Extensions\QueryExpression\Parsers;
$evaluator = new Evaluator(Parsers::SQL);
$query = $evaluator->eval("*1*2*", "your_field_name");
// Output: ["your_field_name LIKE ?", ["%1%2%"]]
Examples
Example 1 - Multiple items with exact values
// 'some-value|some-other-value'
//
// Or using whitespace (only work for exact value)
// 'some-value some-other-value'
//
// Note: it only supports alphanumeric, underscore and hyphen value
use Shark\Extensions\QueryExpression\Evaluator;
use Shark\Extensions\QueryExpression\Parsers;
$evaluator = new Evaluator(Parsers::SQL);
$query = $evaluator->eval("*1*2*", "your_field_name");
// Output: ["your_field_name LIKE ?", ["%1%2%"]]
Example 2 - Between two values
# Between 5 and 10
>=5&<=10
Example 3 - Like pattern
# Starting with 'ABC'
ABC*
Supported Syntax
Comparison operator can be combined with logic operator
| Operator | Type | Example | Description |
|---|---|---|---|
| < | Comparison Operator | <15 | Less than...( Not include ...) |
| <= | Comparison Operator | <=15 | Less than or equal to ... ( Include ... ) |
| > | Comparison Operator | >15 | Greater than ( Not include ... ) |
| >= | Comparison Operator | >=15 | Greater than or equal to ... ( Include .. ) |
| <> | Comparison Operator | <>15 | Not equal to ... |
| | Wildcard Comparison Operator | bc | Like ... | ||
| | | Logic Operator | abc|cde | ... Or ... |
| & | Logic Operator | abc&cde | ... And ... |
| whitespace | Logic Operator | abc cde | ... Or ... |
Contributing
Contributions are welcome! Please submit a pull request or open an issue to discuss your ideas.
License
This project is licensed under the MIT License.