litedbmodel 1.0.0 → 1.1.0

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.
Files changed (92) hide show
  1. package/README.md +18 -14
  2. package/dist/DBModel.d.ts +23 -20
  3. package/dist/DBModel.d.ts.map +1 -1
  4. package/dist/DBModel.js +64 -31
  5. package/dist/DBModel.js.map +1 -1
  6. package/dist/LazyRelation.d.ts.map +1 -1
  7. package/dist/LazyRelation.js +16 -10
  8. package/dist/LazyRelation.js.map +1 -1
  9. package/dist/SqlFragment.js +1 -1
  10. package/dist/SqlFragment.js.map +1 -1
  11. package/dist/decorators.d.ts +6 -7
  12. package/dist/decorators.d.ts.map +1 -1
  13. package/dist/decorators.js +42 -23
  14. package/dist/decorators.js.map +1 -1
  15. package/dist/drivers/PostgresHelper.d.ts.map +1 -1
  16. package/dist/drivers/PostgresHelper.js +4 -0
  17. package/dist/drivers/PostgresHelper.js.map +1 -1
  18. package/dist/drivers/postgres.d.ts.map +1 -1
  19. package/dist/drivers/postgres.js +57 -10
  20. package/dist/drivers/postgres.js.map +1 -1
  21. package/dist/types.d.ts +0 -9
  22. package/dist/types.d.ts.map +1 -1
  23. package/docs/BENCHMARK.md +52 -52
  24. package/docs/COMPARISON.md +9 -7
  25. package/docs/api/README.md +61 -9
  26. package/docs/api/classes/Conditions.md +75 -8
  27. package/docs/api/classes/DBHandler.md +3 -3
  28. package/docs/api/classes/DBModel.md +260 -106
  29. package/docs/api/classes/LimitExceededError.md +1 -1
  30. package/docs/api/classes/Middleware.md +1 -1
  31. package/docs/api/classes/SqlRaw.md +53 -0
  32. package/docs/api/classes/SqlRef.md +59 -0
  33. package/docs/api/classes/Values.md +6 -6
  34. package/docs/api/classes/WriteInReadOnlyContextError.md +1 -1
  35. package/docs/api/classes/WriteOutsideTransactionError.md +1 -1
  36. package/docs/api/functions/belongsTo.md +2 -2
  37. package/docs/api/functions/closeAllPools.md +1 -1
  38. package/docs/api/functions/condsToRecord.md +23 -0
  39. package/docs/api/functions/createMiddleware.md +68 -0
  40. package/docs/api/functions/createPostgresDriver.md +2 -2
  41. package/docs/api/functions/createSqliteDriver.md +1 -1
  42. package/docs/api/functions/dbCast.md +1 -1
  43. package/docs/api/functions/dbCastIn.md +1 -1
  44. package/docs/api/functions/dbDynamic.md +1 -1
  45. package/docs/api/functions/dbFalse.md +1 -1
  46. package/docs/api/functions/dbImmediate.md +1 -1
  47. package/docs/api/functions/dbIn.md +1 -1
  48. package/docs/api/functions/dbNotNull.md +1 -1
  49. package/docs/api/functions/dbNow.md +1 -1
  50. package/docs/api/functions/dbNull.md +1 -1
  51. package/docs/api/functions/dbRaw.md +1 -1
  52. package/docs/api/functions/dbTrue.md +1 -1
  53. package/docs/api/functions/dbUuid.md +1 -1
  54. package/docs/api/functions/dbUuidIn.md +1 -1
  55. package/docs/api/functions/getDBConfig.md +1 -1
  56. package/docs/api/functions/getDBHandler.md +1 -1
  57. package/docs/api/functions/getTransactionConnection.md +2 -2
  58. package/docs/api/functions/getTransactionContext.md +2 -2
  59. package/docs/api/functions/hasMany.md +2 -2
  60. package/docs/api/functions/hasOne.md +2 -2
  61. package/docs/api/functions/initDBHandler.md +1 -1
  62. package/docs/api/functions/isAnySqlFragment.md +25 -0
  63. package/docs/api/functions/isSqlCondition.md +23 -0
  64. package/docs/api/functions/isSqlFragment.md +23 -0
  65. package/docs/api/functions/isSqlRaw.md +23 -0
  66. package/docs/api/functions/isSqlRef.md +23 -0
  67. package/docs/api/functions/isSqlTypedFragment.md +23 -0
  68. package/docs/api/functions/model.md +4 -4
  69. package/docs/api/functions/parentRef.md +1 -1
  70. package/docs/api/functions/sql.md +182 -0
  71. package/docs/api/globals.md +71 -19
  72. package/docs/api/interfaces/Column.md +31 -31
  73. package/docs/api/interfaces/ColumnOptions.md +4 -4
  74. package/docs/api/interfaces/CreatedMiddlewareClass.md +110 -0
  75. package/docs/api/interfaces/DBConfig.md +2 -2
  76. package/docs/api/interfaces/DBConfigOptions.md +1 -1
  77. package/docs/api/interfaces/DeleteOptions.md +1 -1
  78. package/docs/api/interfaces/InsertOptions.md +2 -2
  79. package/docs/api/interfaces/LimitConfig.md +1 -1
  80. package/docs/api/interfaces/MiddlewareConfig.md +40 -0
  81. package/docs/api/interfaces/ModelOptions.md +1 -1
  82. package/docs/api/interfaces/PkeyResult.md +1 -1
  83. package/docs/api/interfaces/SelectOptions.md +1 -1
  84. package/docs/api/interfaces/SqlCondition.md +27 -0
  85. package/docs/api/interfaces/SqlFragment.md +20 -0
  86. package/docs/api/interfaces/SqlTypedFragment.md +29 -0
  87. package/docs/api/interfaces/TransactionOptions.md +1 -1
  88. package/docs/api/interfaces/UpdateManyOptions.md +1 -1
  89. package/docs/api/interfaces/UpdateOptions.md +1 -1
  90. package/docs/benchmark-chart.svg +163 -163
  91. package/docs/sql-tagged-template.md +5 -5
  92. package/package.json +1 -1
