litedbmodel 1.0.1 → 1.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/README.md +35 -13
- package/dist/DBModel.d.ts +18 -18
- package/dist/DBModel.d.ts.map +1 -1
- package/dist/DBModel.js +9 -9
- package/dist/DBModel.js.map +1 -1
- package/dist/LazyRelation.js +7 -7
- package/dist/LazyRelation.js.map +1 -1
- package/dist/SqlFragment.js +1 -1
- package/dist/SqlFragment.js.map +1 -1
- package/dist/TypeCast.d.ts +4 -0
- package/dist/TypeCast.d.ts.map +1 -1
- package/dist/TypeCast.js +16 -0
- package/dist/TypeCast.js.map +1 -1
- package/dist/decorators.d.ts +6 -7
- package/dist/decorators.d.ts.map +1 -1
- package/dist/decorators.js +21 -15
- package/dist/decorators.js.map +1 -1
- package/dist/drivers/PostgresSqlBuilder.d.ts.map +1 -1
- package/dist/drivers/PostgresSqlBuilder.js +2 -4
- package/dist/drivers/PostgresSqlBuilder.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +0 -9
- package/dist/types.d.ts.map +1 -1
- package/docs/COMPARISON.md +4 -2
- package/docs/api/README.md +61 -9
- package/docs/api/classes/Conditions.md +75 -8
- package/docs/api/classes/DBHandler.md +3 -3
- package/docs/api/classes/DBModel.md +260 -106
- package/docs/api/classes/LimitExceededError.md +1 -1
- package/docs/api/classes/Middleware.md +1 -1
- package/docs/api/classes/SqlRaw.md +53 -0
- package/docs/api/classes/SqlRef.md +59 -0
- package/docs/api/classes/Values.md +6 -6
- package/docs/api/classes/WriteInReadOnlyContextError.md +1 -1
- package/docs/api/classes/WriteOutsideTransactionError.md +1 -1
- package/docs/api/functions/belongsTo.md +2 -2
- package/docs/api/functions/closeAllPools.md +1 -1
- package/docs/api/functions/condsToRecord.md +23 -0
- package/docs/api/functions/createMiddleware.md +68 -0
- 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/getDBConfig.md +1 -1
- package/docs/api/functions/getDBHandler.md +1 -1
- package/docs/api/functions/getTransactionConnection.md +2 -2
- package/docs/api/functions/getTransactionContext.md +2 -2
- package/docs/api/functions/hasMany.md +2 -2
- package/docs/api/functions/hasOne.md +2 -2
- package/docs/api/functions/initDBHandler.md +1 -1
- package/docs/api/functions/isAnySqlFragment.md +25 -0
- package/docs/api/functions/isSqlCondition.md +23 -0
- package/docs/api/functions/isSqlFragment.md +23 -0
- package/docs/api/functions/isSqlRaw.md +23 -0
- package/docs/api/functions/isSqlRef.md +23 -0
- package/docs/api/functions/isSqlTypedFragment.md +23 -0
- package/docs/api/functions/model.md +4 -4
- package/docs/api/functions/parentRef.md +1 -1
- package/docs/api/functions/sql.md +182 -0
- package/docs/api/globals.md +71 -19
- package/docs/api/interfaces/Column.md +31 -31
- package/docs/api/interfaces/ColumnOptions.md +4 -4
- package/docs/api/interfaces/CreatedMiddlewareClass.md +110 -0
- package/docs/api/interfaces/DBConfig.md +2 -2
- package/docs/api/interfaces/DBConfigOptions.md +1 -1
- package/docs/api/interfaces/DeleteOptions.md +1 -1
- package/docs/api/interfaces/InsertOptions.md +2 -2
- package/docs/api/interfaces/LimitConfig.md +1 -1
- package/docs/api/interfaces/MiddlewareConfig.md +40 -0
- package/docs/api/interfaces/ModelOptions.md +1 -1
- package/docs/api/interfaces/PkeyResult.md +1 -1
- package/docs/api/interfaces/SelectOptions.md +1 -1
- package/docs/api/interfaces/SqlCondition.md +27 -0
- package/docs/api/interfaces/SqlFragment.md +20 -0
- package/docs/api/interfaces/SqlTypedFragment.md +29 -0
- package/docs/api/interfaces/TransactionOptions.md +1 -1
- package/docs/api/interfaces/UpdateManyOptions.md +1 -1
- package/docs/api/interfaces/UpdateOptions.md +1 -1
- package/docs/sql-tagged-template.md +5 -5
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[**litedbmodel
|
|
1
|
+
[**litedbmodel v1.0.1**](../README.md)
|
|
2
2
|
|
|
3
3
|
***
|
|
4
4
|
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
function model<T>(constructor: T): T;
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
Defined in: decorators.ts:
|
|
15
|
+
Defined in: decorators.ts:927
|
|
16
16
|
|
|
17
17
|
Model class decorator.
|
|
18
18
|
|
|
@@ -85,7 +85,7 @@ const posts = await user.posts; // Batch loads with other users in context
|
|
|
85
85
|
function model(tableName: string): <T>(constructor: T) => T;
|
|
86
86
|
```
|
|
87
87
|
|
|
88
|
-
Defined in: decorators.ts:
|
|
88
|
+
Defined in: decorators.ts:931
|
|
89
89
|
|
|
90
90
|
Model class decorator.
|
|
91
91
|
|
|
@@ -170,7 +170,7 @@ const posts = await user.posts; // Batch loads with other users in context
|
|
|
170
170
|
function model(tableName: string, options: ModelOptions): <T>(constructor: T) => T;
|
|
171
171
|
```
|
|
172
172
|
|
|
173
|
-
Defined in: decorators.ts:
|
|
173
|
+
Defined in: decorators.ts:935
|
|
174
174
|
|
|
175
175
|
Model class decorator.
|
|
176
176
|
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
[**litedbmodel v1.0.1**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[litedbmodel](../globals.md) / sql
|
|
6
|
+
|
|
7
|
+
# Function: sql()
|
|
8
|
+
|
|
9
|
+
## Call Signature
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
function sql<V, M>(strings: TemplateStringsArray, col: Column<V, M>): SqlTypedFragment<V, M>;
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Defined in: SqlFragment.ts:234
|
|
16
|
+
|
|
17
|
+
Single Column interpolation → SqlTypedFragment (for Pattern A tuples or IS NULL conditions).
|
|
18
|
+
|
|
19
|
+
### Type Parameters
|
|
20
|
+
|
|
21
|
+
| Type Parameter |
|
|
22
|
+
| ------ |
|
|
23
|
+
| `V` |
|
|
24
|
+
| `M` |
|
|
25
|
+
|
|
26
|
+
### Parameters
|
|
27
|
+
|
|
28
|
+
| Parameter | Type |
|
|
29
|
+
| ------ | ------ |
|
|
30
|
+
| `strings` | `TemplateStringsArray` |
|
|
31
|
+
| `col` | [`Column`](../interfaces/Column.md)\<`V`, `M`\> |
|
|
32
|
+
|
|
33
|
+
### Returns
|
|
34
|
+
|
|
35
|
+
[`SqlTypedFragment`](../interfaces/SqlTypedFragment.md)\<`V`, `M`\>
|
|
36
|
+
|
|
37
|
+
## Call Signature
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
function sql<V, M>(
|
|
41
|
+
strings: TemplateStringsArray,
|
|
42
|
+
col: Column<V, M>,
|
|
43
|
+
value: V): SqlCondition<M>;
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Defined in: SqlFragment.ts:242
|
|
47
|
+
|
|
48
|
+
Single Column + 1 value → SqlCondition (Pattern B: `sql\`${Col} > ${value}\``).
|
|
49
|
+
|
|
50
|
+
### Type Parameters
|
|
51
|
+
|
|
52
|
+
| Type Parameter |
|
|
53
|
+
| ------ |
|
|
54
|
+
| `V` |
|
|
55
|
+
| `M` |
|
|
56
|
+
|
|
57
|
+
### Parameters
|
|
58
|
+
|
|
59
|
+
| Parameter | Type |
|
|
60
|
+
| ------ | ------ |
|
|
61
|
+
| `strings` | `TemplateStringsArray` |
|
|
62
|
+
| `col` | [`Column`](../interfaces/Column.md)\<`V`, `M`\> |
|
|
63
|
+
| `value` | `V` |
|
|
64
|
+
|
|
65
|
+
### Returns
|
|
66
|
+
|
|
67
|
+
[`SqlCondition`](../interfaces/SqlCondition.md)\<`M`\>
|
|
68
|
+
|
|
69
|
+
## Call Signature
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
function sql<V, M>(
|
|
73
|
+
strings: TemplateStringsArray,
|
|
74
|
+
col: Column<V, M>,
|
|
75
|
+
v1: V,
|
|
76
|
+
v2: V): SqlCondition<M>;
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Defined in: SqlFragment.ts:251
|
|
80
|
+
|
|
81
|
+
Single Column + 2 values → SqlCondition (Pattern B: BETWEEN).
|
|
82
|
+
|
|
83
|
+
### Type Parameters
|
|
84
|
+
|
|
85
|
+
| Type Parameter |
|
|
86
|
+
| ------ |
|
|
87
|
+
| `V` |
|
|
88
|
+
| `M` |
|
|
89
|
+
|
|
90
|
+
### Parameters
|
|
91
|
+
|
|
92
|
+
| Parameter | Type |
|
|
93
|
+
| ------ | ------ |
|
|
94
|
+
| `strings` | `TemplateStringsArray` |
|
|
95
|
+
| `col` | [`Column`](../interfaces/Column.md)\<`V`, `M`\> |
|
|
96
|
+
| `v1` | `V` |
|
|
97
|
+
| `v2` | `V` |
|
|
98
|
+
|
|
99
|
+
### Returns
|
|
100
|
+
|
|
101
|
+
[`SqlCondition`](../interfaces/SqlCondition.md)\<`M`\>
|
|
102
|
+
|
|
103
|
+
## Call Signature
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
function sql<V, M>(
|
|
107
|
+
strings: TemplateStringsArray,
|
|
108
|
+
col: Column<V, M>,
|
|
109
|
+
values: readonly V[]): SqlCondition<M>;
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Defined in: SqlFragment.ts:261
|
|
113
|
+
|
|
114
|
+
Single Column + array → SqlCondition (Pattern B: IN).
|
|
115
|
+
|
|
116
|
+
### Type Parameters
|
|
117
|
+
|
|
118
|
+
| Type Parameter |
|
|
119
|
+
| ------ |
|
|
120
|
+
| `V` |
|
|
121
|
+
| `M` |
|
|
122
|
+
|
|
123
|
+
### Parameters
|
|
124
|
+
|
|
125
|
+
| Parameter | Type |
|
|
126
|
+
| ------ | ------ |
|
|
127
|
+
| `strings` | `TemplateStringsArray` |
|
|
128
|
+
| `col` | [`Column`](../interfaces/Column.md)\<`V`, `M`\> |
|
|
129
|
+
| `values` | readonly `V`[] |
|
|
130
|
+
|
|
131
|
+
### Returns
|
|
132
|
+
|
|
133
|
+
[`SqlCondition`](../interfaces/SqlCondition.md)\<`M`\>
|
|
134
|
+
|
|
135
|
+
## Call Signature
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
function sql(strings: TemplateStringsArray, ...values: (
|
|
139
|
+
| DBParentRef
|
|
140
|
+
| SqlRaw
|
|
141
|
+
| SqlRef
|
|
142
|
+
| Column<any, any>
|
|
143
|
+
| {
|
|
144
|
+
TABLE_NAME: string;
|
|
145
|
+
})[]): SqlFragment;
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Defined in: SqlFragment.ts:270
|
|
149
|
+
|
|
150
|
+
Multiple Columns / TABLE_NAME only → SqlFragment (for QUERY).
|
|
151
|
+
|
|
152
|
+
### Parameters
|
|
153
|
+
|
|
154
|
+
| Parameter | Type |
|
|
155
|
+
| ------ | ------ |
|
|
156
|
+
| `strings` | `TemplateStringsArray` |
|
|
157
|
+
| ...`values` | ( \| `DBParentRef` \| [`SqlRaw`](../classes/SqlRaw.md) \| [`SqlRef`](../classes/SqlRef.md) \| [`Column`](../interfaces/Column.md)\<`any`, `any`\> \| \{ `TABLE_NAME`: `string`; \})[] |
|
|
158
|
+
|
|
159
|
+
### Returns
|
|
160
|
+
|
|
161
|
+
[`SqlFragment`](../interfaces/SqlFragment.md)
|
|
162
|
+
|
|
163
|
+
## Call Signature
|
|
164
|
+
|
|
165
|
+
```ts
|
|
166
|
+
function sql(strings: TemplateStringsArray, ...values: SqlInterpolation[]): SqlFragment;
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Defined in: SqlFragment.ts:278
|
|
170
|
+
|
|
171
|
+
General: mixed interpolation → SqlFragment (for withQuery / execute).
|
|
172
|
+
|
|
173
|
+
### Parameters
|
|
174
|
+
|
|
175
|
+
| Parameter | Type |
|
|
176
|
+
| ------ | ------ |
|
|
177
|
+
| `strings` | `TemplateStringsArray` |
|
|
178
|
+
| ...`values` | [`SqlInterpolation`](../globals.md#sqlinterpolation)[] |
|
|
179
|
+
|
|
180
|
+
### Returns
|
|
181
|
+
|
|
182
|
+
[`SqlFragment`](../interfaces/SqlFragment.md)
|
package/docs/api/globals.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
[**litedbmodel
|
|
1
|
+
[**litedbmodel v1.0.1**](README.md)
|
|
2
2
|
|
|
3
3
|
***
|
|
4
4
|
|
|
5
|
-
# litedbmodel
|
|
5
|
+
# litedbmodel v1.0.1
|
|
6
6
|
|
|
7
7
|
litedbmodel - A lightweight TypeScript data access layer
|
|
8
8
|
|
|
@@ -32,6 +32,8 @@ Supports PostgreSQL and SQLite databases.
|
|
|
32
32
|
### Other
|
|
33
33
|
|
|
34
34
|
- [DBHandler](classes/DBHandler.md)
|
|
35
|
+
- [SqlRaw](classes/SqlRaw.md)
|
|
36
|
+
- [SqlRef](classes/SqlRef.md)
|
|
35
37
|
|
|
36
38
|
## Interfaces
|
|
37
39
|
|
|
@@ -46,6 +48,11 @@ Supports PostgreSQL and SQLite databases.
|
|
|
46
48
|
|
|
47
49
|
- [Column](interfaces/Column.md)
|
|
48
50
|
- [DBConfig](interfaces/DBConfig.md)
|
|
51
|
+
- [MiddlewareConfig](interfaces/MiddlewareConfig.md)
|
|
52
|
+
- [CreatedMiddlewareClass](interfaces/CreatedMiddlewareClass.md)
|
|
53
|
+
- [SqlFragment](interfaces/SqlFragment.md)
|
|
54
|
+
- [SqlTypedFragment](interfaces/SqlTypedFragment.md)
|
|
55
|
+
- [SqlCondition](interfaces/SqlCondition.md)
|
|
49
56
|
- [ColumnOptions](interfaces/ColumnOptions.md)
|
|
50
57
|
- [SelectOptions](interfaces/SelectOptions.md)
|
|
51
58
|
- [InsertOptions](interfaces/InsertOptions.md)
|
|
@@ -62,7 +69,7 @@ Supports PostgreSQL and SQLite databases.
|
|
|
62
69
|
type SkipType = typeof SKIP;
|
|
63
70
|
```
|
|
64
71
|
|
|
65
|
-
Defined in: Column.ts:
|
|
72
|
+
Defined in: Column.ts:780
|
|
66
73
|
|
|
67
74
|
***
|
|
68
75
|
|
|
@@ -76,6 +83,39 @@ Defined in: Middleware.ts:295
|
|
|
76
83
|
|
|
77
84
|
Type for middleware class (not instance)
|
|
78
85
|
|
|
86
|
+
***
|
|
87
|
+
|
|
88
|
+
### SqlInterpolation
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
type SqlInterpolation =
|
|
92
|
+
| Column<any, any>
|
|
93
|
+
| SqlRaw
|
|
94
|
+
| SqlRef
|
|
95
|
+
| DBParentRef
|
|
96
|
+
| SqlFragment
|
|
97
|
+
| SqlCondition<any>
|
|
98
|
+
| SqlTypedFragment<any, any>
|
|
99
|
+
| number
|
|
100
|
+
| string
|
|
101
|
+
| boolean
|
|
102
|
+
| Date
|
|
103
|
+
| bigint
|
|
104
|
+
| null
|
|
105
|
+
| undefined
|
|
106
|
+
| readonly number[]
|
|
107
|
+
| readonly string[]
|
|
108
|
+
| readonly boolean[]
|
|
109
|
+
| readonly Date[]
|
|
110
|
+
| {
|
|
111
|
+
TABLE_NAME: string;
|
|
112
|
+
};
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Defined in: SqlFragment.ts:93
|
|
116
|
+
|
|
117
|
+
Union of all types allowed as interpolated values in `sql` tagged templates.
|
|
118
|
+
|
|
79
119
|
## Variables
|
|
80
120
|
|
|
81
121
|
### Decorators
|
|
@@ -100,7 +140,7 @@ const column: (columnNameOrOptions?: string | ColumnOptions) => PropertyDecorato
|
|
|
100
140
|
};
|
|
101
141
|
```
|
|
102
142
|
|
|
103
|
-
Defined in: decorators.ts:
|
|
143
|
+
Defined in: decorators.ts:427
|
|
104
144
|
|
|
105
145
|
Column decorator for defining model properties.
|
|
106
146
|
|
|
@@ -123,7 +163,7 @@ Explicit type conversion required (cannot be auto-inferred):
|
|
|
123
163
|
@column.stringArray() tags?: string[]; // Array element type unknown
|
|
124
164
|
@column.intArray() scores?: number[]; // Array element type unknown
|
|
125
165
|
@column.json<MyType>() data?: MyType; // Generic type unknown
|
|
126
|
-
@column.date() birth_date?:
|
|
166
|
+
@column.date() birth_date?: string; // date vs datetime distinction
|
|
127
167
|
```
|
|
128
168
|
|
|
129
169
|
Note: The explicit variants (`@column.boolean()`, `@column.datetime()`, etc.)
|
|
@@ -133,19 +173,19 @@ still work and can be used when you want to be explicit about the conversion.
|
|
|
133
173
|
|
|
134
174
|
| Name | Type | Description | Defined in |
|
|
135
175
|
| ------ | ------ | ------ | ------ |
|
|
136
|
-
| `boolean()` | (`columnName?`: `string`) => `PropertyDecorator` | Boolean type conversion Converts 't'/'f', 'true'/'false', 1/0 to boolean Preserves null for nullable columns, undefined stays undefined **Example** `@column.boolean() is_active?: boolean;` | decorators.ts:
|
|
137
|
-
| `number()` | (`columnName?`: `string`) => `PropertyDecorator` | Number type conversion (from string) Preserves null for nullable columns, undefined stays undefined **Example** `@column.number() amount?: number;` | decorators.ts:
|
|
138
|
-
| `bigint()` | (`columnName?`: `string`) => `PropertyDecorator` | BigInt type conversion Preserves null for nullable columns, undefined stays undefined **Example** `@column.bigint() large_id?: bigint;` | decorators.ts:
|
|
139
|
-
| `datetime()` | (`columnName?`: `string`) => `PropertyDecorator` | DateTime type conversion (timestamp, timestamptz) Preserves null for nullable columns, undefined stays undefined **Example** `@column.datetime() created_at?: Date;` | decorators.ts:
|
|
140
|
-
| `date()` | (`columnName?`: `string`) => `PropertyDecorator` | Date type conversion
|
|
141
|
-
| `stringArray()` | (`columnName?`: `string`) => `PropertyDecorator` | String array type conversion (text[]) Preserves null for nullable columns, undefined stays undefined **Example** `@column.stringArray() tags?: string[];` | decorators.ts:
|
|
142
|
-
| `intArray()` | (`columnName?`: `string`) => `PropertyDecorator` | Integer array type conversion (integer[]) Preserves null for nullable columns, undefined stays undefined **Example** `@column.intArray() scores?: number[];` | decorators.ts:
|
|
143
|
-
| `numericArray()` | (`columnName?`: `string`) => `PropertyDecorator` | Numeric array type conversion (numeric[], allows null elements) Preserves null for nullable columns, undefined stays undefined **Example** `@column.numericArray() values?: (number | null)[];` | decorators.ts:
|
|
144
|
-
| `booleanArray()` | (`columnName?`: `string`) => `PropertyDecorator` | Boolean array type conversion (boolean[]) Preserves null for nullable columns, undefined stays undefined **Example** `@column.booleanArray() flags?: (boolean | null)[];` | decorators.ts:
|
|
145
|
-
| `datetimeArray()` | (`columnName?`: `string`) => `PropertyDecorator` | DateTime array type conversion (timestamp[]) Preserves null for nullable columns, undefined stays undefined **Example** `@column.datetimeArray() event_dates?: (Date | null)[];` | decorators.ts:
|
|
146
|
-
| `json()` | \<`T`\>(`columnName?`: `string`) => `PropertyDecorator` | JSON/JSONB type conversion Preserves null for nullable columns, undefined stays undefined **Examples** `@column.json() metadata?: Record<string, unknown>;` `@column.json<UserSettings>() settings?: UserSettings;` | decorators.ts:
|
|
147
|
-
| `uuid()` | (`columnNameOrOptions?`: `string` \| [`ColumnOptions`](interfaces/ColumnOptions.md)) => `PropertyDecorator` | UUID type with automatic casting for PostgreSQL. Automatically adds ::uuid cast to conditions and INSERT/UPDATE values. Preserves null for nullable columns, undefined stays undefined. **Example** `@column.uuid() id?: string; @column.uuid({ primaryKey: true }) id?: string; // Conditions automatically cast to UUID: await User.find([[User.id, 'uuid-string']]); // → WHERE id = ?::uuid // IN clauses also cast: await User.find([[User.id, ['uuid1', 'uuid2']]]); // → WHERE id IN (?::uuid, ?::uuid)` | decorators.ts:
|
|
148
|
-
| `custom()` | \<`T`\>(`castFn`: (`value`: `unknown`) => `T`, `serializeFn?`: `SerializeFn`, `columnName?`: `string`) => `PropertyDecorator` | Custom type conversion with user-provided function **Examples** `@column.custom((v) => String(v).toUpperCase()) status?: string;` `@column.custom((v) => v, (v) => JSON.stringify(v)) data?: MyType; // with serializer` | decorators.ts:
|
|
176
|
+
| `boolean()` | (`columnName?`: `string`) => `PropertyDecorator` | Boolean type conversion Converts 't'/'f', 'true'/'false', 1/0 to boolean Preserves null for nullable columns, undefined stays undefined **Example** `@column.boolean() is_active?: boolean;` | decorators.ts:441 |
|
|
177
|
+
| `number()` | (`columnName?`: `string`) => `PropertyDecorator` | Number type conversion (from string) Preserves null for nullable columns, undefined stays undefined **Example** `@column.number() amount?: number;` | decorators.ts:457 |
|
|
178
|
+
| `bigint()` | (`columnName?`: `string`) => `PropertyDecorator` | BigInt type conversion Preserves null for nullable columns, undefined stays undefined **Example** `@column.bigint() large_id?: bigint;` | decorators.ts:470 |
|
|
179
|
+
| `datetime()` | (`columnName?`: `string`) => `PropertyDecorator` | DateTime type conversion (timestamp, timestamptz) Preserves null for nullable columns, undefined stays undefined Timezone handling: - PostgreSQL: Serializes to ISO 8601 UTC string with 'Z' suffix for explicit timezone - MySQL/SQLite: Passes Date object to driver (driver-dependent timezone handling) **Example** `@column.datetime() created_at?: Date;` | decorators.ts:500 |
|
|
180
|
+
| `date()` | (`columnName?`: `string`) => `PropertyDecorator` | Date type conversion — returns YYYY-MM-DD string. Preserves null for nullable columns, undefined stays undefined. DB values (Date object or string) are normalized to 'YYYY-MM-DD' string. On write, string values are passed through; Date objects are formatted as 'YYYY-MM-DD'. **Example** `@column.date() birth_date?: string;` | decorators.ts:527 |
|
|
181
|
+
| `stringArray()` | (`columnName?`: `string`) => `PropertyDecorator` | String array type conversion (text[]) Preserves null for nullable columns, undefined stays undefined **Example** `@column.stringArray() tags?: string[];` | decorators.ts:578 |
|
|
182
|
+
| `intArray()` | (`columnName?`: `string`) => `PropertyDecorator` | Integer array type conversion (integer[]) Preserves null for nullable columns, undefined stays undefined **Example** `@column.intArray() scores?: number[];` | decorators.ts:595 |
|
|
183
|
+
| `numericArray()` | (`columnName?`: `string`) => `PropertyDecorator` | Numeric array type conversion (numeric[], allows null elements) Preserves null for nullable columns, undefined stays undefined **Example** `@column.numericArray() values?: (number | null)[];` | decorators.ts:612 |
|
|
184
|
+
| `booleanArray()` | (`columnName?`: `string`) => `PropertyDecorator` | Boolean array type conversion (boolean[]) Preserves null for nullable columns, undefined stays undefined **Example** `@column.booleanArray() flags?: (boolean | null)[];` | decorators.ts:629 |
|
|
185
|
+
| `datetimeArray()` | (`columnName?`: `string`) => `PropertyDecorator` | DateTime array type conversion (timestamp[]) Preserves null for nullable columns, undefined stays undefined **Example** `@column.datetimeArray() event_dates?: (Date | null)[];` | decorators.ts:646 |
|
|
186
|
+
| `json()` | \<`T`\>(`columnName?`: `string`) => `PropertyDecorator` | JSON/JSONB type conversion Preserves null for nullable columns, undefined stays undefined **Examples** `@column.json() metadata?: Record<string, unknown>;` `@column.json<UserSettings>() settings?: UserSettings;` | decorators.ts:672 |
|
|
187
|
+
| `uuid()` | (`columnNameOrOptions?`: `string` \| [`ColumnOptions`](interfaces/ColumnOptions.md)) => `PropertyDecorator` | UUID type with automatic casting for PostgreSQL. Automatically adds ::uuid cast to conditions and INSERT/UPDATE values. Preserves null for nullable columns, undefined stays undefined. **Example** `@column.uuid() id?: string; @column.uuid({ primaryKey: true }) id?: string; // Conditions automatically cast to UUID: await User.find([[User.id, 'uuid-string']]); // → WHERE id = ?::uuid // IN clauses also cast: await User.find([[User.id, ['uuid1', 'uuid2']]]); // → WHERE id IN (?::uuid, ?::uuid)` | decorators.ts:707 |
|
|
188
|
+
| `custom()` | \<`T`\>(`castFn`: (`value`: `unknown`) => `T`, `serializeFn?`: `SerializeFn`, `columnName?`: `string`) => `PropertyDecorator` | Custom type conversion with user-provided function **Examples** `@column.custom((v) => String(v).toUpperCase()) status?: string;` `@column.custom((v) => v, (v) => JSON.stringify(v)) data?: MyType; // with serializer` | decorators.ts:729 |
|
|
149
189
|
|
|
150
190
|
### Other
|
|
151
191
|
|
|
@@ -155,7 +195,7 @@ still work and can be used when you want to be explicit about the conversion.
|
|
|
155
195
|
const SKIP: typeof SKIP;
|
|
156
196
|
```
|
|
157
197
|
|
|
158
|
-
Defined in: Column.ts:
|
|
198
|
+
Defined in: Column.ts:779
|
|
159
199
|
|
|
160
200
|
Sentinel value to skip a field in create/update operations.
|
|
161
201
|
Use with conditional expressions to keep code as expressions instead of statements.
|
|
@@ -184,8 +224,13 @@ await User.update(conds, [
|
|
|
184
224
|
- [hasOne](functions/hasOne.md)
|
|
185
225
|
- [model](functions/model.md)
|
|
186
226
|
|
|
227
|
+
### Middleware
|
|
228
|
+
|
|
229
|
+
- [createMiddleware](functions/createMiddleware.md)
|
|
230
|
+
|
|
187
231
|
### Other
|
|
188
232
|
|
|
233
|
+
- [condsToRecord](functions/condsToRecord.md)
|
|
189
234
|
- [initDBHandler](functions/initDBHandler.md)
|
|
190
235
|
- [getDBHandler](functions/getDBHandler.md)
|
|
191
236
|
- [getDBConfig](functions/getDBConfig.md)
|
|
@@ -206,6 +251,13 @@ await User.update(conds, [
|
|
|
206
251
|
- [dbCastIn](functions/dbCastIn.md)
|
|
207
252
|
- [dbUuidIn](functions/dbUuidIn.md)
|
|
208
253
|
- [parentRef](functions/parentRef.md)
|
|
254
|
+
- [isSqlFragment](functions/isSqlFragment.md)
|
|
255
|
+
- [isSqlTypedFragment](functions/isSqlTypedFragment.md)
|
|
256
|
+
- [isSqlCondition](functions/isSqlCondition.md)
|
|
257
|
+
- [isAnySqlFragment](functions/isAnySqlFragment.md)
|
|
258
|
+
- [isSqlRaw](functions/isSqlRaw.md)
|
|
259
|
+
- [isSqlRef](functions/isSqlRef.md)
|
|
260
|
+
- [sql](functions/sql.md)
|
|
209
261
|
- [createPostgresDriver](functions/createPostgresDriver.md)
|
|
210
262
|
- [createSqliteDriver](functions/createSqliteDriver.md)
|
|
211
263
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[**litedbmodel
|
|
1
|
+
[**litedbmodel v1.0.1**](../README.md)
|
|
2
2
|
|
|
3
3
|
***
|
|
4
4
|
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
# Interface: Column()\<ValueType, ModelType\>
|
|
8
8
|
|
|
9
|
-
Defined in: Column.ts:
|
|
9
|
+
Defined in: Column.ts:144
|
|
10
10
|
|
|
11
11
|
Type-safe column reference as a callable function.
|
|
12
12
|
|
|
@@ -21,7 +21,7 @@ Type-safe column reference as a callable function.
|
|
|
21
21
|
Column(): string;
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
Defined in: Column.ts:
|
|
24
|
+
Defined in: Column.ts:146
|
|
25
25
|
|
|
26
26
|
Call to get column name as string (for computed property keys)
|
|
27
27
|
|
|
@@ -33,13 +33,13 @@ Call to get column name as string (for computed property keys)
|
|
|
33
33
|
|
|
34
34
|
| Property | Modifier | Type | Description | Defined in |
|
|
35
35
|
| ------ | ------ | ------ | ------ | ------ |
|
|
36
|
-
| <a id="columnname"></a> `columnName` | `readonly` | `string` | The database column name | Column.ts:
|
|
37
|
-
| <a id="propertyname"></a> `propertyName` | `readonly` | `string` | The property name on the model class (may differ from columnName) | Column.ts:
|
|
38
|
-
| <a id="tablename"></a> `tableName` | `readonly` | `string` | The database table name | Column.ts:
|
|
39
|
-
| <a id="modelname"></a> `modelName` | `readonly` | `string` | The model class name (for debugging and static analysis) | Column.ts:
|
|
40
|
-
| <a id="_brand"></a> `_brand` | `readonly` | `"Column"` | Brand for type discrimination - enables static analysis to distinguish from regular variables | Column.ts:
|
|
41
|
-
| <a id="sqlcast"></a> `sqlCast?` | `readonly` | `string` | SQL type for automatic casting in conditions (e.g., 'uuid') | Column.ts:
|
|
42
|
-
| <a id="__model"></a> `__model?` | `readonly` | `ModelType` | Phantom type for model association (compile-time only, not used at runtime) | Column.ts:
|
|
36
|
+
| <a id="columnname"></a> `columnName` | `readonly` | `string` | The database column name | Column.ts:149 |
|
|
37
|
+
| <a id="propertyname"></a> `propertyName` | `readonly` | `string` | The property name on the model class (may differ from columnName) | Column.ts:152 |
|
|
38
|
+
| <a id="tablename"></a> `tableName` | `readonly` | `string` | The database table name | Column.ts:155 |
|
|
39
|
+
| <a id="modelname"></a> `modelName` | `readonly` | `string` | The model class name (for debugging and static analysis) | Column.ts:158 |
|
|
40
|
+
| <a id="_brand"></a> `_brand` | `readonly` | `"Column"` | Brand for type discrimination - enables static analysis to distinguish from regular variables | Column.ts:161 |
|
|
41
|
+
| <a id="sqlcast"></a> `sqlCast?` | `readonly` | `string` | SQL type for automatic casting in conditions (e.g., 'uuid') | Column.ts:164 |
|
|
42
|
+
| <a id="__model"></a> `__model?` | `readonly` | `ModelType` | Phantom type for model association (compile-time only, not used at runtime) | Column.ts:167 |
|
|
43
43
|
|
|
44
44
|
## Methods
|
|
45
45
|
|
|
@@ -49,7 +49,7 @@ Call to get column name as string (for computed property keys)
|
|
|
49
49
|
eq(value: ValueType): Record<string, ValueType | DBCast>;
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
Defined in: Column.ts:
|
|
52
|
+
Defined in: Column.ts:177
|
|
53
53
|
|
|
54
54
|
Equal condition (column = value)
|
|
55
55
|
|
|
@@ -77,7 +77,7 @@ User.id.eq(1) → { id: 1 }
|
|
|
77
77
|
ne(value: ValueType): Record<string, ValueType | DBCast>;
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
-
Defined in: Column.ts:
|
|
80
|
+
Defined in: Column.ts:183
|
|
81
81
|
|
|
82
82
|
Not equal condition (column != value)
|
|
83
83
|
|
|
@@ -105,7 +105,7 @@ User.status.ne('deleted') → { 'status != ?': 'deleted' }
|
|
|
105
105
|
gt(value: ValueType): Record<string, ValueType | DBCast>;
|
|
106
106
|
```
|
|
107
107
|
|
|
108
|
-
Defined in: Column.ts:
|
|
108
|
+
Defined in: Column.ts:189
|
|
109
109
|
|
|
110
110
|
Greater than condition (column > value)
|
|
111
111
|
|
|
@@ -133,7 +133,7 @@ User.age.gt(18) → { 'age > ?': 18 }
|
|
|
133
133
|
gte(value: ValueType): Record<string, ValueType | DBCast>;
|
|
134
134
|
```
|
|
135
135
|
|
|
136
|
-
Defined in: Column.ts:
|
|
136
|
+
Defined in: Column.ts:195
|
|
137
137
|
|
|
138
138
|
Greater than or equal condition (column >= value)
|
|
139
139
|
|
|
@@ -161,7 +161,7 @@ User.age.gte(18) → { 'age >= ?': 18 }
|
|
|
161
161
|
lt(value: ValueType): Record<string, ValueType | DBCast>;
|
|
162
162
|
```
|
|
163
163
|
|
|
164
|
-
Defined in: Column.ts:
|
|
164
|
+
Defined in: Column.ts:201
|
|
165
165
|
|
|
166
166
|
Less than condition (column < value)
|
|
167
167
|
|
|
@@ -189,7 +189,7 @@ User.age.lt(65) → { 'age < ?': 65 }
|
|
|
189
189
|
lte(value: ValueType): Record<string, ValueType | DBCast>;
|
|
190
190
|
```
|
|
191
191
|
|
|
192
|
-
Defined in: Column.ts:
|
|
192
|
+
Defined in: Column.ts:207
|
|
193
193
|
|
|
194
194
|
Less than or equal condition (column <= value)
|
|
195
195
|
|
|
@@ -217,7 +217,7 @@ User.age.lte(65) → { 'age <= ?': 65 }
|
|
|
217
217
|
like(pattern: string): Record<string, string>;
|
|
218
218
|
```
|
|
219
219
|
|
|
220
|
-
Defined in: Column.ts:
|
|
220
|
+
Defined in: Column.ts:213
|
|
221
221
|
|
|
222
222
|
LIKE condition (column LIKE pattern)
|
|
223
223
|
|
|
@@ -245,7 +245,7 @@ User.name.like('%test%') → { 'name LIKE ?': '%test%' }
|
|
|
245
245
|
notLike(pattern: string): Record<string, string>;
|
|
246
246
|
```
|
|
247
247
|
|
|
248
|
-
Defined in: Column.ts:
|
|
248
|
+
Defined in: Column.ts:219
|
|
249
249
|
|
|
250
250
|
NOT LIKE condition (column NOT LIKE pattern)
|
|
251
251
|
|
|
@@ -273,7 +273,7 @@ User.name.notLike('%test%') → { 'name NOT LIKE ?': '%test%' }
|
|
|
273
273
|
ilike(pattern: string): Record<string, string>;
|
|
274
274
|
```
|
|
275
275
|
|
|
276
|
-
Defined in: Column.ts:
|
|
276
|
+
Defined in: Column.ts:225
|
|
277
277
|
|
|
278
278
|
ILIKE condition (case-insensitive LIKE, PostgreSQL specific)
|
|
279
279
|
|
|
@@ -301,7 +301,7 @@ User.name.ilike('%TEST%') → { 'name ILIKE ?': '%TEST%' }
|
|
|
301
301
|
between(from: ValueType, to: ValueType): Record<string, [ValueType, ValueType]>;
|
|
302
302
|
```
|
|
303
303
|
|
|
304
|
-
Defined in: Column.ts:
|
|
304
|
+
Defined in: Column.ts:231
|
|
305
305
|
|
|
306
306
|
BETWEEN condition (column BETWEEN from AND to)
|
|
307
307
|
|
|
@@ -330,7 +330,7 @@ User.age.between(18, 65) → { 'age BETWEEN ? AND ?': [18, 65] }
|
|
|
330
330
|
in(values: ValueType[]): Record<string, ValueType[] | DBCastArray>;
|
|
331
331
|
```
|
|
332
332
|
|
|
333
|
-
Defined in: Column.ts:
|
|
333
|
+
Defined in: Column.ts:238
|
|
334
334
|
|
|
335
335
|
IN condition (column IN (values))
|
|
336
336
|
Note: Arrays are automatically converted to IN clause by litedbmodel
|
|
@@ -359,7 +359,7 @@ User.status.in(['active', 'pending']) → { status: ['active', 'pending'] }
|
|
|
359
359
|
notIn(values: ValueType[]): Record<string, ValueType[] | DBCastArray>;
|
|
360
360
|
```
|
|
361
361
|
|
|
362
|
-
Defined in: Column.ts:
|
|
362
|
+
Defined in: Column.ts:244
|
|
363
363
|
|
|
364
364
|
NOT IN condition (column NOT IN (values))
|
|
365
365
|
|
|
@@ -387,7 +387,7 @@ User.status.notIn(['deleted', 'banned'])
|
|
|
387
387
|
isNull(): Record<string, null>;
|
|
388
388
|
```
|
|
389
389
|
|
|
390
|
-
Defined in: Column.ts:
|
|
390
|
+
Defined in: Column.ts:250
|
|
391
391
|
|
|
392
392
|
IS NULL condition
|
|
393
393
|
|
|
@@ -409,7 +409,7 @@ User.deleted_at.isNull() → { deleted_at: null }
|
|
|
409
409
|
isNotNull(): Record<string, DBNotNullValue>;
|
|
410
410
|
```
|
|
411
411
|
|
|
412
|
-
Defined in: Column.ts:
|
|
412
|
+
Defined in: Column.ts:256
|
|
413
413
|
|
|
414
414
|
IS NOT NULL condition
|
|
415
415
|
|
|
@@ -431,7 +431,7 @@ User.email.isNotNull() → { email: DBNotNullValue }
|
|
|
431
431
|
asc(): OrderColumn<ModelType>;
|
|
432
432
|
```
|
|
433
433
|
|
|
434
|
-
Defined in: Column.ts:
|
|
434
|
+
Defined in: Column.ts:266
|
|
435
435
|
|
|
436
436
|
Ascending order
|
|
437
437
|
|
|
@@ -453,7 +453,7 @@ User.created_at.asc() → OrderColumn('created_at', 'ASC')
|
|
|
453
453
|
desc(): OrderColumn<ModelType>;
|
|
454
454
|
```
|
|
455
455
|
|
|
456
|
-
Defined in: Column.ts:
|
|
456
|
+
Defined in: Column.ts:272
|
|
457
457
|
|
|
458
458
|
Descending order
|
|
459
459
|
|
|
@@ -475,7 +475,7 @@ User.created_at.desc() → OrderColumn('created_at', 'DESC')
|
|
|
475
475
|
ascNullsFirst(): OrderColumn<ModelType>;
|
|
476
476
|
```
|
|
477
477
|
|
|
478
|
-
Defined in: Column.ts:
|
|
478
|
+
Defined in: Column.ts:278
|
|
479
479
|
|
|
480
480
|
Ascending order with NULLS FIRST
|
|
481
481
|
|
|
@@ -497,7 +497,7 @@ User.updated_at.ascNullsFirst() → OrderColumn with NULLS FIRST
|
|
|
497
497
|
ascNullsLast(): OrderColumn<ModelType>;
|
|
498
498
|
```
|
|
499
499
|
|
|
500
|
-
Defined in: Column.ts:
|
|
500
|
+
Defined in: Column.ts:284
|
|
501
501
|
|
|
502
502
|
Ascending order with NULLS LAST
|
|
503
503
|
|
|
@@ -519,7 +519,7 @@ User.updated_at.ascNullsLast() → OrderColumn with NULLS LAST
|
|
|
519
519
|
descNullsFirst(): OrderColumn<ModelType>;
|
|
520
520
|
```
|
|
521
521
|
|
|
522
|
-
Defined in: Column.ts:
|
|
522
|
+
Defined in: Column.ts:290
|
|
523
523
|
|
|
524
524
|
Descending order with NULLS FIRST
|
|
525
525
|
|
|
@@ -541,7 +541,7 @@ User.updated_at.descNullsFirst() → OrderColumn with NULLS FIRST
|
|
|
541
541
|
descNullsLast(): OrderColumn<ModelType>;
|
|
542
542
|
```
|
|
543
543
|
|
|
544
|
-
Defined in: Column.ts:
|
|
544
|
+
Defined in: Column.ts:296
|
|
545
545
|
|
|
546
546
|
Descending order with NULLS LAST
|
|
547
547
|
|
|
@@ -563,7 +563,7 @@ User.updated_at.descNullsLast() → OrderColumn with NULLS LAST
|
|
|
563
563
|
toString(): string;
|
|
564
564
|
```
|
|
565
565
|
|
|
566
|
-
Defined in: Column.ts:
|
|
566
|
+
Defined in: Column.ts:306
|
|
567
567
|
|
|
568
568
|
Returns column name (for template literals)
|
|
569
569
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[**litedbmodel
|
|
1
|
+
[**litedbmodel v1.0.1**](../README.md)
|
|
2
2
|
|
|
3
3
|
***
|
|
4
4
|
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
# Interface: ColumnOptions
|
|
8
8
|
|
|
9
|
-
Defined in: decorators.ts:
|
|
9
|
+
Defined in: decorators.ts:268
|
|
10
10
|
|
|
11
11
|
Options that can be passed to
|
|
12
12
|
|
|
@@ -18,5 +18,5 @@ decorator
|
|
|
18
18
|
|
|
19
19
|
| Property | Type | Description | Defined in |
|
|
20
20
|
| ------ | ------ | ------ | ------ |
|
|
21
|
-
| <a id="columnname"></a> `columnName?` | `string` | Custom column name (defaults to property name) | decorators.ts:
|
|
22
|
-
| <a id="primarykey"></a> `primaryKey?` | `boolean` | Mark this column as part of the primary key | decorators.ts:
|
|
21
|
+
| <a id="columnname"></a> `columnName?` | `string` | Custom column name (defaults to property name) | decorators.ts:270 |
|
|
22
|
+
| <a id="primarykey"></a> `primaryKey?` | `boolean` | Mark this column as part of the primary key | decorators.ts:272 |
|