litedbmodel 2.2.9 → 2.2.11
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/README.md +8 -5
- package/dist/DBHandler.d.ts +2 -28
- package/dist/DBHandler.d.ts.map +1 -1
- package/dist/DBHandler.js.map +1 -1
- package/dist/DBModel.d.ts +14 -12
- package/dist/DBModel.d.ts.map +1 -1
- package/dist/DBModel.js +71 -72
- package/dist/DBModel.js.map +1 -1
- package/dist/LazyRelation.d.ts +1 -0
- package/dist/LazyRelation.d.ts.map +1 -1
- package/dist/LazyRelation.js +17 -14
- package/dist/LazyRelation.js.map +1 -1
- package/dist/Middleware.d.ts +19 -17
- package/dist/Middleware.d.ts.map +1 -1
- package/dist/Middleware.js +30 -33
- package/dist/Middleware.js.map +1 -1
- package/dist/drivers/mysql.d.ts.map +1 -1
- package/dist/drivers/mysql.js +1 -0
- package/dist/drivers/mysql.js.map +1 -1
- package/dist/drivers/postgres.d.ts.map +1 -1
- package/dist/drivers/postgres.js +42 -22
- package/dist/drivers/postgres.js.map +1 -1
- package/dist/drivers/types.d.ts +2 -26
- package/dist/drivers/types.d.ts.map +1 -1
- package/dist/drivers/types.js.map +1 -1
- package/dist/index.cjs +224 -163
- package/dist/scp/connection-routing.d.ts +50 -18
- package/dist/scp/connection-routing.d.ts.map +1 -1
- package/dist/scp/connection-routing.js +55 -24
- package/dist/scp/connection-routing.js.map +1 -1
- package/dist/scp/dbmodel-runtime.d.ts +3 -0
- package/dist/scp/dbmodel-runtime.d.ts.map +1 -1
- package/dist/scp/dbmodel-runtime.js +2 -0
- package/dist/scp/dbmodel-runtime.js.map +1 -1
- package/dist/scp/exec-context.d.ts.map +1 -1
- package/dist/scp/exec-context.js +54 -46
- package/dist/scp/exec-context.js.map +1 -1
- package/dist/scp/index.cjs +99 -48
- package/dist/scp/index.mjs +96 -47
- package/dist/scp/makesql/pool-executor.d.ts +4 -1
- package/dist/scp/makesql/pool-executor.d.ts.map +1 -1
- package/dist/scp/makesql/pool-executor.js +21 -3
- package/dist/scp/makesql/pool-executor.js.map +1 -1
- package/dist/types.d.ts +9 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/docs/BENCHMARK.md +1 -1
- package/docs/COMPARISON.md +2 -2
- package/docs/api/README.md +1 -1
- package/docs/api/classes/Conditions.md +1 -1
- package/docs/api/classes/DBHandler.md +16 -16
- package/docs/api/classes/DBModel.md +94 -93
- package/docs/api/classes/LimitExceededError.md +8 -8
- package/docs/api/classes/Middleware.md +35 -31
- package/docs/api/classes/SqlRaw.md +1 -1
- package/docs/api/classes/SqlRef.md +1 -1
- package/docs/api/classes/Values.md +1 -1
- package/docs/api/classes/WriteInReadOnlyContextError.md +5 -5
- package/docs/api/classes/WriteOutsideTransactionError.md +5 -5
- package/docs/api/functions/belongsTo.md +1 -1
- package/docs/api/functions/closeAllPools.md +2 -2
- package/docs/api/functions/condsToRecord.md +1 -1
- package/docs/api/functions/createMiddleware.md +4 -4
- package/docs/api/functions/createPostgresDriver.md +2 -2
- package/docs/api/functions/createSqliteDriver.md +1 -1
- package/docs/api/functions/dbCast.md +1 -1
- package/docs/api/functions/dbCastIn.md +1 -1
- package/docs/api/functions/dbDynamic.md +1 -1
- package/docs/api/functions/dbFalse.md +1 -1
- package/docs/api/functions/dbImmediate.md +1 -1
- package/docs/api/functions/dbIn.md +1 -1
- package/docs/api/functions/dbNotNull.md +1 -1
- package/docs/api/functions/dbNow.md +1 -1
- package/docs/api/functions/dbNull.md +1 -1
- package/docs/api/functions/dbRaw.md +1 -1
- package/docs/api/functions/dbTrue.md +1 -1
- package/docs/api/functions/dbUuid.md +1 -1
- package/docs/api/functions/dbUuidIn.md +1 -1
- package/docs/api/functions/formatLocalDate.md +1 -1
- package/docs/api/functions/formatUTCDate.md +1 -1
- package/docs/api/functions/getDBConfig.md +2 -2
- package/docs/api/functions/getDBHandler.md +2 -2
- package/docs/api/functions/getTransactionConnection.md +2 -2
- package/docs/api/functions/getTransactionContext.md +2 -2
- package/docs/api/functions/hasMany.md +1 -1
- package/docs/api/functions/hasOne.md +1 -1
- package/docs/api/functions/initDBHandler.md +2 -2
- package/docs/api/functions/isAnySqlFragment.md +1 -1
- package/docs/api/functions/isConnectionError.md +1 -1
- package/docs/api/functions/isSqlCondition.md +1 -1
- package/docs/api/functions/isSqlFragment.md +1 -1
- package/docs/api/functions/isSqlRaw.md +1 -1
- package/docs/api/functions/isSqlRef.md +1 -1
- package/docs/api/functions/isSqlTypedFragment.md +1 -1
- package/docs/api/functions/model.md +1 -1
- package/docs/api/functions/parentRef.md +1 -1
- package/docs/api/functions/sql.md +1 -1
- package/docs/api/globals.md +5 -5
- package/docs/api/interfaces/Column.md +1 -1
- package/docs/api/interfaces/ColumnDecorator.md +1 -1
- package/docs/api/interfaces/ColumnOptions.md +1 -1
- package/docs/api/interfaces/CreatedMiddlewareClass.md +7 -7
- package/docs/api/interfaces/DBConfig.md +29 -14
- package/docs/api/interfaces/DBConfigOptions.md +8 -8
- package/docs/api/interfaces/DeleteOptions.md +4 -4
- package/docs/api/interfaces/InsertOptions.md +8 -8
- package/docs/api/interfaces/LimitConfig.md +4 -4
- package/docs/api/interfaces/MiddlewareConfig.md +15 -15
- package/docs/api/interfaces/ModelClassDecorator.md +1 -1
- package/docs/api/interfaces/ModelOptions.md +1 -1
- package/docs/api/interfaces/PkeyResult.md +1 -1
- package/docs/api/interfaces/RelationDecorator.md +1 -1
- package/docs/api/interfaces/SelectOptions.md +17 -17
- package/docs/api/interfaces/SqlCondition.md +1 -1
- package/docs/api/interfaces/SqlFragment.md +1 -1
- package/docs/api/interfaces/SqlTypedFragment.md +1 -1
- package/docs/api/interfaces/TransactionOptions.md +7 -7
- package/docs/api/interfaces/UpdateManyOptions.md +4 -4
- package/docs/api/interfaces/UpdateOptions.md +4 -4
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[**litedbmodel v2.2.
|
|
1
|
+
[**litedbmodel v2.2.11**](../README.md)
|
|
2
2
|
|
|
3
3
|
***
|
|
4
4
|
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
# Abstract Class: DBModel
|
|
8
8
|
|
|
9
|
-
Defined in: [DBModel.ts:
|
|
9
|
+
Defined in: [DBModel.ts:141](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L141)
|
|
10
10
|
|
|
11
11
|
Base class for all database models in litedbmodel.
|
|
12
12
|
Provides CRUD operations, relations, transactions, and middleware support.
|
|
@@ -63,7 +63,7 @@ const john = await User.findOne([[User.email, 'john@example.com']]);
|
|
|
63
63
|
new DBModel(): DBModel;
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
Defined in: [DBModel.ts:
|
|
66
|
+
Defined in: [DBModel.ts:1871](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L1871)
|
|
67
67
|
|
|
68
68
|
#### Returns
|
|
69
69
|
|
|
@@ -73,19 +73,19 @@ Defined in: [DBModel.ts:1882](https://github.com/foo-ogawa/litedbmodel/blob/main
|
|
|
73
73
|
|
|
74
74
|
| Property | Modifier | Type | Default value | Description | Defined in |
|
|
75
75
|
| ------ | ------ | ------ | ------ | ------ | ------ |
|
|
76
|
-
| <a id="query"></a> `QUERY` | `static` | \| `string` \| [`SqlFragment`](../interfaces/SqlFragment.md) \| [`SqlTypedFragment`](../interfaces/SqlTypedFragment.md)\<`unknown`, `unknown`\> \| [`SqlCondition`](../interfaces/SqlCondition.md)\<`unknown`\> \| `null` | `null` | SQL query for query-based models (view models, aggregations, etc.) When defined, the model uses this query as a CTE instead of TABLE_NAME. **Example** `// Static query static QUERY = ` SELECT users.id, COUNT(posts.id) as post_count FROM users LEFT JOIN posts ON users.id = posts.user_id GROUP BY users.id `;` | [DBModel.ts:
|
|
77
|
-
| <a id="_dbconfig"></a> `_dbConfig` | `static` | [`DBConfig`](../interfaces/DBConfig.md) \| `null` | `null` | Database config | [DBModel.ts:
|
|
78
|
-
| <a id="_limitconfig"></a> `_limitConfig` | `static` | [`LimitConfig`](../interfaces/LimitConfig.md) | `{}` | Limit config for safety guards | [DBModel.ts:
|
|
79
|
-
| <a id="_configoptions"></a> `_configOptions` | `static` | [`DBConfigOptions`](../interfaces/DBConfigOptions.md) | `undefined` | Configuration options for reader/writer separation | [DBModel.ts:
|
|
80
|
-
| <a id="
|
|
81
|
-
| <a id="true"></a> `true` | `readonly` | `DBBoolValue` | `undefined` | Boolean TRUE value | [DBModel.ts:
|
|
82
|
-
| <a id="false"></a> `false` | `readonly` | `DBBoolValue` | `undefined` | Boolean FALSE value | [DBModel.ts:
|
|
83
|
-
| <a id="null"></a> `null` | `readonly` | `DBNullValue` | `undefined` | NULL value | [DBModel.ts:
|
|
84
|
-
| <a id="notnull"></a> `notNull` | `readonly` | `DBNotNullValue` | `undefined` | NOT NULL value | [DBModel.ts:
|
|
85
|
-
| <a id="now"></a> `now` | `readonly` | `DBImmediateValue` | `undefined` | NOW() value | [DBModel.ts:
|
|
86
|
-
| <a id="_modelclass"></a> `_modelClass` | `protected` | *typeof* `DBModel` | `undefined` | Instance reference to the static class | [DBModel.ts:
|
|
87
|
-
| <a id="_relationcache"></a> `_relationCache` | `protected` | `Map`\<`string`, `unknown`\> \| `null` | `null` | Per-instance cache for loaded relations (lazy-initialized) | [DBModel.ts:
|
|
88
|
-
| <a id="_deferredcontext"></a> `_deferredContext` | `public` | \[*typeof* `DBModel`, `DBModel`[]\] \| `null` | `null` | Deferred context info: [sourceClass, records] set by _select, resolved on first relation access | [DBModel.ts:
|
|
76
|
+
| <a id="query"></a> `QUERY` | `static` | \| `string` \| [`SqlFragment`](../interfaces/SqlFragment.md) \| [`SqlTypedFragment`](../interfaces/SqlTypedFragment.md)\<`unknown`, `unknown`\> \| [`SqlCondition`](../interfaces/SqlCondition.md)\<`unknown`\> \| `null` | `null` | SQL query for query-based models (view models, aggregations, etc.) When defined, the model uses this query as a CTE instead of TABLE_NAME. **Example** `// Static query static QUERY = ` SELECT users.id, COUNT(posts.id) as post_count FROM users LEFT JOIN posts ON users.id = posts.user_id GROUP BY users.id `;` | [DBModel.ts:200](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L200) |
|
|
77
|
+
| <a id="_dbconfig"></a> `_dbConfig` | `static` | [`DBConfig`](../interfaces/DBConfig.md) \| `null` | `null` | Database config | [DBModel.ts:222](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L222) |
|
|
78
|
+
| <a id="_limitconfig"></a> `_limitConfig` | `static` | [`LimitConfig`](../interfaces/LimitConfig.md) | `{}` | Limit config for safety guards | [DBModel.ts:225](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L225) |
|
|
79
|
+
| <a id="_configoptions"></a> `_configOptions` | `static` | [`DBConfigOptions`](../interfaces/DBConfigOptions.md) | `undefined` | Configuration options for reader/writer separation | [DBModel.ts:228](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L228) |
|
|
80
|
+
| <a id="_writersticky"></a> `_writerSticky` | `static` | `WriterStickyClock` | `undefined` | Writer-sticky clock of the v1 execution path (the SCP runtime carries its own in its routing). | [DBModel.ts:234](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L234) |
|
|
81
|
+
| <a id="true"></a> `true` | `readonly` | `DBBoolValue` | `undefined` | Boolean TRUE value | [DBModel.ts:1458](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L1458) |
|
|
82
|
+
| <a id="false"></a> `false` | `readonly` | `DBBoolValue` | `undefined` | Boolean FALSE value | [DBModel.ts:1461](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L1461) |
|
|
83
|
+
| <a id="null"></a> `null` | `readonly` | `DBNullValue` | `undefined` | NULL value | [DBModel.ts:1464](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L1464) |
|
|
84
|
+
| <a id="notnull"></a> `notNull` | `readonly` | `DBNotNullValue` | `undefined` | NOT NULL value | [DBModel.ts:1467](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L1467) |
|
|
85
|
+
| <a id="now"></a> `now` | `readonly` | `DBImmediateValue` | `undefined` | NOW() value | [DBModel.ts:1470](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L1470) |
|
|
86
|
+
| <a id="_modelclass"></a> `_modelClass` | `protected` | *typeof* `DBModel` | `undefined` | Instance reference to the static class | [DBModel.ts:1860](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L1860) |
|
|
87
|
+
| <a id="_relationcache"></a> `_relationCache` | `protected` | `Map`\<`string`, `unknown`\> \| `null` | `null` | Per-instance cache for loaded relations (lazy-initialized) | [DBModel.ts:1863](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L1863) |
|
|
88
|
+
| <a id="_deferredcontext"></a> `_deferredContext` | `public` | \[*typeof* `DBModel`, `DBModel`[]\] \| `null` | `null` | Deferred context info: [sourceClass, records] set by _select, resolved on first relation access | [DBModel.ts:1869](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L1869) |
|
|
89
89
|
|
|
90
90
|
## Methods
|
|
91
91
|
|
|
@@ -95,7 +95,7 @@ Defined in: [DBModel.ts:1882](https://github.com/foo-ogawa/litedbmodel/blob/main
|
|
|
95
95
|
static asModel<T>(this: T): T & ColumnsOf<InstanceType<T>>;
|
|
96
96
|
```
|
|
97
97
|
|
|
98
|
-
Defined in: [DBModel.ts:
|
|
98
|
+
Defined in: [DBModel.ts:167](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L167)
|
|
99
99
|
|
|
100
100
|
Returns the model class with type-safe column properties.
|
|
101
101
|
Use this instead of manual casting with `ColumnsOf`.
|
|
@@ -139,7 +139,7 @@ await User.find([[User.name, 'John']]);
|
|
|
139
139
|
static setConfig(config: DBConfig, options?: DBConfigOptions): void;
|
|
140
140
|
```
|
|
141
141
|
|
|
142
|
-
Defined in: [DBModel.ts:
|
|
142
|
+
Defined in: [DBModel.ts:395](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L395)
|
|
143
143
|
|
|
144
144
|
Initialize DBModel with database config.
|
|
145
145
|
Call this once at application startup.
|
|
@@ -188,7 +188,7 @@ DBModel.setConfig(
|
|
|
188
188
|
static getLimitConfig(): LimitConfig;
|
|
189
189
|
```
|
|
190
190
|
|
|
191
|
-
Defined in: [DBModel.ts:
|
|
191
|
+
Defined in: [DBModel.ts:428](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L428)
|
|
192
192
|
|
|
193
193
|
Get current limit configuration.
|
|
194
194
|
|
|
@@ -204,7 +204,7 @@ Get current limit configuration.
|
|
|
204
204
|
static setLimitConfig(config: LimitConfig): void;
|
|
205
205
|
```
|
|
206
206
|
|
|
207
|
-
Defined in: [DBModel.ts:
|
|
207
|
+
Defined in: [DBModel.ts:443](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L443)
|
|
208
208
|
|
|
209
209
|
Update limit configuration.
|
|
210
210
|
|
|
@@ -236,7 +236,7 @@ DBModel.setLimitConfig({ findHardLimit: null, hasManyHardLimit: null });
|
|
|
236
236
|
static getDBConfig(): DBConfig | null;
|
|
237
237
|
```
|
|
238
238
|
|
|
239
|
-
Defined in: [DBModel.ts:
|
|
239
|
+
Defined in: [DBModel.ts:450](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L450)
|
|
240
240
|
|
|
241
241
|
Get database config
|
|
242
242
|
|
|
@@ -249,17 +249,17 @@ Get database config
|
|
|
249
249
|
### getDriverType()
|
|
250
250
|
|
|
251
251
|
```ts
|
|
252
|
-
static getDriverType(): "postgres" | "
|
|
252
|
+
static getDriverType(): "postgres" | "sqlite" | "mysql";
|
|
253
253
|
```
|
|
254
254
|
|
|
255
|
-
Defined in: [DBModel.ts:
|
|
255
|
+
Defined in: [DBModel.ts:458](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L458)
|
|
256
256
|
|
|
257
257
|
Get the database driver type.
|
|
258
258
|
Returns 'postgres', 'mysql', or 'sqlite'.
|
|
259
259
|
|
|
260
260
|
#### Returns
|
|
261
261
|
|
|
262
|
-
`"postgres"` \| `"
|
|
262
|
+
`"postgres"` \| `"sqlite"` \| `"mysql"`
|
|
263
263
|
|
|
264
264
|
***
|
|
265
265
|
|
|
@@ -269,14 +269,11 @@ Returns 'postgres', 'mysql', or 'sqlite'.
|
|
|
269
269
|
protected static getHandler(): DBHandler;
|
|
270
270
|
```
|
|
271
271
|
|
|
272
|
-
Defined in: [DBModel.ts:
|
|
272
|
+
Defined in: [DBModel.ts:509](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L509)
|
|
273
273
|
|
|
274
|
-
Get a DBHandler instance for this model
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
2. Writer context (if in withWriter())
|
|
278
|
-
3. Writer sticky (if within writerStickyDuration after transaction)
|
|
279
|
-
4. Default reader connection
|
|
274
|
+
Get a DBHandler instance for this model: the transaction's handler inside a transaction, else the
|
|
275
|
+
default handler (whose reads `execute()` sends to the writer inside `withWriter()` or while
|
|
276
|
+
writer-sticky).
|
|
280
277
|
|
|
281
278
|
#### Returns
|
|
282
279
|
|
|
@@ -290,9 +287,10 @@ Connection priority:
|
|
|
290
287
|
protected static _shouldUseWriterSticky(): boolean;
|
|
291
288
|
```
|
|
292
289
|
|
|
293
|
-
Defined in: [DBModel.ts:
|
|
290
|
+
Defined in: [DBModel.ts:524](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L524)
|
|
294
291
|
|
|
295
|
-
Check if
|
|
292
|
+
Check if this async chain should read from the writer because it committed a transaction within
|
|
293
|
+
`writerStickyDuration` (read-your-writes for the request that wrote).
|
|
296
294
|
|
|
297
295
|
#### Returns
|
|
298
296
|
|
|
@@ -306,7 +304,7 @@ Check if we should use writer due to sticky after transaction.
|
|
|
306
304
|
protected static _getTransactionContext(): AsyncLocalStorage<TransactionContext>;
|
|
307
305
|
```
|
|
308
306
|
|
|
309
|
-
Defined in: [DBModel.ts:
|
|
307
|
+
Defined in: [DBModel.ts:532](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L532)
|
|
310
308
|
|
|
311
309
|
Get transaction context storage.
|
|
312
310
|
Override in subclass to use independent transaction context.
|
|
@@ -323,7 +321,7 @@ Override in subclass to use independent transaction context.
|
|
|
323
321
|
protected static _getWriterContext(): AsyncLocalStorage<WriterContext>;
|
|
324
322
|
```
|
|
325
323
|
|
|
326
|
-
Defined in: [DBModel.ts:
|
|
324
|
+
Defined in: [DBModel.ts:540](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L540)
|
|
327
325
|
|
|
328
326
|
Get writer context storage.
|
|
329
327
|
Override in subclass to use independent writer context.
|
|
@@ -340,7 +338,7 @@ Override in subclass to use independent writer context.
|
|
|
340
338
|
static inWriterContext(): boolean;
|
|
341
339
|
```
|
|
342
340
|
|
|
343
|
-
Defined in: [DBModel.ts:
|
|
341
|
+
Defined in: [DBModel.ts:547](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L547)
|
|
344
342
|
|
|
345
343
|
Check if currently in a withWriter context.
|
|
346
344
|
|
|
@@ -356,7 +354,7 @@ Check if currently in a withWriter context.
|
|
|
356
354
|
static use(MiddlewareClass: MiddlewareClass): () => void;
|
|
357
355
|
```
|
|
358
356
|
|
|
359
|
-
Defined in: [DBModel.ts:
|
|
357
|
+
Defined in: [DBModel.ts:593](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L593)
|
|
360
358
|
|
|
361
359
|
Register a middleware class to intercept DBModel methods.
|
|
362
360
|
|
|
@@ -395,8 +393,11 @@ class LoggerMiddleware extends Middleware {
|
|
|
395
393
|
|
|
396
394
|
DBModel.use(LoggerMiddleware);
|
|
397
395
|
|
|
398
|
-
//
|
|
399
|
-
|
|
396
|
+
// One request
|
|
397
|
+
await Middleware.run(async () => {
|
|
398
|
+
await handleRequest();
|
|
399
|
+
console.log(LoggerMiddleware.getCurrentContext().getLogs());
|
|
400
|
+
});
|
|
400
401
|
```
|
|
401
402
|
|
|
402
403
|
***
|
|
@@ -407,7 +408,7 @@ console.log(LoggerMiddleware.getCurrentContext().getLogs());
|
|
|
407
408
|
static createMiddleware<S>(config: MiddlewareConfig<S>): CreatedMiddlewareClass<S>;
|
|
408
409
|
```
|
|
409
410
|
|
|
410
|
-
Defined in: [DBModel.ts:
|
|
411
|
+
Defined in: [DBModel.ts:645](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L645)
|
|
411
412
|
|
|
412
413
|
Create a middleware class from a configuration object.
|
|
413
414
|
|
|
@@ -461,7 +462,7 @@ const TenantMiddleware = DBModel.createMiddleware({
|
|
|
461
462
|
// Register
|
|
462
463
|
DBModel.use(TenantMiddleware);
|
|
463
464
|
|
|
464
|
-
// Set tenant for current request (type-safe)
|
|
465
|
+
// Set tenant for the current request (inside Middleware.run at the request entry, type-safe)
|
|
465
466
|
TenantMiddleware.getCurrentContext().tenantId = 123;
|
|
466
467
|
```
|
|
467
468
|
|
|
@@ -473,7 +474,7 @@ TenantMiddleware.getCurrentContext().tenantId = 123;
|
|
|
473
474
|
static removeMiddleware(MiddlewareClass: MiddlewareClass): boolean;
|
|
474
475
|
```
|
|
475
476
|
|
|
476
|
-
Defined in: [DBModel.ts:
|
|
477
|
+
Defined in: [DBModel.ts:656](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L656)
|
|
477
478
|
|
|
478
479
|
Remove a middleware class
|
|
479
480
|
|
|
@@ -497,7 +498,7 @@ true if middleware was found and removed
|
|
|
497
498
|
static clearMiddlewares(): void;
|
|
498
499
|
```
|
|
499
500
|
|
|
500
|
-
Defined in: [DBModel.ts:
|
|
501
|
+
Defined in: [DBModel.ts:668](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L668)
|
|
501
502
|
|
|
502
503
|
Clear all middlewares (useful for testing)
|
|
503
504
|
|
|
@@ -513,7 +514,7 @@ Clear all middlewares (useful for testing)
|
|
|
513
514
|
static getMiddlewares(): readonly MiddlewareClass[];
|
|
514
515
|
```
|
|
515
516
|
|
|
516
|
-
Defined in: [DBModel.ts:
|
|
517
|
+
Defined in: [DBModel.ts:675](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L675)
|
|
517
518
|
|
|
518
519
|
Get registered middleware classes
|
|
519
520
|
|
|
@@ -536,7 +537,7 @@ static buildSelectSQL<T>(
|
|
|
536
537
|
};
|
|
537
538
|
```
|
|
538
539
|
|
|
539
|
-
Defined in: [DBModel.ts:
|
|
540
|
+
Defined in: [DBModel.ts:865](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L865)
|
|
540
541
|
|
|
541
542
|
Build SELECT SQL without executing.
|
|
542
543
|
Useful for constructing CTE/subquery SQL fragments.
|
|
@@ -570,8 +571,8 @@ Object with sql and params
|
|
|
570
571
|
|
|
571
572
|
| Name | Type | Defined in |
|
|
572
573
|
| ------ | ------ | ------ |
|
|
573
|
-
| `sql` | `string` | [DBModel.ts:
|
|
574
|
-
| `params` | `unknown`[] | [DBModel.ts:
|
|
574
|
+
| `sql` | `string` | [DBModel.ts:870](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L870) |
|
|
575
|
+
| `params` | `unknown`[] | [DBModel.ts:870](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L870) |
|
|
575
576
|
|
|
576
577
|
#### Example
|
|
577
578
|
|
|
@@ -593,7 +594,7 @@ const { sql, params } = User.buildSelectSQL(
|
|
|
593
594
|
protected static _mergeFindFilter(conditions: ConditionObject): ConditionObject;
|
|
594
595
|
```
|
|
595
596
|
|
|
596
|
-
Defined in: [DBModel.ts:
|
|
597
|
+
Defined in: [DBModel.ts:952](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L952)
|
|
597
598
|
|
|
598
599
|
Merge FIND_FILTER (the model's default filter) into a condition object (v1 `_buildSelectSQL` parity).
|
|
599
600
|
|
|
@@ -618,7 +619,7 @@ static inSubquery<T, S>(
|
|
|
618
619
|
conditions?: readonly [Column<any, S>, unknown][]): readonly [string, DBSubquery];
|
|
619
620
|
```
|
|
620
621
|
|
|
621
|
-
Defined in: [DBModel.ts:
|
|
622
|
+
Defined in: [DBModel.ts:1516](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L1516)
|
|
622
623
|
|
|
623
624
|
IN subquery condition.
|
|
624
625
|
Creates a condition like: column IN (SELECT selectColumn FROM targetModel WHERE ...)
|
|
@@ -686,7 +687,7 @@ static notInSubquery<T, S>(
|
|
|
686
687
|
conditions?: readonly [Column<any, S>, unknown][]): readonly [string, DBSubquery];
|
|
687
688
|
```
|
|
688
689
|
|
|
689
|
-
Defined in: [DBModel.ts:
|
|
690
|
+
Defined in: [DBModel.ts:1561](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L1561)
|
|
690
691
|
|
|
691
692
|
NOT IN subquery condition.
|
|
692
693
|
Creates a condition like: table.column NOT IN (SELECT table.column FROM targetModel WHERE ...)
|
|
@@ -739,7 +740,7 @@ await User.find([
|
|
|
739
740
|
static exists<S>(conditions: readonly [Column<any, S>, unknown][]): readonly [string, DBExists];
|
|
740
741
|
```
|
|
741
742
|
|
|
742
|
-
Defined in: [DBModel.ts:
|
|
743
|
+
Defined in: [DBModel.ts:1601](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L1601)
|
|
743
744
|
|
|
744
745
|
EXISTS subquery condition.
|
|
745
746
|
Creates a condition like: EXISTS (SELECT 1 FROM targetModel WHERE table.column = ...)
|
|
@@ -786,7 +787,7 @@ await User.find([
|
|
|
786
787
|
static notExists<S>(conditions: readonly [Column<any, S>, unknown][]): readonly [string, DBExists];
|
|
787
788
|
```
|
|
788
789
|
|
|
789
|
-
Defined in: [DBModel.ts:
|
|
790
|
+
Defined in: [DBModel.ts:1633](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L1633)
|
|
790
791
|
|
|
791
792
|
NOT EXISTS subquery condition.
|
|
792
793
|
Creates a condition like: NOT EXISTS (SELECT 1 FROM targetModel WHERE table.column = ...)
|
|
@@ -832,7 +833,7 @@ await User.find([
|
|
|
832
833
|
static getTableName(): string;
|
|
833
834
|
```
|
|
834
835
|
|
|
835
|
-
Defined in: [DBModel.ts:
|
|
836
|
+
Defined in: [DBModel.ts:1711](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L1711)
|
|
836
837
|
|
|
837
838
|
Get table name for SELECT queries.
|
|
838
839
|
For query-based models, returns the CTE alias (TABLE_NAME).
|
|
@@ -849,7 +850,7 @@ For query-based models, returns the CTE alias (TABLE_NAME).
|
|
|
849
850
|
static isQueryBased(): boolean;
|
|
850
851
|
```
|
|
851
852
|
|
|
852
|
-
Defined in: [DBModel.ts:
|
|
853
|
+
Defined in: [DBModel.ts:1769](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L1769)
|
|
853
854
|
|
|
854
855
|
Check if this model is query-based (uses QUERY instead of TABLE_NAME)
|
|
855
856
|
|
|
@@ -872,7 +873,7 @@ static withQuery<T>(this: T, queryConfig:
|
|
|
872
873
|
}): T;
|
|
873
874
|
```
|
|
874
875
|
|
|
875
|
-
Defined in: [DBModel.ts:
|
|
876
|
+
Defined in: [DBModel.ts:1798](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L1798)
|
|
876
877
|
|
|
877
878
|
Create a new model class bound to specific query parameters.
|
|
878
879
|
Used for parameterized query-based models.
|
|
@@ -923,7 +924,7 @@ class SalesReportModel extends DBModel {
|
|
|
923
924
|
static getUpdateTableName(): string;
|
|
924
925
|
```
|
|
925
926
|
|
|
926
|
-
Defined in: [DBModel.ts:
|
|
927
|
+
Defined in: [DBModel.ts:1848](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L1848)
|
|
927
928
|
|
|
928
929
|
Get table name for UPDATE/DELETE queries.
|
|
929
930
|
Query-based models cannot be updated/deleted directly.
|
|
@@ -940,7 +941,7 @@ Query-based models cannot be updated/deleted directly.
|
|
|
940
941
|
clearRelationCache(): void;
|
|
941
942
|
```
|
|
942
943
|
|
|
943
|
-
Defined in: [DBModel.ts:
|
|
944
|
+
Defined in: [DBModel.ts:1912](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L1912)
|
|
944
945
|
|
|
945
946
|
Clear the relation cache for this instance.
|
|
946
947
|
Also clears the context cache to force reload from DB.
|
|
@@ -957,7 +958,7 @@ Also clears the context cache to force reload from DB.
|
|
|
957
958
|
typeCastFromDB(): void;
|
|
958
959
|
```
|
|
959
960
|
|
|
960
|
-
Defined in: [DBModel.ts:
|
|
961
|
+
Defined in: [DBModel.ts:2054](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L2054)
|
|
961
962
|
|
|
962
963
|
Called after loading from DB to convert types
|
|
963
964
|
Override in derived class to implement type conversions
|
|
@@ -983,7 +984,7 @@ typeCastFromDB(): void {
|
|
|
983
984
|
getPkey(): Record<string, unknown> | null;
|
|
984
985
|
```
|
|
985
986
|
|
|
986
|
-
Defined in: [DBModel.ts:
|
|
987
|
+
Defined in: [DBModel.ts:2066](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L2066)
|
|
987
988
|
|
|
988
989
|
Get primary key as object
|
|
989
990
|
|
|
@@ -1001,7 +1002,7 @@ Object with primary key column names and values, or null if not set
|
|
|
1001
1002
|
setPkey(key: unknown): void;
|
|
1002
1003
|
```
|
|
1003
1004
|
|
|
1004
|
-
Defined in: [DBModel.ts:
|
|
1005
|
+
Defined in: [DBModel.ts:2087](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L2087)
|
|
1005
1006
|
|
|
1006
1007
|
Set primary key value
|
|
1007
1008
|
|
|
@@ -1023,7 +1024,7 @@ Set primary key value
|
|
|
1023
1024
|
getPkeyString(): string;
|
|
1024
1025
|
```
|
|
1025
1026
|
|
|
1026
|
-
Defined in: [DBModel.ts:
|
|
1027
|
+
Defined in: [DBModel.ts:2105](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L2105)
|
|
1027
1028
|
|
|
1028
1029
|
Get primary key as string (for logging, caching, etc.)
|
|
1029
1030
|
|
|
@@ -1039,7 +1040,7 @@ Get primary key as string (for logging, caching, etc.)
|
|
|
1039
1040
|
getSingleColId(): unknown;
|
|
1040
1041
|
```
|
|
1041
1042
|
|
|
1042
|
-
Defined in: [DBModel.ts:
|
|
1043
|
+
Defined in: [DBModel.ts:2117](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L2117)
|
|
1043
1044
|
|
|
1044
1045
|
Get single-column ID value
|
|
1045
1046
|
|
|
@@ -1057,7 +1058,7 @@ ID value or undefined
|
|
|
1057
1058
|
clone<T>(this: T): T;
|
|
1058
1059
|
```
|
|
1059
1060
|
|
|
1060
|
-
Defined in: [DBModel.ts:
|
|
1061
|
+
Defined in: [DBModel.ts:2132](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L2132)
|
|
1061
1062
|
|
|
1062
1063
|
Create a shallow copy of the model instance
|
|
1063
1064
|
|
|
@@ -1085,7 +1086,7 @@ Create a shallow copy of the model instance
|
|
|
1085
1086
|
assign(source: Partial<this>): this;
|
|
1086
1087
|
```
|
|
1087
1088
|
|
|
1088
|
-
Defined in: [DBModel.ts:
|
|
1089
|
+
Defined in: [DBModel.ts:2140](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L2140)
|
|
1089
1090
|
|
|
1090
1091
|
Copy properties from another object
|
|
1091
1092
|
|
|
@@ -1107,7 +1108,7 @@ Copy properties from another object
|
|
|
1107
1108
|
toObject(): Record<string, unknown>;
|
|
1108
1109
|
```
|
|
1109
1110
|
|
|
1110
|
-
Defined in: [DBModel.ts:
|
|
1111
|
+
Defined in: [DBModel.ts:2151](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L2151)
|
|
1111
1112
|
|
|
1112
1113
|
Convert to plain object
|
|
1113
1114
|
|
|
@@ -1123,7 +1124,7 @@ Convert to plain object
|
|
|
1123
1124
|
toJSON(): Record<string, unknown>;
|
|
1124
1125
|
```
|
|
1125
1126
|
|
|
1126
|
-
Defined in: [DBModel.ts:
|
|
1127
|
+
Defined in: [DBModel.ts:2164](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L2164)
|
|
1127
1128
|
|
|
1128
1129
|
Convert to JSON-serializable object
|
|
1129
1130
|
|
|
@@ -1139,7 +1140,7 @@ Convert to JSON-serializable object
|
|
|
1139
1140
|
static fromObject<T>(this: () => T, obj: Record<string, unknown>): T;
|
|
1140
1141
|
```
|
|
1141
1142
|
|
|
1142
|
-
Defined in: [DBModel.ts:
|
|
1143
|
+
Defined in: [DBModel.ts:2175](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L2175)
|
|
1143
1144
|
|
|
1144
1145
|
Create an instance from a plain object
|
|
1145
1146
|
|
|
@@ -1168,7 +1169,7 @@ Create an instance from a plain object
|
|
|
1168
1169
|
static fromObjects<T>(this: () => T, objs: Record<string, unknown>[]): T[];
|
|
1169
1170
|
```
|
|
1170
1171
|
|
|
1171
|
-
Defined in: [DBModel.ts:
|
|
1172
|
+
Defined in: [DBModel.ts:2188](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L2188)
|
|
1172
1173
|
|
|
1173
1174
|
Create multiple instances from an array of plain objects
|
|
1174
1175
|
|
|
@@ -1197,7 +1198,7 @@ Create multiple instances from an array of plain objects
|
|
|
1197
1198
|
static columnList<T>(records: T[], columnName: string): unknown[];
|
|
1198
1199
|
```
|
|
1199
1200
|
|
|
1200
|
-
Defined in: [DBModel.ts:
|
|
1201
|
+
Defined in: [DBModel.ts:2198](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L2198)
|
|
1201
1202
|
|
|
1202
1203
|
Get column values from an array of model instances
|
|
1203
1204
|
|
|
@@ -1226,7 +1227,7 @@ Get column values from an array of model instances
|
|
|
1226
1227
|
static hashByProperty<T>(records: T[], propertyKey: string): Record<string, T>;
|
|
1227
1228
|
```
|
|
1228
1229
|
|
|
1229
|
-
Defined in: [DBModel.ts:
|
|
1230
|
+
Defined in: [DBModel.ts:2208](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L2208)
|
|
1230
1231
|
|
|
1231
1232
|
Create a hash map by property value
|
|
1232
1233
|
|
|
@@ -1255,7 +1256,7 @@ Create a hash map by property value
|
|
|
1255
1256
|
static groupByProperty<T>(records: T[], propertyKey: string): Record<string, T[]>;
|
|
1256
1257
|
```
|
|
1257
1258
|
|
|
1258
|
-
Defined in: [DBModel.ts:
|
|
1259
|
+
Defined in: [DBModel.ts:2223](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L2223)
|
|
1259
1260
|
|
|
1260
1261
|
Group records by property value
|
|
1261
1262
|
|
|
@@ -1284,7 +1285,7 @@ Group records by property value
|
|
|
1284
1285
|
static idList<T>(records: T[], column?: string): unknown[];
|
|
1285
1286
|
```
|
|
1286
1287
|
|
|
1287
|
-
Defined in: [DBModel.ts:
|
|
1288
|
+
Defined in: [DBModel.ts:2241](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L2241)
|
|
1288
1289
|
|
|
1289
1290
|
Get ID list from records
|
|
1290
1291
|
|
|
@@ -1316,7 +1317,7 @@ static makeLikeString(
|
|
|
1316
1317
|
back?: boolean): string;
|
|
1317
1318
|
```
|
|
1318
1319
|
|
|
1319
|
-
Defined in: [DBModel.ts:
|
|
1320
|
+
Defined in: [DBModel.ts:2249](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L2249)
|
|
1320
1321
|
|
|
1321
1322
|
Generate LIKE pattern string
|
|
1322
1323
|
|
|
@@ -1340,7 +1341,7 @@ Generate LIKE pattern string
|
|
|
1340
1341
|
static or<T>(this: T, ...condGroups: readonly CondsOf<T>[]): OrCondOf<T>;
|
|
1341
1342
|
```
|
|
1342
1343
|
|
|
1343
|
-
Defined in: [DBModel.ts:
|
|
1344
|
+
Defined in: [DBModel.ts:2286](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L2286)
|
|
1344
1345
|
|
|
1345
1346
|
Create a type-safe OR condition for this model.
|
|
1346
1347
|
All columns in the conditions must belong to this model.
|
|
@@ -1391,7 +1392,7 @@ static find<T>(
|
|
|
1391
1392
|
options?: SelectOptions): Promise<InstanceType<T>[]>;
|
|
1392
1393
|
```
|
|
1393
1394
|
|
|
1394
|
-
Defined in: [DBModel.ts:
|
|
1395
|
+
Defined in: [DBModel.ts:2322](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L2322)
|
|
1395
1396
|
|
|
1396
1397
|
Find all records using type-safe condition tuples.
|
|
1397
1398
|
All columns in conditions must belong to this model.
|
|
@@ -1445,7 +1446,7 @@ static findOne<T>(
|
|
|
1445
1446
|
options?: SelectOptions): Promise<InstanceType<T> | null>;
|
|
1446
1447
|
```
|
|
1447
1448
|
|
|
1448
|
-
Defined in: [DBModel.ts:
|
|
1449
|
+
Defined in: [DBModel.ts:2368](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L2368)
|
|
1449
1450
|
|
|
1450
1451
|
Find first record using type-safe condition tuples.
|
|
1451
1452
|
|
|
@@ -1488,7 +1489,7 @@ static findById<T>(
|
|
|
1488
1489
|
options?: SelectOptions): Promise<InstanceType<T>[]>;
|
|
1489
1490
|
```
|
|
1490
1491
|
|
|
1491
|
-
Defined in: [DBModel.ts:
|
|
1492
|
+
Defined in: [DBModel.ts:2407](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L2407)
|
|
1492
1493
|
|
|
1493
1494
|
Find records by primary key using PkeyResult format.
|
|
1494
1495
|
Efficiently fetches multiple records by their primary keys.
|
|
@@ -1540,7 +1541,7 @@ const users = await User.findById(result);
|
|
|
1540
1541
|
static count<T>(this: T, conditions: CondsOf<T>): Promise<number>;
|
|
1541
1542
|
```
|
|
1542
1543
|
|
|
1543
|
-
Defined in: [DBModel.ts:
|
|
1544
|
+
Defined in: [DBModel.ts:2472](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L2472)
|
|
1544
1545
|
|
|
1545
1546
|
Count records using type-safe condition tuples.
|
|
1546
1547
|
|
|
@@ -1580,7 +1581,7 @@ static create<T, P>(
|
|
|
1580
1581
|
options?: InsertOptions<InstanceType<T>>): Promise<PkeyResult | null>;
|
|
1581
1582
|
```
|
|
1582
1583
|
|
|
1583
|
-
Defined in: [DBModel.ts:
|
|
1584
|
+
Defined in: [DBModel.ts:2507](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L2507)
|
|
1584
1585
|
|
|
1585
1586
|
Create a new record using type-safe column-value tuples.
|
|
1586
1587
|
Value types are validated at compile time.
|
|
@@ -1634,7 +1635,7 @@ static createMany<T>(
|
|
|
1634
1635
|
options?: InsertOptions<InstanceType<T>>): Promise<PkeyResult | null>;
|
|
1635
1636
|
```
|
|
1636
1637
|
|
|
1637
|
-
Defined in: [DBModel.ts:
|
|
1638
|
+
Defined in: [DBModel.ts:2577](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L2577)
|
|
1638
1639
|
|
|
1639
1640
|
Create multiple records using type-safe column-value tuples.
|
|
1640
1641
|
|
|
@@ -1687,7 +1688,7 @@ static update<T, V>(
|
|
|
1687
1688
|
options?: UpdateOptions): Promise<PkeyResult | null>;
|
|
1688
1689
|
```
|
|
1689
1690
|
|
|
1690
|
-
Defined in: [DBModel.ts:
|
|
1691
|
+
Defined in: [DBModel.ts:2647](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L2647)
|
|
1691
1692
|
|
|
1692
1693
|
Update records using type-safe column-value tuples.
|
|
1693
1694
|
Value types are validated at compile time.
|
|
@@ -1743,7 +1744,7 @@ static delete<T>(
|
|
|
1743
1744
|
options?: DeleteOptions): Promise<PkeyResult | null>;
|
|
1744
1745
|
```
|
|
1745
1746
|
|
|
1746
|
-
Defined in: [DBModel.ts:
|
|
1747
|
+
Defined in: [DBModel.ts:2726](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L2726)
|
|
1747
1748
|
|
|
1748
1749
|
Delete records matching conditions
|
|
1749
1750
|
|
|
@@ -1789,7 +1790,7 @@ static updateMany<T>(
|
|
|
1789
1790
|
options: UpdateManyOptions): Promise<PkeyResult | null>;
|
|
1790
1791
|
```
|
|
1791
1792
|
|
|
1792
|
-
Defined in: [DBModel.ts:
|
|
1793
|
+
Defined in: [DBModel.ts:2804](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L2804)
|
|
1793
1794
|
|
|
1794
1795
|
Update multiple records with different values per row.
|
|
1795
1796
|
Uses efficient bulk update strategies (UNNEST for PostgreSQL, VALUES for MySQL/SQLite).
|
|
@@ -1841,7 +1842,7 @@ const users = await User.findById(result);
|
|
|
1841
1842
|
static execute(sql: string, params?: unknown[]): Promise<ExecuteResult>;
|
|
1842
1843
|
```
|
|
1843
1844
|
|
|
1844
|
-
Defined in: [DBModel.ts:
|
|
1845
|
+
Defined in: [DBModel.ts:2947](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L2947)
|
|
1845
1846
|
|
|
1846
1847
|
Execute raw SQL query.
|
|
1847
1848
|
Accepts either a SQL string with params, or a `SqlFragment` from `sql` tagged template.
|
|
@@ -1884,7 +1885,7 @@ static execute(fragment:
|
|
|
1884
1885
|
| SqlCondition<unknown>): Promise<ExecuteResult>;
|
|
1885
1886
|
```
|
|
1886
1887
|
|
|
1887
|
-
Defined in: [DBModel.ts:
|
|
1888
|
+
Defined in: [DBModel.ts:2948](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L2948)
|
|
1888
1889
|
|
|
1889
1890
|
Execute raw SQL query.
|
|
1890
1891
|
Accepts either a SQL string with params, or a `SqlFragment` from `sql` tagged template.
|
|
@@ -1928,7 +1929,7 @@ static query<T>(
|
|
|
1928
1929
|
params?: unknown[]): Promise<InstanceType<T>[]>;
|
|
1929
1930
|
```
|
|
1930
1931
|
|
|
1931
|
-
Defined in: [DBModel.ts:
|
|
1932
|
+
Defined in: [DBModel.ts:3012](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L3012)
|
|
1932
1933
|
|
|
1933
1934
|
Execute raw SQL and return model instances.
|
|
1934
1935
|
The SQL should return columns matching the model's properties.
|
|
@@ -1977,7 +1978,7 @@ const posts = await Post.query(`
|
|
|
1977
1978
|
static inTransaction(): boolean;
|
|
1978
1979
|
```
|
|
1979
1980
|
|
|
1980
|
-
Defined in: [DBModel.ts:
|
|
1981
|
+
Defined in: [DBModel.ts:3044](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L3044)
|
|
1981
1982
|
|
|
1982
1983
|
Check if currently in a transaction
|
|
1983
1984
|
|
|
@@ -1993,7 +1994,7 @@ Check if currently in a transaction
|
|
|
1993
1994
|
static transaction<R>(func: () => Promise<R>, options?: TransactionOptions): Promise<R>;
|
|
1994
1995
|
```
|
|
1995
1996
|
|
|
1996
|
-
Defined in: [DBModel.ts:
|
|
1997
|
+
Defined in: [DBModel.ts:3082](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L3082)
|
|
1997
1998
|
|
|
1998
1999
|
Execute a function within a transaction
|
|
1999
2000
|
All model operations inside the callback will use the same database connection.
|
|
@@ -2052,7 +2053,7 @@ await DBModel.transaction(
|
|
|
2052
2053
|
static getCurrentConnection(): DBConnection | null;
|
|
2053
2054
|
```
|
|
2054
2055
|
|
|
2055
|
-
Defined in: [DBModel.ts:
|
|
2056
|
+
Defined in: [DBModel.ts:3227](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L3227)
|
|
2056
2057
|
|
|
2057
2058
|
Get current transaction connection
|
|
2058
2059
|
Use this to execute raw SQL queries within a transaction
|
|
@@ -2082,7 +2083,7 @@ await DBModel.transaction(async () => {
|
|
|
2082
2083
|
static getCurrentClient(): DBConnection | null;
|
|
2083
2084
|
```
|
|
2084
2085
|
|
|
2085
|
-
Defined in: [DBModel.ts:
|
|
2086
|
+
Defined in: [DBModel.ts:3235](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L3235)
|
|
2086
2087
|
|
|
2087
2088
|
#### Returns
|
|
2088
2089
|
|
|
@@ -2100,7 +2101,7 @@ Use getCurrentConnection() instead
|
|
|
2100
2101
|
static withWriter<R>(func: () => Promise<R>): Promise<R>;
|
|
2101
2102
|
```
|
|
2102
2103
|
|
|
2103
|
-
Defined in: [DBModel.ts:
|
|
2104
|
+
Defined in: [DBModel.ts:3260](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L3260)
|
|
2104
2105
|
|
|
2105
2106
|
Execute a function with explicit writer connection access.
|
|
2106
2107
|
Use this when you need to read from writer to avoid replication lag.
|
|
@@ -2146,7 +2147,7 @@ await DBModel.withWriter(async () => {
|
|
|
2146
2147
|
static createDBBase(config: DBConfig, options?: DBConfigOptions): typeof DBModel;
|
|
2147
2148
|
```
|
|
2148
2149
|
|
|
2149
|
-
Defined in: [DBModel.ts:
|
|
2150
|
+
Defined in: [DBModel.ts:3322](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L3322)
|
|
2150
2151
|
|
|
2151
2152
|
Create an independent database base class.
|
|
2152
2153
|
Use this to connect to multiple databases with isolated configurations.
|
|
@@ -2205,7 +2206,7 @@ await BaseDB.transaction(async () => {
|
|
|
2205
2206
|
reload(forUpdate?: boolean): Promise<DBModel | null>;
|
|
2206
2207
|
```
|
|
2207
2208
|
|
|
2208
|
-
Defined in: [DBModel.ts:
|
|
2209
|
+
Defined in: [DBModel.ts:3399](https://github.com/foo-ogawa/litedbmodel/blob/main/src/DBModel.ts#L3399)
|
|
2209
2210
|
|
|
2210
2211
|
Reload this instance from the database
|
|
2211
2212
|
|