cl-orm 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/drivers/_utils.d.ts +4 -0
- package/lib/drivers/_utils.js +23 -0
- package/lib/drivers/d1.d.ts +2 -0
- package/lib/drivers/d1.js +48 -0
- package/lib/drivers/do.d.ts +2 -0
- package/lib/drivers/do.js +45 -0
- package/{src/index.ts → lib/index.d.ts} +1 -10
- package/lib/index.js +9 -0
- package/lib/queries/_utils.d.ts +1 -0
- package/lib/queries/_utils.js +13 -0
- package/lib/queries/delete.d.ts +5 -0
- package/lib/queries/delete.js +22 -0
- package/lib/queries/insert.d.ts +5 -0
- package/lib/queries/insert.js +19 -0
- package/lib/queries/select.d.ts +5 -0
- package/lib/queries/select.js +55 -0
- package/lib/queries/update.d.ts +5 -0
- package/lib/queries/update.js +25 -0
- package/lib/queries/where/operators.d.ts +23 -0
- package/lib/queries/where/operators.js +60 -0
- package/lib/queries/where/where.d.ts +5 -0
- package/lib/queries/where/where.js +34 -0
- package/lib/types.d.ts +64 -0
- package/lib/types.js +2 -0
- package/package.json +27 -2
- package/.editorconfig +0 -12
- package/.gitattributes +0 -1
- package/.prettierignore +0 -3
- package/.prettierrc +0 -34
- package/.vscode/settings.json +0 -14
- package/mcr.config.ts +0 -12
- package/src/drivers/_utils.ts +0 -31
- package/src/drivers/d1.ts +0 -70
- package/src/drivers/do.ts +0 -81
- package/src/queries/_utils.ts +0 -10
- package/src/queries/delete.ts +0 -26
- package/src/queries/insert.ts +0 -22
- package/src/queries/select.ts +0 -64
- package/src/queries/update.ts +0 -28
- package/src/queries/where/operators.ts +0 -96
- package/src/queries/where/where.ts +0 -50
- package/src/types.ts +0 -76
- package/test/__fixtures__/d1/worker.ts +0 -70
- package/test/__fixtures__/d1/wrangler.jsonc +0 -13
- package/test/__fixtures__/do/worker.ts +0 -106
- package/test/__fixtures__/do/wrangler.jsonc +0 -20
- package/test/e2e/d1.test.ts +0 -113
- package/test/e2e/do.test.ts +0 -116
- package/test/unit/buildDelete.test.ts +0 -36
- package/test/unit/buildInsert.test.ts +0 -36
- package/test/unit/buildSelect.test.ts +0 -137
- package/test/unit/buildUpdate.test.ts +0 -34
- package/test/unit/buildWhere.test.ts +0 -249
- package/test/unit/operators.test.ts +0 -98
- package/test/unit/prepare.test.ts +0 -22
- package/test/unit/quoteIdentifier.test.ts +0 -12
- package/test/unit/returnsRows.test.ts +0 -41
- package/test/unit/setMeta.test.ts +0 -31
- package/tsconfig.build.json +0 -4
- package/tsconfig.json +0 -34
- package/website/.prettierignore +0 -4
- package/website/.prettierrc +0 -34
- package/website/README.md +0 -3
- package/website/docs/documentation/connection.mdx +0 -123
- package/website/docs/documentation/queries/_category_.json +0 -7
- package/website/docs/documentation/queries/delete.mdx +0 -51
- package/website/docs/documentation/queries/insert.mdx +0 -63
- package/website/docs/documentation/queries/operators/_category_.json +0 -7
- package/website/docs/documentation/queries/operators/between.mdx +0 -17
- package/website/docs/documentation/queries/operators/eq.mdx +0 -22
- package/website/docs/documentation/queries/operators/gt.mdx +0 -22
- package/website/docs/documentation/queries/operators/gte.mdx +0 -22
- package/website/docs/documentation/queries/operators/in.mdx +0 -28
- package/website/docs/documentation/queries/operators/is-not-null.mdx +0 -22
- package/website/docs/documentation/queries/operators/is-null.mdx +0 -22
- package/website/docs/documentation/queries/operators/like.mdx +0 -27
- package/website/docs/documentation/queries/operators/lt.mdx +0 -22
- package/website/docs/documentation/queries/operators/lte.mdx +0 -22
- package/website/docs/documentation/queries/operators/ne.mdx +0 -22
- package/website/docs/documentation/queries/operators/not-between.mdx +0 -17
- package/website/docs/documentation/queries/operators/not-like.mdx +0 -27
- package/website/docs/documentation/queries/operators/notIn.mdx +0 -28
- package/website/docs/documentation/queries/select.mdx +0 -294
- package/website/docs/documentation/queries/update.mdx +0 -61
- package/website/docs/documentation/queries/where.mdx +0 -176
- package/website/docs/index.mdx +0 -228
- package/website/docusaurus.config.ts +0 -82
- package/website/package-lock.json +0 -21348
- package/website/package.json +0 -59
- package/website/plugins/locale.ts +0 -16
- package/website/sidebars.ts +0 -18
- package/website/src/components/FAQ.tsx +0 -35
- package/website/src/components/Loading.tsx +0 -4
- package/website/src/components/PageTitle.tsx +0 -29
- package/website/src/css/_faq.scss +0 -39
- package/website/src/css/_loading.scss +0 -43
- package/website/src/css/_mixins.scss +0 -19
- package/website/src/css/custom.scss +0 -149
- package/website/src/pages/index.tsx +0 -17
- package/website/static/.nojekyll +0 -0
- package/website/static/img/favicon.svg +0 -1
- package/website/test/unit/check-extensions.test.ts +0 -48
- package/website/tsconfig.json +0 -14
|
@@ -1,294 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
sidebar_position: 1
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# SELECT
|
|
6
|
-
|
|
7
|
-
> For **WHERE** examples, please see the **WHERE** section.
|
|
8
|
-
|
|
9
|
-
## Simple SELECT
|
|
10
|
-
|
|
11
|
-
```ts
|
|
12
|
-
// highlight-start
|
|
13
|
-
import { useD1 } from 'cl-orm';
|
|
14
|
-
|
|
15
|
-
const db = useD1(env.DB);
|
|
16
|
-
// highlight-end
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @return T[]
|
|
20
|
-
*/
|
|
21
|
-
await db.select({
|
|
22
|
-
table: 'test',
|
|
23
|
-
});
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
> SQL Query
|
|
27
|
-
|
|
28
|
-
```sql
|
|
29
|
-
SELECT * FROM test
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
<hr />
|
|
33
|
-
|
|
34
|
-
## SELECT (columns: string[])
|
|
35
|
-
|
|
36
|
-
```ts
|
|
37
|
-
// highlight-start
|
|
38
|
-
import { useD1 } from 'cl-orm';
|
|
39
|
-
|
|
40
|
-
const db = useD1(env.DB);
|
|
41
|
-
// highlight-end
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* @return T[]
|
|
45
|
-
*/
|
|
46
|
-
await db.select({
|
|
47
|
-
table: 'test',
|
|
48
|
-
columns: ['foo'],
|
|
49
|
-
});
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
> SQL Query
|
|
53
|
-
|
|
54
|
-
```sql
|
|
55
|
-
SELECT foo FROM test
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
<hr />
|
|
59
|
-
|
|
60
|
-
## SELECT (columns: string)
|
|
61
|
-
|
|
62
|
-
```ts
|
|
63
|
-
// highlight-start
|
|
64
|
-
import { useD1 } from 'cl-orm';
|
|
65
|
-
|
|
66
|
-
const db = useD1(env.DB);
|
|
67
|
-
// highlight-end
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* @return T[]
|
|
71
|
-
*/
|
|
72
|
-
await db.select({
|
|
73
|
-
table: 'test',
|
|
74
|
-
columns: 'COUNT(*) AS total',
|
|
75
|
-
});
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
> SQL Query
|
|
79
|
-
|
|
80
|
-
```sql
|
|
81
|
-
SELECT COUNT(*) AS total FROM test
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
<hr />
|
|
85
|
-
|
|
86
|
-
## SELECT (limit: number)
|
|
87
|
-
|
|
88
|
-
```ts
|
|
89
|
-
// highlight-start
|
|
90
|
-
import { useD1 } from 'cl-orm';
|
|
91
|
-
|
|
92
|
-
const db = useD1(env.DB);
|
|
93
|
-
// highlight-end
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* @return T[]
|
|
97
|
-
*/
|
|
98
|
-
await db.select({
|
|
99
|
-
table: 'test',
|
|
100
|
-
limit: 10,
|
|
101
|
-
});
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
> SQL Query
|
|
105
|
-
|
|
106
|
-
```sql
|
|
107
|
-
SELECT * FROM test LIMIT ?
|
|
108
|
-
-- params: [10]
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
- By using `limit: 1`, it will return a single **row** (`T | null`).
|
|
112
|
-
|
|
113
|
-
<hr />
|
|
114
|
-
|
|
115
|
-
## SELECT (offset: number)
|
|
116
|
-
|
|
117
|
-
```ts
|
|
118
|
-
// highlight-start
|
|
119
|
-
import { useD1 } from 'cl-orm';
|
|
120
|
-
|
|
121
|
-
const db = useD1(env.DB);
|
|
122
|
-
// highlight-end
|
|
123
|
-
|
|
124
|
-
await db.select({
|
|
125
|
-
table: 'test',
|
|
126
|
-
limit: 10,
|
|
127
|
-
offset: 20,
|
|
128
|
-
});
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
> SQL Query
|
|
132
|
-
|
|
133
|
-
```sql
|
|
134
|
-
SELECT * FROM test LIMIT ? OFFSET ?
|
|
135
|
-
-- params: [10, 20]
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
- By using `limit: 1`, it will return a single **row**.
|
|
139
|
-
|
|
140
|
-
<hr />
|
|
141
|
-
|
|
142
|
-
## SELECT (orderBy: [string, 'ASC' | 'DESC'])
|
|
143
|
-
|
|
144
|
-
```ts
|
|
145
|
-
// highlight-start
|
|
146
|
-
import { useD1 } from 'cl-orm';
|
|
147
|
-
|
|
148
|
-
const db = useD1(env.DB);
|
|
149
|
-
// highlight-end
|
|
150
|
-
|
|
151
|
-
await db.select({
|
|
152
|
-
table: 'test',
|
|
153
|
-
orderBy: ['id'],
|
|
154
|
-
// orderBy: ['id', 'ASC'],
|
|
155
|
-
// orderBy: ['id', 'DESC'],
|
|
156
|
-
});
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
> SQL Query
|
|
160
|
-
|
|
161
|
-
```sql
|
|
162
|
-
SELECT * FROM test ORDER BY id ASC
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
<hr />
|
|
166
|
-
|
|
167
|
-
## SELECT (groupBy: string)
|
|
168
|
-
|
|
169
|
-
```ts
|
|
170
|
-
// highlight-start
|
|
171
|
-
import { useD1 } from 'cl-orm';
|
|
172
|
-
|
|
173
|
-
const db = useD1(env.DB);
|
|
174
|
-
// highlight-end
|
|
175
|
-
|
|
176
|
-
await db.select({
|
|
177
|
-
columns: 'age, COUNT(*) AS total',
|
|
178
|
-
table: 'users',
|
|
179
|
-
groupBy: 'age',
|
|
180
|
-
});
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
> SQL Query
|
|
184
|
-
|
|
185
|
-
```sql
|
|
186
|
-
SELECT age, COUNT(*) AS total FROM users GROUP BY age
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
<hr />
|
|
190
|
-
|
|
191
|
-
## SELECT (join: JoinOptions | JoinOptions[])
|
|
192
|
-
|
|
193
|
-
```ts
|
|
194
|
-
// highlight-start
|
|
195
|
-
import { useD1 } from 'cl-orm';
|
|
196
|
-
|
|
197
|
-
const db = useD1(env.DB);
|
|
198
|
-
// highlight-end
|
|
199
|
-
|
|
200
|
-
await db.select({
|
|
201
|
-
columns: ['users.name', 'users.age'],
|
|
202
|
-
table: 'preferences',
|
|
203
|
-
join: {
|
|
204
|
-
type: 'left',
|
|
205
|
-
table: 'users',
|
|
206
|
-
on: {
|
|
207
|
-
a: 'preferences.userId',
|
|
208
|
-
b: 'users.id',
|
|
209
|
-
},
|
|
210
|
-
},
|
|
211
|
-
});
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
> SQL Query
|
|
215
|
-
|
|
216
|
-
```sql
|
|
217
|
-
SELECT users.name, users.age
|
|
218
|
-
FROM preferences
|
|
219
|
-
LEFT JOIN users ON preferences.userId = users.id
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
- You can insert multiple `JOIN` by using them within an array.
|
|
223
|
-
|
|
224
|
-
<hr />
|
|
225
|
-
|
|
226
|
-
## Available options
|
|
227
|
-
|
|
228
|
-
```ts
|
|
229
|
-
export type SelectOptions = {
|
|
230
|
-
distinct?: boolean;
|
|
231
|
-
columns?: string | string[];
|
|
232
|
-
table: string;
|
|
233
|
-
join?: JoinOptions | JoinOptions[];
|
|
234
|
-
where?: WhereClause;
|
|
235
|
-
limit?: number;
|
|
236
|
-
offset?: number;
|
|
237
|
-
groupBy?: string;
|
|
238
|
-
orderBy?: [string] | [string, 'ASC' | 'DESC'];
|
|
239
|
-
params?: unknown[];
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
export type JoinOptions = {
|
|
243
|
-
type: 'left' | 'right' | 'inner' | 'cross';
|
|
244
|
-
table: string;
|
|
245
|
-
on: {
|
|
246
|
-
a: string;
|
|
247
|
-
b: string;
|
|
248
|
-
};
|
|
249
|
-
outer?: boolean;
|
|
250
|
-
};
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
<hr />
|
|
254
|
-
|
|
255
|
-
## Type Assertion
|
|
256
|
-
|
|
257
|
-
The `select` method provides type assertion.
|
|
258
|
-
|
|
259
|
-
```ts
|
|
260
|
-
import { useD1 } from 'cl-orm';
|
|
261
|
-
|
|
262
|
-
// highlight-start
|
|
263
|
-
const db = useD1(env.DB);
|
|
264
|
-
// highlight-end
|
|
265
|
-
|
|
266
|
-
interface User {
|
|
267
|
-
id: number;
|
|
268
|
-
name: string;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* @return User[]
|
|
273
|
-
*/
|
|
274
|
-
const users = await db.select<User>({
|
|
275
|
-
table: 'test',
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* @return User | null
|
|
280
|
-
*/
|
|
281
|
-
const user = await db.select<User>({
|
|
282
|
-
table: 'test',
|
|
283
|
-
limit: 1,
|
|
284
|
-
});
|
|
285
|
-
```
|
|
286
|
-
|
|
287
|
-
:::note
|
|
288
|
-
|
|
289
|
-
The return type as `T | null` or `T[]` is determined by `limit`, not the type assertion itself:
|
|
290
|
-
|
|
291
|
-
- **If no `limit` is set or it's greater than 1:** `T[]` will be returned.
|
|
292
|
-
- **Setting `limit: 1`:** `T | null` will be returned.
|
|
293
|
-
|
|
294
|
-
:::
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
sidebar_position: 3
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# UPDATE
|
|
6
|
-
|
|
7
|
-
> For **WHERE** examples, please see the **WHERE** section.
|
|
8
|
-
|
|
9
|
-
## Simple update
|
|
10
|
-
|
|
11
|
-
```ts
|
|
12
|
-
// highlight-start
|
|
13
|
-
import { useD1 } from 'cl-orm';
|
|
14
|
-
|
|
15
|
-
const db = useD1(env.DB);
|
|
16
|
-
// highlight-end
|
|
17
|
-
|
|
18
|
-
await db.update({
|
|
19
|
-
table: 'users',
|
|
20
|
-
set: {
|
|
21
|
-
name: 'John',
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
> SQL Query
|
|
27
|
-
|
|
28
|
-
```sql
|
|
29
|
-
UPDATE users SET name = ?
|
|
30
|
-
-- params: ['John']
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
<hr />
|
|
34
|
-
|
|
35
|
-
## Update multiple columns
|
|
36
|
-
|
|
37
|
-
```ts
|
|
38
|
-
// highlight-start
|
|
39
|
-
import { useD1 } from 'cl-orm';
|
|
40
|
-
|
|
41
|
-
const db = useD1(env.DB);
|
|
42
|
-
// highlight-end
|
|
43
|
-
|
|
44
|
-
await db.update({
|
|
45
|
-
table: 'users',
|
|
46
|
-
set: {
|
|
47
|
-
name: 'John',
|
|
48
|
-
age: 29,
|
|
49
|
-
// highlight-start
|
|
50
|
-
// ...
|
|
51
|
-
// highlight-end
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
> SQL Query
|
|
57
|
-
|
|
58
|
-
```sql
|
|
59
|
-
UPDATE users SET name = ?, age = ?
|
|
60
|
-
-- params: ['John', 29]
|
|
61
|
-
```
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
sidebar_position: 5
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# WHERE Clauses
|
|
6
|
-
|
|
7
|
-
The **WHERE** clause is essential for filtering records in `SELECT`, `UPDATE`, and `DELETE` operations.<br/>
|
|
8
|
-
With **CL ORM**, you can use the [**OP**](/docs/category/operators) object to construct complex queries efficiently.
|
|
9
|
-
|
|
10
|
-
The operator names **eq**, **ne**, **gt**, **lt**, **gte** and **lte** are inspired by [**Sequelize**](https://sequelize.org/docs/v6/core-concepts/model-querying-basics/#operators).<br />
|
|
11
|
-
See all available operators [**here**](/docs/category/operators).
|
|
12
|
-
|
|
13
|
-
> The following examples apply as well to **SELECT**, **UPDATE** and **DELETE**.
|
|
14
|
-
|
|
15
|
-
## Single condition
|
|
16
|
-
|
|
17
|
-
```ts
|
|
18
|
-
// highlight-start
|
|
19
|
-
import { OP, useD1 } from 'cl-orm';
|
|
20
|
-
|
|
21
|
-
const db = useD1(env.DB);
|
|
22
|
-
|
|
23
|
-
await db.select({
|
|
24
|
-
table: 'users',
|
|
25
|
-
// highlight-end
|
|
26
|
-
where: OP.eq('id', 15),
|
|
27
|
-
// highlight-start
|
|
28
|
-
});
|
|
29
|
-
// highlight-end
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
> SQL Query
|
|
33
|
-
|
|
34
|
-
```sql
|
|
35
|
-
-- highlight-start
|
|
36
|
-
SELECT * FROM users
|
|
37
|
-
-- highlight-end
|
|
38
|
-
WHERE id = ?
|
|
39
|
-
|
|
40
|
-
-- params [15]
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
<hr />
|
|
44
|
-
|
|
45
|
-
## Multiple conditions
|
|
46
|
-
|
|
47
|
-
Ensure to use **AND**, **OR**, **XOR** or **NOT** between each condition.
|
|
48
|
-
|
|
49
|
-
```ts
|
|
50
|
-
// highlight-start
|
|
51
|
-
import { OP, useD1 } from 'cl-orm';
|
|
52
|
-
|
|
53
|
-
const db = useD1(env.DB);
|
|
54
|
-
|
|
55
|
-
await db.select({
|
|
56
|
-
table: 'users',
|
|
57
|
-
// highlight-end
|
|
58
|
-
where: [OP.in('id', [15, 30]), 'AND', OP.eq('status', 1)],
|
|
59
|
-
// highlight-start
|
|
60
|
-
});
|
|
61
|
-
// highlight-end
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
> SQL Query
|
|
65
|
-
|
|
66
|
-
```sql
|
|
67
|
-
-- highlight-start
|
|
68
|
-
SELECT * FROM users
|
|
69
|
-
-- highlight-end
|
|
70
|
-
WHERE id IN (?, ?) AND status = ?
|
|
71
|
-
|
|
72
|
-
-- params [15, 30, 1]
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
<hr />
|
|
76
|
-
|
|
77
|
-
## Combine conditions
|
|
78
|
-
|
|
79
|
-
Ensure to use **AND**, **OR**, **XOR** or **NOT** between each combination.
|
|
80
|
-
|
|
81
|
-
```ts
|
|
82
|
-
// highlight-start
|
|
83
|
-
import { OP, useD1 } from 'cl-orm';
|
|
84
|
-
|
|
85
|
-
const db = useD1(env.DB);
|
|
86
|
-
|
|
87
|
-
await db.select({
|
|
88
|
-
table: 'users',
|
|
89
|
-
// highlight-end
|
|
90
|
-
where: [[OP.lt('age', 18)], 'OR', [OP.eq('status', 'locked')]],
|
|
91
|
-
// highlight-start
|
|
92
|
-
});
|
|
93
|
-
// highlight-end
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
> SQL Query
|
|
97
|
-
|
|
98
|
-
```sql
|
|
99
|
-
-- highlight-start
|
|
100
|
-
SELECT * FROM users
|
|
101
|
-
-- highlight-end
|
|
102
|
-
WHERE (age < ?) OR (status = ?)
|
|
103
|
-
|
|
104
|
-
-- params [18, 'locked']
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
<hr />
|
|
108
|
-
|
|
109
|
-
## Combine multiple conditions
|
|
110
|
-
|
|
111
|
-
Ensure to use **AND**, **OR**, **XOR** or **NOT** between each condition and combination.
|
|
112
|
-
|
|
113
|
-
```ts
|
|
114
|
-
// highlight-start
|
|
115
|
-
import { OP, useD1 } from 'cl-orm';
|
|
116
|
-
|
|
117
|
-
const db = useD1(env.DB);
|
|
118
|
-
|
|
119
|
-
await db.select({
|
|
120
|
-
table: 'users',
|
|
121
|
-
// highlight-end
|
|
122
|
-
where: [
|
|
123
|
-
[OP.gte('age', 18), 'AND', OP.eq('status', 'locked')],
|
|
124
|
-
'OR',
|
|
125
|
-
[OP.lt('age', 18), 'AND', OP.eq('status', 'enabled')],
|
|
126
|
-
],
|
|
127
|
-
// highlight-start
|
|
128
|
-
});
|
|
129
|
-
// highlight-end
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
> SQL Query
|
|
133
|
-
|
|
134
|
-
```sql
|
|
135
|
-
-- highlight-start
|
|
136
|
-
SELECT * FROM users
|
|
137
|
-
-- highlight-end
|
|
138
|
-
WHERE (age >= ? AND status = ?) OR (age < ? AND status = ?);
|
|
139
|
-
|
|
140
|
-
-- params [18, 'locked', 18, 'enabled']
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
- You can play into depth with combined conditions by encapsulating your conditions in an array. But note that this can become complex.
|
|
144
|
-
|
|
145
|
-
<hr />
|
|
146
|
-
|
|
147
|
-
## Manual conditions
|
|
148
|
-
|
|
149
|
-
You can also use `where` as a string, creating your conditions and passing the params manually:
|
|
150
|
-
|
|
151
|
-
```ts
|
|
152
|
-
// highlight-start
|
|
153
|
-
import { useD1 } from 'cl-orm';
|
|
154
|
-
|
|
155
|
-
const db = useD1(env.DB);
|
|
156
|
-
|
|
157
|
-
await db.select({
|
|
158
|
-
table: 'users',
|
|
159
|
-
// highlight-end
|
|
160
|
-
where: 'createdAt > ?',
|
|
161
|
-
params: ['2024-01-01'],
|
|
162
|
-
// highlight-start
|
|
163
|
-
});
|
|
164
|
-
// highlight-end
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
> SQL Query
|
|
168
|
-
|
|
169
|
-
```sql
|
|
170
|
-
-- highlight-start
|
|
171
|
-
SELECT * FROM users
|
|
172
|
-
-- highlight-end
|
|
173
|
-
WHERE createdAt > ?
|
|
174
|
-
|
|
175
|
-
-- params ['2024-01-01']
|
|
176
|
-
```
|