@@ -0,0 +1,110 @@
1
+ [**litedbmodel v1.0.1**](../README.md)
2
+
3
+ ***
4
+
5
+ [litedbmodel](../globals.md) / CreatedMiddlewareClass
6
+
7
+ # Interface: CreatedMiddlewareClass\<S\>
8
+
9
+ Defined in: Middleware.ts:427
10
+
11
+ Type for the middleware class created by createMiddleware.
12
+ Provides typed access to state via getCurrentContext().
13
+
14
+ ## Type Parameters
15
+
16
+ | Type Parameter | Description |
17
+ | ------ | ------ |
18
+ | `S` *extends* `object` | The state object type |
19
+
20
+ ## Constructors
21
+
22
+ ### Constructor
23
+
24
+ ```ts
25
+ new CreatedMiddlewareClass(): Middleware & S;
26
+ ```
27
+
28
+ Defined in: Middleware.ts:437
29
+
30
+ Constructor
31
+
32
+ #### Returns
33
+
34
+ [`Middleware`](../classes/Middleware.md) & `S`
35
+
36
+ ## Methods
37
+
38
+ ### getCurrentContext()
39
+
40
+ ```ts
41
+ getCurrentContext(): S;
42
+ ```
43
+
44
+ Defined in: Middleware.ts:429
45
+
46
+ Get the current request's state (creates new instance if none exists)
47
+
48
+ #### Returns
49
+
50
+ `S`
51
+
52
+ ***
53
+
54
+ ### run()
55
+
56
+ ```ts
57
+ run<R>(fn: () => R): R;
58
+ ```
59
+
60
+ Defined in: Middleware.ts:431
61
+
62
+ Run a function with a fresh middleware context
63
+
64
+ #### Type Parameters
65
+
66
+ | Type Parameter |
67
+ | ------ |
68
+ | `R` |
69
+
70
+ #### Parameters
71
+
72
+ | Parameter | Type |
73
+ | ------ | ------ |
74
+ | `fn` | () => `R` |
75
+
76
+ #### Returns
77
+
78
+ `R`
79
+
80
+ ***
81
+
82
+ ### hasContext()
83
+
84
+ ```ts
85
+ hasContext(): boolean;
86
+ ```
87
+
88
+ Defined in: Middleware.ts:433
89
+
90
+ Check if a context exists for the current request
91
+
92
+ #### Returns
93
+
94
+ `boolean`
95
+
96
+ ***
97
+
98
+ ### clearContext()
99
+
100
+ ```ts
101
+ clearContext(): void;
102
+ ```
103
+
104
+ Defined in: Middleware.ts:435
105
+
106
+ Clear the current context (useful for testing)
107
+
108
+ #### Returns
109
+
110
+ `void`
@@ -1,4 +1,4 @@
1
- [**litedbmodel v0.20.1**](../README.md)
1
+ [**litedbmodel v1.0.1**](../README.md)
2
2
 
