Use JSON functions to analyze and aggregate JSON data.
use tommyknocker\pdodb\helpers\Db;
$users = $db->find()
->from('users')
->select([
'id',
'name',
'tag_count' => Db::jsonLength('tags')
])
->where(Db::jsonLength('tags'), 3, '>')
->get();$users = $db->find()
->from('users')
->orderBy(Db::jsonLength('tags'), 'DESC')
->limit(10)
->get();$users = $db->find()
->from('users')
->select([
'id',
'tags_type' => Db::jsonType('tags')
])
->get();
// Returns: 'array', 'object', 'string', 'number', 'boolean', 'null'$users = $db->find()
->from('users')
->select([
'id',
'meta_keys' => Db::jsonKeys('meta')
])
->get();$tagStats = $db->find()
->from('users')
->select([
'tag_count' => Db::jsonLength('tags'),
'has_many_tags' => Db::jsonLength('tags') . ' > 5'
])
->get();$analysis = $db->find()
->from('users')
->select([
'id',
'meta_type' => Db::jsonType('meta'),
'meta_keys_count' => Db::jsonLength(Db::jsonKeys('meta')),
'tags_count' => Db::jsonLength('tags')
])
->get();$stats = $db->find()
->from('users')
->select([
'city' => Db::jsonGet('meta', ['city']),
'city_count' => Db::count()
])
->groupBy('city')
->orderBy('city_count', 'DESC')
->get();- JSON Aggregations - JSON length, type, keys, group by JSON
- JSON Basics - JSON fundamentals
- JSON Querying - Query JSON
- JSON Modification - Update JSON