kennyyuen / shark-query-expression
There is no license information available for the latest version (0.1.5) of this package.
0.1.5
2025-01-29 02:00 UTC
Requires
- php: ^8.3
- nette/tokenizer: ^3.1
Requires (Dev)
- phpunit/phpunit: ^11.5
This package is auto-updated.
Last update: 2025-05-29 01:58:31 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.