3
3
  ***
4
4
 
@@ -22,4 +22,4 @@ Database configuration
22
22
  | <a id="max"></a> `max?` | `number` | Maximum pool size | DBHandler.ts:52 |
23
23
  | <a id="timeout"></a> `timeout?` | `number` | Connection timeout in seconds | DBHandler.ts:54 |
24
24
  | <a id="querytimeout"></a> `queryTimeout?` | `number` | Query timeout in seconds | DBHandler.ts:56 |
25
- | <a id="driver"></a> `driver?` | `"postgres"` \| `"sqlite"` \| `"mysql"` | Driver type: 'postgres' (default), 'sqlite', or 'mysql' | DBHandler.ts:58 |
25
+ | <a id="driver"></a> `driver?` | `"postgres"` \| `"mysql"` \| `"sqlite"` | Driver type: 'postgres' (default), 'sqlite', or 'mysql' | DBHandler.ts:58 |
@@ -1,4 +1,4 @@
1
- [**litedbmodel v0.20.1**](../README.md)
1
+ [**litedbmodel v1.0.1**](../README.md)
2
2
 
3
3
  ***
4
4
 
@@ -1,4 +1,4 @@
1
- [**litedbmodel v0.20.1**](../README.md)
1
+ [**litedbmodel v1.0.1**](../README.md)
2
2
 
3
3
  ***
4
4
 
@@ -1,4 +1,4 @@
1
- [**litedbmodel v0.20.1**](../README.md)
1
+ [**litedbmodel v1.0.1**](../README.md)
2
2
 
3
3
  ***
4
4
 
@@ -24,5 +24,5 @@ Insert options with type-safe column references.
24
24
  | <a id="returning"></a> `returning?` | `boolean` | If true, return PkeyResult with affected primary keys. If false (default), return null for better performance. | types.ts:157 |
25
25
  | <a id="conflict"></a> ~~`conflict?`~~ | `string` | **Deprecated** Use onConflict instead | types.ts:159 |
26
26
  | <a id="onconflict"></a> `onConflict?` | \| [`Column`](Column.md)\<`unknown`, `Model`\> \| [`Column`](Column.md)\<`unknown`, `Model`\>[] | Columns for ON CONFLICT clause (unique constraint columns). Must be Column symbols from the same model for type safety. **Example** `// Single column onConflict: User.email // Multiple columns (composite unique constraint) onConflict: [UserPref.user_id, UserPref.key]` | types.ts:169 |
