Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/imyangjin/yii2-mysql-json
extend yii2-ActiceRecord And yii2-ActiveQuery with use mysql json make simple.
https://github.com/imyangjin/yii2-mysql-json
Last synced: 10 days ago
JSON representation
extend yii2-ActiceRecord And yii2-ActiveQuery with use mysql json make simple.
- Host: GitHub
- URL: https://github.com/imyangjin/yii2-mysql-json
- Owner: imyangjin
- Created: 2018-10-19T06:20:46.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2018-12-12T07:40:48.000Z (almost 6 years ago)
- Last Synced: 2024-09-17T04:37:46.927Z (about 2 months ago)
- Language: PHP
- Size: 20.5 KB
- Stars: 12
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-yii2 - imyangjin/yii2-mysql-json
README
# Yii2 Mysql Json
The extension yii2-ActiceRecord And yii2-ActiveQuery with use mysql json make simple.## Installation
The preferred way to install this extension is through composer.Either run
> composer require --prefer-dist imyangjin/yii2-mysql-json
or add
> "imyangjin/yii2-mysql-json": "~1.0"
to the require section of your `composer.json`.
## Basic Usage
Your Model file must extend this extension class;
```
use Imyangji\Yii2MysqlJson\ActiveRecordJson;class YourModel extent ActiveRecordJson
{}
```
Then if you want to use it to search column with json.
### jsonWhere
This func like use `Model::find()->where(\[Query::where()\])`;
column search is `column->"$.jsonColumn1.jsonColumn2..."`;
```
public function search()
{
YourModel::findJson()
->jsonWhere(['content->"$.en.content"' => 'who'])
->jsonWhere(['>', 'content->"$.en.content"' , 'who'])
}
```### jsonContainsWhere
This func Support mysql `JSON_CONTAINS(target, candidate[, path])`;
This query is equivalent to the query, but the difference is that the query is an inclusion relation, that is, the field contains the value of the value;
Column A multilevel field supporting JSON fields is segmented using '.';```
public function search()
{
YourModel::findJson()
->jsonContainsWhere('content.en.content', 'who')
}
```### jsonExtractWhere
This func Support JSON_EXTRACT(json_doc, path[, path] ...) in query;
Column A multilevel field supporting JSON fields is segmented using '.';
Can use operate to search。```
public function search()
{
YourModel::findJson()
->jsonContainsWhere('content.en.content', 'who', '>')
}
```### jsonSelect
This func Support JSON_EXTRACT(json_doc, path) AS `xx` in query select;
Column A multilevel field supporting JSON fields is segmented using '.';```
public function search()
{
YourModel::findJson()
->jsonSelect(['content.en.content', 'content.en.text' => 'tt']])
}
```