kennyyuen/shark-query-expression
最新稳定版本:0.1.5
Composer 安装命令:
composer require kennyyuen/shark-query-expression
包简介
README 文档
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.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2025-01-29