矩阵查询
使用类似ORM的语法查询JavaScript数组,得益于优秀的类型安全和发展者经验.
关键特性 :
- 🛠 类型安全查询 : 用强打字设计您的查询( 类型排序 / 搜索 / 过滤键和输出)
- 📄 铺设 : 在内置支持下,通过大型数据集轻松地相接.
- 🔎 全文搜索 : 在您数据中的多个字段进行全面搜索.
- 🧭 高级过滤 : 应用各种匹配模式的复杂过滤器进行精确的数据检索。 支持逻辑组、嵌入条件和阵列匹配.
- 🔢 弹性排序 : 基于任意字段的排序结果,支持多类标准.
- 🚀 轻取快取: 查询会保持超快,即使有大型数据集.
- 🧩 无依赖: 完全自成一体,没有外部依赖性,确保小额捆绑成本
通知
// npm
npm install @chronicstone/array-query
// yarn
yarn add @chronicstone/array-query
// pnpm
pnpm add @chronicstone/array-query
// bun
bun add @chronicstone/array-query
用户示例
import { query } from '@chronicstone/array-query'
const users = [
{ id: 1, fullName: 'John Doe', email: '[email protected]', age: 30, status: 'active', roles: ['admin'], createdAt: '2023-01-01' },
{ id: 2, fullName: 'Jane Smith', email: '[email protected]', age: 28, status: 'inactive', roles: ['user'], createdAt: '2023-02-15' },
{ id: 3, fullName: 'Bob Johnson', email: '[email protected]', age: 35, status: 'active', roles: ['user', 'manager'], createdAt: '2023-03-20' },
// ... more users
]
const { totalRows, totalPages, rows } = query(users, {
// Pagination
page: 1,
limit: 10,
// Sorting
sort: [
{ key: 'age', dir: 'desc' },
{ key: 'fullName', dir: 'asc' }
],
// Searching
search: {
value: 'john',
keys: ['fullName', 'email']
},
// Filtering
filter: [
{ key: 'status', matchMode: 'equals', value: 'active' },
{ key: 'age', matchMode: 'greaterThan', value: 25 },
]
})
这个例子显示了pagination,多字段排序,全文搜索,以及带有嵌入条件和阵列字段匹配的复杂过滤.