Skip to content

Commit eb233be

Browse files
Copilothotlong
andcommitted
Update core documentation files with new query syntax
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 34a92ec commit eb233be

3 files changed

Lines changed: 51 additions & 46 deletions

File tree

content/docs/data-access/querying.mdx

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ The `find` method recovers a list of records matching specific criteria.
1515

1616
```typescript
1717
const products = await app.object('product').find({
18-
filters: [
19-
['category', '=', 'electronics'],
20-
['price', '>', 500]
21-
],
18+
filters: {
19+
category: 'electronics',
20+
price: { $gt: 500 }
21+
},
2222
fields: ['name', 'price', 'category'],
2323
sort: ['-price'], // Descending
2424
skip: 0,
@@ -28,19 +28,26 @@ const products = await app.object('product').find({
2828

2929
### Filters
3030

31-
Filters are defined as a 2D array: `[[ field, operator, value ]]`.
31+
Filters use an object-based syntax with implicit equality and operator objects.
3232

3333
**Implicit AND**:
3434
```typescript
35-
filters: [
36-
['status', '=', 'active'],
37-
['stock', '>', 0]
38-
]
35+
filters: {
36+
status: 'active',
37+
stock: { $gt: 0 }
38+
}
3939
// SQL: WHERE status = 'active' AND stock > 0
4040
```
4141

4242
**Explicit OR**:
43-
Use the `_or` special operator in complex filters (see advanced docs).
43+
```typescript
44+
filters: {
45+
$or: [
46+
{ status: 'active' },
47+
{ featured: true }
48+
]
49+
}
50+
```
4451

4552
### Sorting
4653

@@ -66,13 +73,13 @@ Updates are always bulk operations targeted by `filters`. To update a single rec
6673
```typescript
6774
// Update specific record
6875
await app.object('user').update(
69-
{ filters: [['_id', '=', '123']] }, // Target
76+
{ filters: { _id: '123' } }, // Target
7077
{ doc: { status: 'active' } } // Change
7178
);
7279

7380
// Bulk update
7481
await app.object('product').update(
75-
{ filters: [['stock', '=', 0]] },
82+
{ filters: { stock: 0 } },
7683
{ doc: { status: 'out_of_stock' } }
7784
);
7885
```
@@ -82,7 +89,7 @@ await app.object('product').update(
8289
```typescript
8390
// Delete specific record
8491
await app.object('user').delete({
85-
filters: [['_id', '=', '123']]
92+
filters: { _id: '123' }
8693
});
8794
```
8895

@@ -141,9 +148,9 @@ There are two ways to filter based on relationships:
141148
Find tasks where the *project's status* is active.
142149
*(Note: Requires a driver that supports SQL Joins)*
143150
```typescript
144-
filters: [
145-
['project.status', '=', 'active']
146-
]
151+
filters: {
152+
'project.status': 'active'
153+
}
147154
```
148155

149156
**B. Filter the Expanded List**
@@ -152,7 +159,7 @@ Find projects, but only include *completed* tasks in the expansion.
152159
app.object('project').find({
153160
expand: {
154161
tasks: {
155-
filters: [['status', '=', 'completed']]
162+
filters: { status: 'completed' }
156163
}
157164
}
158165
})
@@ -165,7 +172,7 @@ ObjectQL supports SQL-like aggregation via the `aggregate()` method on the repos
165172
```typescript
166173
const stats = await app.object('order').aggregate({
167174
// 1. Filter first
168-
filters: [['status', '=', 'paid']],
175+
filters: { status: 'paid' },
169176

170177
// 2. Group by specific fields
171178
groupBy: ['customer_id'],

content/docs/data-access/sdk.mdx

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ console.log(response.meta); // Pagination metadata
4545

4646
// With filters and pagination
4747
const activeUsers = await dataClient.list('users', {
48-
filter: [['status', '=', 'active']],
48+
filter: { status: 'active' },
4949
sort: [['created_at', 'desc']],
5050
limit: 20,
5151
skip: 0,
@@ -62,7 +62,7 @@ interface User {
6262
}
6363

6464
const users = await dataClient.list<User>('users', {
65-
filter: [['status', '=', 'active']]
65+
filter: { status: 'active' }
6666
});
6767

6868
users.items?.forEach(user => {
@@ -127,7 +127,7 @@ console.log(updated.updated_at); // New timestamp
127127

128128
```typescript
129129
const result = await dataClient.updateMany('users', {
130-
filters: [['status', '=', 'pending']],
130+
filters: { status: 'pending' },
131131
data: { status: 'active' }
132132
});
133133
```
@@ -143,7 +143,7 @@ console.log(result.success);
143143

144144
```typescript
145145
const result = await dataClient.deleteMany('users', {
146-
filters: [['created_at', '<', '2023-01-01']]
146+
filters: { created_at: { $lt: '2023-01-01' } }
147147
});
148148

149149
console.log(result.deleted_count);
@@ -152,9 +152,9 @@ console.log(result.deleted_count);
152152
### Count Records
153153

154154
```typescript
155-
const countResult = await dataClient.count('users', [
156-
['status', '=', 'active']
157-
]);
155+
const countResult = await dataClient.count('users', {
156+
status: 'active'
157+
});
158158

159159
console.log(countResult.count);
160160
```
@@ -336,7 +336,7 @@ interface User {
336336

337337
function UserList() {
338338
const { data: users, loading, error } = useObjectData<User>('users', {
339-
filter: [['status', '=', 'active']],
339+
filter: { status: 'active' },
340340
sort: [['name', 'asc']]
341341
});
342342

@@ -478,35 +478,33 @@ export function useObjectData<T>(objectName: string, params?: any) {
478478
### Complex Filter Expressions
479479

480480
```typescript
481-
// AND condition
481+
// AND condition (implicit)
482482
const result = await dataClient.list('orders', {
483-
filter: [
484-
'and',
485-
['status', '=', 'pending'],
486-
['total', '>', 100]
487-
]
483+
filter: {
484+
status: 'pending',
485+
total: { $gt: 100 }
486+
}
488487
});
489488

490489
// OR condition
491490
const result = await dataClient.list('users', {
492-
filter: [
493-
'or',
494-
['role', '=', 'admin'],
495-
['role', '=', 'manager']
496-
]
491+
filter: {
492+
$or: [
493+
{ role: 'admin' },
494+
{ role: 'manager' }
495+
]
496+
}
497497
});
498498

499499
// Nested conditions
500500
const result = await dataClient.list('orders', {
501-
filter: [
502-
'and',
503-
['status', '=', 'pending'],
504-
[
505-
'or',
506-
['priority', '=', 'high'],
507-
['total', '>', 1000]
501+
filter: {
502+
status: 'pending',
503+
$or: [
504+
{ priority: 'high' },
505+
{ total: { $gt: 1000 } }
508506
]
509-
]
507+
}
510508
});
511509
```
512510

content/docs/getting-started/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ async function main() {
156156

157157
// 4. Query Data
158158
const tasks = await todoRepo.find({
159-
filters: [['completed', '=', false]]
159+
filters: { completed: false }
160160
});
161161
console.log('Pending Tasks:', tasks);
162162
}

0 commit comments

Comments
 (0)