27
- | <a id="onconflictupdate"></a> `onConflictUpdate?` | [`Column`](Column.md)\<`unknown`, `Model`\>[] \| `"all"` | Columns to update on conflict. Can be: - 'all': Update all inserted columns - Array of Column symbols from the same model **Example** `// Update all columns onConflictUpdate: 'all' // Update specific columns onConflictUpdate: [User.name, User.updated_at]` | types.ts:181 |
27
+ | <a id="onconflictupdate"></a> `onConflictUpdate?` | `"all"` \| [`Column`](Column.md)\<`unknown`, `Model`\>[] | Columns to update on conflict. Can be: - 'all': Update all inserted columns - Array of Column symbols from the same model **Example** `// Update all columns onConflictUpdate: 'all' // Update specific columns onConflictUpdate: [User.name, User.updated_at]` | types.ts:181 |
28
28
  | <a id="onconflictignore"></a> `onConflictIgnore?` | `boolean` | If true, ignore the insert on conflict (DO NOTHING). Cannot be used with onConflictUpdate. | types.ts:186 |
@@ -1,4 +1,4 @@
1
- [**litedbmodel v0.20.1**](../README.md)
1
+ [**litedbmodel v1.0.1**](../README.md)
2
2
 
3
3
  ***
4
4
 
@@ -0,0 +1,40 @@
1
+ [**litedbmodel v1.0.1**](../README.md)
2
+
3
+ ***
4
+
5
+ [litedbmodel](../globals.md) / MiddlewareConfig
6
+
7
+ # Interface: MiddlewareConfig\<S\>
8
+
9
+ Defined in: Middleware.ts:311
10
+
11
+ Configuration object for createMiddleware.
12
+ All hook functions receive `this` bound to the state object.
13
+
14
+ Hook signature matches the Middleware class:
15
+ - Method-level hooks: `(model, next, ...args)`
16
+ - execute hook: `(next, sql, params)`
17
+
18
+ ## Type Parameters
19
+
20
+ | Type Parameter | Default type | Description |
21
+ | ------ | ------ | ------ |
22
+ | `S` *extends* `object` | `Record`\<`string`, `never`\> | Type of the state object (defaults to empty object) |
23
+
24
+ ## Properties
25
+
26
+ | Property | Type | Description | Defined in |
27
+ | ------ | ------ | ------ | ------ |
28
+ | <a id="state"></a> `state?` | `S` | Initial state for each request context. A fresh copy is created for each request via structuredClone. Access via `this` in hook functions or `getCurrentContext()`. | Middleware.ts:317 |
29
+ | <a id="init"></a> `init?` | (`this`: `S`) => `void` | Called when a new context is created | Middleware.ts:320 |
30
+ | <a id="find"></a> `find?` | \<`T`\>(`this`: `S`, `model`: `T`, `next`: `NextFind`\<`T`\>, `conditions`: `Conds`, `options?`: [`SelectOptions`](SelectOptions.md)) => `Promise`\<`InstanceType`\<`T`\>[]\> | Intercept find() | Middleware.ts:323 |
31
+ | <a id="findone"></a> `findOne?` | \<`T`\>(`this`: `S`, `model`: `T`, `next`: `NextFindOne`\<`T`\>, `conditions`: `Conds`, `options?`: [`SelectOptions`](SelectOptions.md)) => `Promise`\<`InstanceType`\<`T`\> \| `null`\> | Intercept findOne() | Middleware.ts:332 |
32
+ | <a id="findbyid"></a> `findById?` | \<`T`\>(`this`: `S`, `model`: `T`, `next`: `NextFindById`\<`T`\>, `id`: `unknown`, `options?`: [`SelectOptions`](SelectOptions.md)) => `Promise`\<`InstanceType`\<`T`\>[]\> | Intercept findById() | Middleware.ts:341 |
33
+ | <a id="count"></a> `count?` | \<`T`\>(`this`: `S`, `model`: `T`, `next`: `NextCount`, `conditions`: `Conds`) => `Promise`\<`number`\> | Intercept count() | Middleware.ts:350 |
34
+ | <a id="create"></a> `create?` | \<`T`\>(`this`: `S`, `model`: `T`, `next`: `NextCreate`, `pairs`: readonly readonly \[[`Column`](Column.md)\<`any`, `any`\>, `any`\][], `options?`: [`InsertOptions`](InsertOptions.md)\<`unknown`\>) => `Promise`\<[`PkeyResult`](PkeyResult.md) \| `null`\> | Intercept create() | Middleware.ts:358 |
35
+ | <a id="createmany"></a> `createMany?` | \<`T`\>(`this`: `S`, `model`: `T`, `next`: `NextCreateMany`, `pairsArray`: readonly readonly readonly \[[`Column`](Column.md)\<`any`, `any`\>, `any`\][][], `options?`: [`InsertOptions`](InsertOptions.md)\<`unknown`\>) => `Promise`\<[`PkeyResult`](PkeyResult.md) \| `null`\> | Intercept createMany() | Middleware.ts:367 |
36
+ | <a id="update"></a> `update?` | \<`T`\>(`this`: `S`, `model`: `T`, `next`: `NextUpdate`, `conditions`: `Conds`, `values`: readonly readonly \[[`Column`](Column.md)\<`any`, `any`\>, `any`\][], `options?`: [`UpdateOptions`](UpdateOptions.md)) => `Promise`\<[`PkeyResult`](PkeyResult.md) \| `null`\> | Intercept update() | Middleware.ts:376 |
37
+ | <a id="updatemany"></a> `updateMany?` | \<`T`\>(`this`: `S`, `model`: `T`, `next`: `NextUpdateMany`, `records`: readonly readonly readonly \[[`Column`](Column.md)\<`any`, `any`\>, `any`\][][], `options?`: [`UpdateManyOptions`](UpdateManyOptions.md)) => `Promise`\<[`PkeyResult`](PkeyResult.md) \| `null`\> | Intercept updateMany() | Middleware.ts:386 |
38
+ | <a id="delete"></a> `delete?` | \<`T`\>(`this`: `S`, `model`: `T`, `next`: `NextDelete`, `conditions`: `Conds`, `options?`: [`DeleteOptions`](DeleteOptions.md)) => `Promise`\<[`PkeyResult`](PkeyResult.md) \| `null`\> | Intercept delete() | Middleware.ts:395 |
39
+ | <a id="execute"></a> `execute?` | (`this`: `S`, `next`: `NextExecute`, `sql`: `string`, `params?`: `unknown`[]) => `Promise`\<`ExecuteResult`\> | Intercept execute() - lowest level, catches ALL SQL queries | Middleware.ts:404 |
40
+ | <a id="query"></a> `query?` | \<`T`\>(`this`: `S`, `model`: `T`, `next`: `NextQuery`\<`T`\>, `sql`: `string`, `params?`: `unknown`[]) => `Promise`\<`InstanceType`\<`T`\>[]\> | Intercept query() - catches raw SQL that returns model instances | Middleware.ts:412 |
@@ -1,4 +1,4 @@
1
- [**litedbmodel v0.20.1**](../README.md)
1
+ [**litedbmodel v1.0.1**](../README.md)
2
2
 
