mirror of
https://github.com/grocy/grocy.git
synced 2025-07-02 22:09:30 +00:00
Added REGEXP operator for API query filter (closes #1174)
This commit is contained in:
parent
d3883ba93a
commit
59aad1c180
@ -199,10 +199,12 @@
|
|||||||
- `=` equal
|
- `=` equal
|
||||||
- `!=` not equal
|
- `!=` not equal
|
||||||
- `~` LIKE
|
- `~` LIKE
|
||||||
|
- `!~` not LIKE
|
||||||
- `<` less
|
- `<` less
|
||||||
- `>` greater
|
- `>` greater
|
||||||
- `>=` greater or equal
|
|
||||||
- `<=` less or equal
|
- `<=` less or equal
|
||||||
|
- `>=` greater or equal
|
||||||
|
- `§` regular expression
|
||||||
- `<value>` is the value to search for
|
- `<value>` is the value to search for
|
||||||
- New endpoint `/stock/shoppinglist/add-overdue-products` to add all currently in-stock but overdue products to a shopping list (thanks @m-byte)
|
- New endpoint `/stock/shoppinglist/add-overdue-products` to add all currently in-stock but overdue products to a shopping list (thanks @m-byte)
|
||||||
- New endpoint `/stock/shoppinglist/add-expired-products` to add all currently in-stock but expired products to a shopping list
|
- New endpoint `/stock/shoppinglist/add-expired-products` to add all currently in-stock but expired products to a shopping list
|
||||||
|
@ -9,8 +9,8 @@ class BaseApiController extends BaseController
|
|||||||
protected $OpenApiSpec = null;
|
protected $OpenApiSpec = null;
|
||||||
|
|
||||||
const PATTERN_FIELD = '[A-Za-z_][A-Za-z0-9_]+';
|
const PATTERN_FIELD = '[A-Za-z_][A-Za-z0-9_]+';
|
||||||
const PATTERN_OPERATOR = '!?(=|~|<|>|(>=)|(<=))';
|
const PATTERN_OPERATOR = '!?(=|~|<|>|(>=)|(<=)|(§))';
|
||||||
const PATTERN_VALUE = '[A-Za-z_0-9.]+';
|
const PATTERN_VALUE = '[A-Za-z_0-9.$#^|]+';
|
||||||
|
|
||||||
public function __construct(\DI\Container $container)
|
public function __construct(\DI\Container $container)
|
||||||
{
|
{
|
||||||
@ -123,6 +123,9 @@ class BaseApiController extends BaseController
|
|||||||
case '<=':
|
case '<=':
|
||||||
$data = $data->where($matches['field'] . ' <= ?', $matches['value']);
|
$data = $data->where($matches['field'] . ' <= ?', $matches['value']);
|
||||||
break;
|
break;
|
||||||
|
case '§':
|
||||||
|
$data = $data->where($matches['field'] . ' REGEXP ?', $matches['value']);
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5093,7 +5093,7 @@
|
|||||||
"in": "query",
|
"in": "query",
|
||||||
"name": "query[]",
|
"name": "query[]",
|
||||||
"required": false,
|
"required": false,
|
||||||
"description": "An array of filter conditions, each of them is a string in the form of `<field><condition><value>` where<br>`<field>` is a valid field name<br>`<condition>` is a comparison operator, one of<br> `=` equal<br> `!=` not equal<br> `~` LIKE<br> `<` less<br> `>` greater<br> `<=` less or equal<br> `>=` (greater or equal<br>`<value>` is the value to search for",
|
"description": "An array of filter conditions, each of them is a string in the form of `<field><condition><value>` where<br>`<field>` is a valid field name<br>`<condition>` is a comparison operator, one of<br> `=` equal<br> `!=` not equal<br> `~` LIKE<br> `!~` not LIKE<br> `<` less<br> `>` greater<br> `<=` less or equal<br> `>=` greater or equal<br> `§` regular expression<br>`<value>` is the value to search for",
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {
|
"items": {
|
||||||
|
@ -5,9 +5,7 @@ namespace Grocy\Services;
|
|||||||
class DatabaseService
|
class DatabaseService
|
||||||
{
|
{
|
||||||
private static $DbConnection = null;
|
private static $DbConnection = null;
|
||||||
|
|
||||||
private static $DbConnectionRaw = null;
|
private static $DbConnectionRaw = null;
|
||||||
|
|
||||||
private static $instance = null;
|
private static $instance = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -67,6 +65,12 @@ class DatabaseService
|
|||||||
{
|
{
|
||||||
$pdo = new \PDO('sqlite:' . $this->GetDbFilePath());
|
$pdo = new \PDO('sqlite:' . $this->GetDbFilePath());
|
||||||
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||||
|
|
||||||
|
$pdo->sqliteCreateFunction('regexp', function ($pattern, $value) {
|
||||||
|
mb_regex_encoding('UTF-8');
|
||||||
|
return (false !== mb_ereg($pattern, $value)) ? 1 : 0;
|
||||||
|
});
|
||||||
|
|
||||||
self::$DbConnectionRaw = $pdo;
|
self::$DbConnectionRaw = $pdo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user