3
3
  ***
4
4
 
@@ -1,4 +1,4 @@
1
- [**litedbmodel v0.20.1**](../README.md)
1
+ [**litedbmodel v1.0.1**](../README.md)
2
2
 
3
3
  ***
4
4
 
@@ -1,4 +1,4 @@
1
- [**litedbmodel v0.20.1**](../README.md)
1
+ [**litedbmodel v1.0.1**](../README.md)
2
2
 
3
3
  ***
4
4
 
@@ -0,0 +1,27 @@
1
+ [**litedbmodel v1.0.1**](../README.md)
2
+
3
+ ***
4
+
5
+ [litedbmodel](../globals.md) / SqlCondition
6
+
7
+ # Interface: SqlCondition\<M\>
8
+
9
+ Defined in: SqlFragment.ts:48
10
+
11
+ A SQL condition with embedded parameter values.
12
+ Used for Pattern B (value-embedded) conditions and value-free conditions (IS NULL).
13
+
14
+ ## Type Parameters
15
+
16
+ | Type Parameter | Default type | Description |
17
+ | ------ | ------ | ------ |
18
+ | `M` | `unknown` | The model type the Column belongs to |
19
+
20
+ ## Properties
21
+
22
+ | Property | Modifier | Type | Defined in |
23
+ | ------ | ------ | ------ | ------ |
24
+ | <a id="_tag"></a> `_tag` | `readonly` | `"SqlCondition"` | SqlFragment.ts:49 |
25
+ | <a id="sql"></a> `sql` | `readonly` | `string` | SqlFragment.ts:50 |
26
+ | <a id="params"></a> `params` | `readonly` | readonly `unknown`[] | SqlFragment.ts:51 |
27
+ | <a id="__modeltype"></a> `__modelType?` | `readonly` | `M` | SqlFragment.ts:52 |
@@ -0,0 +1,20 @@
1
+ [**litedbmodel v1.0.1**](../README.md)
2
+
3
+ ***
4
+
5
+ [litedbmodel](../globals.md) / SqlFragment
6
+
7
+ # Interface: SqlFragment
8
+
9
+ Defined in: SqlFragment.ts:21
10
+
11
+ A general SQL fragment with parameterized values.
12
+ Used for withQuery, QUERY, and execute.
13
+
14
+ ## Properties
15
+
16
+ | Property | Modifier | Type | Defined in |
17
+ | ------ | ------ | ------ | ------ |
18
+ | <a id="_tag"></a> `_tag` | `readonly` | `"SqlFragment"` | SqlFragment.ts:22 |
19
+ | <a id="sql"></a> `sql` | `readonly` | `string` | SqlFragment.ts:23 |
20
+ | <a id="params"></a> `params` | `readonly` | readonly `unknown`[] | SqlFragment.ts:24 |
@@ -0,0 +1,29 @@
1
+ [**litedbmodel v1.0.1**](../README.md)
2
+
3
+ ***
4
+
5
+ [litedbmodel](../globals.md) / SqlTypedFragment
6
+
7
+ # Interface: SqlTypedFragment\<V, M\>
8
+
9
+ Defined in: SqlFragment.ts:34
10
+
11
+ A typed SQL fragment that preserves the Column's value type.
12
+ Used as the first element of a condition tuple (Pattern A).
13
+
14
+ ## Type Parameters
15
+
16
+ | Type Parameter | Default type | Description |
17
+ | ------ | ------ | ------ |
18
+ | `V` | `unknown` | The value type of the referenced Column |
19
+ | `M` | `unknown` | The model type the Column belongs to |
20
+
21
+ ## Properties
22
+
23
+ | Property | Modifier | Type | Defined in |
24
+ | ------ | ------ | ------ | ------ |
25
+ | <a id="_tag"></a> `_tag` | `readonly` | `"SqlTypedFragment"` | SqlFragment.ts:35 |
26
+ | <a id="sql"></a> `sql` | `readonly` | `string` | SqlFragment.ts:36 |
27
+ | <a id="params"></a> `params` | `readonly` | readonly `unknown`[] | SqlFragment.ts:37 |
28
+ | <a id="__valuetype"></a> `__valueType?` | `readonly` | `V` | SqlFragment.ts:38 |
29
+ | <a id="__modeltype"></a> `__modelType?` | `readonly` | `M` | SqlFragment.ts:39 |
@@ -1,4 +1,4 @@
1
- [**litedbmodel v0.20.1**](../README.md)
1
+ [**litedbmodel v1.0.1**](../README.md)
2
2
 
3
3
  ***
4
4
 
@@ -1,4 +1,4 @@
1
- [**litedbmodel v0.20.1**](../README.md)
1
+ [**litedbmodel v1.0.1**](../README.md)
2
2
 
3
3
  ***
4
4
 
@@ -1,4 +1,4 @@
1
- [**litedbmodel v0.20.1**](../README.md)
1
+ [**litedbmodel v1.0.1**](../README.md)
2
2
 
3
3
  ***
4
4