litedbmodel 2.2.6 → 2.2.8
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 +146 -86
- package/dist/Column.d.ts +30 -6
- package/dist/Column.d.ts.map +1 -1
- package/dist/Column.js +30 -10
- package/dist/Column.js.map +1 -1
- package/dist/DBModel.d.ts +28 -16
- package/dist/DBModel.d.ts.map +1 -1
- package/dist/DBModel.js +60 -46
- package/dist/DBModel.js.map +1 -1
- package/dist/LazyRelation.d.ts +2 -2
- package/dist/LazyRelation.js +2 -2
- package/dist/TypeCast.d.ts +2 -2
- package/dist/TypeCast.d.ts.map +1 -1
- package/dist/TypeCast.js +7 -9
- package/dist/TypeCast.js.map +1 -1
- package/dist/decorators.d.ts +128 -60
- package/dist/decorators.d.ts.map +1 -1
- package/dist/decorators.js +393 -251
- package/dist/decorators.js.map +1 -1
- package/dist/drivers/MysqlHelper.d.ts +3 -3
- package/dist/drivers/MysqlHelper.d.ts.map +1 -1
- package/dist/drivers/MysqlHelper.js +3 -17
- package/dist/drivers/MysqlHelper.js.map +1 -1
- package/dist/drivers/MysqlSqlBuilder.d.ts.map +1 -1
- package/dist/drivers/MysqlSqlBuilder.js +2 -13
- package/dist/drivers/MysqlSqlBuilder.js.map +1 -1
- package/dist/drivers/PostgresHelper.d.ts +3 -2
- package/dist/drivers/PostgresHelper.d.ts.map +1 -1
- package/dist/drivers/PostgresHelper.js +3 -16
- package/dist/drivers/PostgresHelper.js.map +1 -1
- package/dist/drivers/PostgresSqlBuilder.d.ts.map +1 -1
- package/dist/drivers/PostgresSqlBuilder.js +2 -14
- package/dist/drivers/PostgresSqlBuilder.js.map +1 -1
- package/dist/drivers/SqliteHelper.d.ts +4 -2
- package/dist/drivers/SqliteHelper.d.ts.map +1 -1
- package/dist/drivers/SqliteHelper.js +4 -2
- package/dist/drivers/SqliteHelper.js.map +1 -1
- package/dist/drivers/SqliteSqlBuilder.d.ts.map +1 -1
- package/dist/drivers/SqliteSqlBuilder.js +2 -13
- package/dist/drivers/SqliteSqlBuilder.js.map +1 -1
- package/dist/index.cjs +861 -816
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/scp/coltype.d.ts +14 -5
- package/dist/scp/coltype.d.ts.map +1 -1
- package/dist/scp/coltype.js +35 -36
- package/dist/scp/coltype.js.map +1 -1
- package/dist/scp/decorator-adapter.d.ts +12 -15
- package/dist/scp/decorator-adapter.d.ts.map +1 -1
- package/dist/scp/decorator-adapter.js +13 -15
- package/dist/scp/decorator-adapter.js.map +1 -1
- package/dist/scp/index.cjs +237 -233
- package/dist/scp/index.mjs +237 -233
- package/dist/scp/makesql/json-array.d.ts +6 -0
- package/dist/scp/makesql/json-array.d.ts.map +1 -1
- package/dist/scp/makesql/json-array.js +17 -2
- package/dist/scp/makesql/json-array.js.map +1 -1
- package/dist/scp/makesql/tx.d.ts.map +1 -1
- package/dist/scp/makesql/tx.js +1 -3
- package/dist/scp/makesql/tx.js.map +1 -1
- package/dist/scp/relation.d.ts.map +1 -1
- package/dist/scp/relation.js +8 -10
- package/dist/scp/relation.js.map +1 -1
- package/docs/BENCHMARK.md +3 -3
- package/docs/COMPARISON.md +7 -7
- package/docs/api/README.md +18 -18
- package/docs/api/classes/Conditions.md +10 -10
- package/docs/api/classes/DBHandler.md +1 -1
- package/docs/api/classes/DBModel.md +84 -84
- package/docs/api/classes/LimitExceededError.md +1 -1
- package/docs/api/classes/Middleware.md +1 -1
- package/docs/api/classes/SqlRaw.md +1 -1
- package/docs/api/classes/SqlRef.md +1 -1
- 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 +10 -4
- package/docs/api/functions/closeAllPools.md +1 -1
- package/docs/api/functions/condsToRecord.md +4 -3
- package/docs/api/functions/createMiddleware.md +1 -1
- package/docs/api/functions/createPostgresDriver.md +1 -1
- 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 +2 -2
- package/docs/api/functions/formatUTCDate.md +2 -2
- 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 +11 -5
- package/docs/api/functions/hasOne.md +10 -4
- package/docs/api/functions/initDBHandler.md +1 -1
- 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 +8 -155
- package/docs/api/functions/parentRef.md +1 -1
- package/docs/api/functions/sql.md +1 -1
- package/docs/api/globals.md +99 -58
- package/docs/api/interfaces/Column.md +32 -31
- package/docs/api/interfaces/ColumnDecorator.md +81 -0
- package/docs/api/interfaces/ColumnOptions.md +6 -10
- package/docs/api/interfaces/CreatedMiddlewareClass.md +1 -1
- package/docs/api/interfaces/DBConfig.md +1 -1
- package/docs/api/interfaces/DBConfigOptions.md +1 -1
- package/docs/api/interfaces/DeleteOptions.md +1 -1
- package/docs/api/interfaces/InsertOptions.md +1 -1
- package/docs/api/interfaces/LimitConfig.md +1 -1
- package/docs/api/interfaces/MiddlewareConfig.md +1 -1
- package/docs/api/interfaces/ModelClassDecorator.md +64 -0
- package/docs/api/interfaces/ModelOptions.md +1 -1
- package/docs/api/interfaces/PkeyResult.md +1 -1
- package/docs/api/interfaces/RelationDecorator.md +72 -0
- package/docs/api/interfaces/SelectOptions.md +1 -1
- 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 +1 -1
- package/docs/api/interfaces/UpdateManyOptions.md +1 -1
- package/docs/api/interfaces/UpdateOptions.md +1 -1
- package/docs/api-guide.md +17 -17
- package/docs/architecture.md +14 -10
- package/docs/sql-tagged-template.md +5 -5
- package/eslint-plugin/rules/require-declare-for-relations.js +59 -4
- package/package.json +8 -7
package/docs/api/globals.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
[**litedbmodel v2.2.
|
|
1
|
+
[**litedbmodel v2.2.8**](README.md)
|
|
2
2
|
|
|
3
3
|
***
|
|
4
4
|
|
|
5
|
-
# litedbmodel v2.2.
|
|
5
|
+
# litedbmodel v2.2.8
|
|
6
6
|
|
|
7
7
|
litedbmodel - A lightweight TypeScript data access layer
|
|
8
8
|
|
|
@@ -37,6 +37,12 @@ Supports PostgreSQL and SQLite databases.
|
|
|
37
37
|
|
|
38
38
|
## Interfaces
|
|
39
39
|
|
|
40
|
+
### Decorators
|
|
41
|
+
|
|
42
|
+
- [ColumnDecorator](interfaces/ColumnDecorator.md)
|
|
43
|
+
- [RelationDecorator](interfaces/RelationDecorator.md)
|
|
44
|
+
- [ModelClassDecorator](interfaces/ModelClassDecorator.md)
|
|
45
|
+
|
|
40
46
|
### Types
|
|
41
47
|
|
|
42
48
|
- [PkeyResult](interfaces/PkeyResult.md)
|
|
@@ -63,17 +69,44 @@ Supports PostgreSQL and SQLite databases.
|
|
|
63
69
|
|
|
64
70
|
## Type Aliases
|
|
65
71
|
|
|
66
|
-
###
|
|
72
|
+
### Column
|
|
73
|
+
|
|
74
|
+
#### WriteValue
|
|
67
75
|
|
|
68
76
|
```ts
|
|
69
|
-
type
|
|
77
|
+
type WriteValue<V> = V | V extends string ? Date | bigint : never;
|
|
70
78
|
```
|
|
71
79
|
|
|
72
80
|
Defined in: [Column.ts:780](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L780)
|
|
73
81
|
|
|
82
|
+
What a column ACCEPTS on write, given the type it READS BACK.
|
|
83
|
+
|
|
84
|
+
A `@column.datetime()` / `.date()` / `.bigint()` column reads a string — the column's own textual
|
|
85
|
+
form, or a BIGINT's exact decimal — but the write path still takes the JS value that string stands
|
|
86
|
+
for: a `Date` goes through the driver's dialect-specific datetime serializer (MySQL wants a local
|
|
87
|
+
`YYYY-MM-DD HH:mm:ss`, PostgreSQL an ISO instant, and getting that right is the library's job, not
|
|
88
|
+
the caller's), and a `bigint` is written as its exact digits. TypeScript cannot tell those columns
|
|
89
|
+
from a plain text one — all of them read `string` — so the widening applies to every string column.
|
|
90
|
+
|
|
91
|
+
##### Type Parameters
|
|
92
|
+
|
|
93
|
+
| Type Parameter |
|
|
94
|
+
| ------ |
|
|
95
|
+
| `V` |
|
|
96
|
+
|
|
97
|
+
### Other
|
|
98
|
+
|
|
99
|
+
#### SkipType
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
type SkipType = typeof SKIP;
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Defined in: [Column.ts:805](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L805)
|
|
106
|
+
|
|
74
107
|
***
|
|
75
108
|
|
|
76
|
-
|
|
109
|
+
#### MiddlewareClass
|
|
77
110
|
|
|
78
111
|
```ts
|
|
79
112
|
type MiddlewareClass = {
|
|
@@ -98,9 +131,9 @@ the assigned own property wins over the prototype method). So the DOCUMENTED pai
|
|
|
98
131
|
(`DBModel.use(DBModel.createMiddleware(…))`, README) did not typecheck even though it is the
|
|
99
132
|
runtime-correct call, and every stateful middleware in the README was affected.
|
|
100
133
|
|
|
101
|
-
|
|
134
|
+
##### Methods
|
|
102
135
|
|
|
103
|
-
|
|
136
|
+
###### getCurrentContext()
|
|
104
137
|
|
|
105
138
|
```ts
|
|
106
139
|
getCurrentContext(): object;
|
|
@@ -114,7 +147,7 @@ Defined in: [Middleware.ts:310](https://github.com/foo-ogawa/litedbmodel/blob/ma
|
|
|
114
147
|
|
|
115
148
|
***
|
|
116
149
|
|
|
117
|
-
|
|
150
|
+
#### SqlInterpolation
|
|
118
151
|
|
|
119
152
|
```ts
|
|
120
153
|
type SqlInterpolation =
|
|
@@ -155,69 +188,77 @@ Union of all types allowed as interpolated values in `sql` tagged templates.
|
|
|
155
188
|
#### column
|
|
156
189
|
|
|
157
190
|
```ts
|
|
158
|
-
const column: (
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
191
|
+
const column: (_columnNameOrOptions?: string | ColumnOptions) => never & {
|
|
192
|
+
text: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<string | null | undefined>;
|
|
193
|
+
decimal: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<string | null | undefined>;
|
|
194
|
+
boolean: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<boolean | null | undefined>;
|
|
195
|
+
number: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<number | null | undefined>;
|
|
196
|
+
bigint: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<bigint | null | undefined>;
|
|
197
|
+
datetime: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<string | null | undefined>;
|
|
198
|
+
date: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<string | null | undefined>;
|
|
199
|
+
stringArray: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<string[] | null | undefined>;
|
|
200
|
+
intArray: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<number[] | null | undefined>;
|
|
201
|
+
numericArray: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<(number | null)[] | null | undefined>;
|
|
202
|
+
booleanArray: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<(boolean | null)[] | null | undefined>;
|
|
203
|
+
datetimeArray: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<(string | null)[] | null | undefined>;
|
|
204
|
+
json: <T>(columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<T | null | undefined>;
|
|
205
|
+
uuid: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<string | null | undefined>;
|
|
206
|
+
passthrough: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<unknown>;
|
|
207
|
+
custom: <T>(castFn: (value: unknown) => T, serializeFn?: SerializeFn, columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<T | null | undefined>;
|
|
172
208
|
};
|
|
173
209
|
```
|
|
174
210
|
|
|
175
|
-
Defined in: [decorators.ts:
|
|
211
|
+
Defined in: [decorators.ts:598](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L598)
|
|
176
212
|
|
|
177
213
|
Column decorator for defining model properties.
|
|
178
214
|
|
|
179
|
-
**
|
|
180
|
-
|
|
181
|
-
|
|
215
|
+
**A column declares its own type with a family** — the family decides both the TypeScript type the
|
|
216
|
+
model declares and the value `find()` gives back, on every toolchain and under either decorator
|
|
217
|
+
protocol. Nothing is inferred from the TypeScript type annotation.
|
|
182
218
|
|
|
183
|
-
Auto-inferred types:
|
|
184
219
|
```typescript
|
|
185
|
-
@column() id?: number;
|
|
186
|
-
@column() name?: string;
|
|
187
|
-
@column()
|
|
188
|
-
@column()
|
|
189
|
-
@column()
|
|
190
|
-
@column(
|
|
220
|
+
@column.number({ primaryKey: true, autoIncrement: true }) id?: number;
|
|
221
|
+
@column.text() name?: string; // TEXT / VARCHAR / CHAR / ENUM — no cast needed
|
|
222
|
+
@column.text('custom_name') prop?: string; // custom column name
|
|
223
|
+
@column.decimal() price?: string; // NUMERIC / DECIMAL — exact decimal string
|
|
224
|
+
@column.boolean() is_active?: boolean;
|
|
225
|
+
@column.datetime() created_at?: string; // TZ-attached string, NOT a JS Date
|
|
226
|
+
@column.date() birth_date?: string; // 'YYYY-MM-DD'
|
|
227
|
+
@column.bigint() large_id?: bigint; // bc `int` — a JS bigint
|
|
228
|
+
@column.uuid() ext_id?: string;
|
|
229
|
+
@column.stringArray() tags?: string[];
|
|
230
|
+
@column.intArray() scores?: number[];
|
|
231
|
+
@column.json<MyType>() data?: MyType;
|
|
232
|
+
@column.date() birth_date?: string; // 'YYYY-MM-DD' — not a datetime
|
|
233
|
+
@column.passthrough() payload?: unknown; // BYTEA / BLOB — no cast exists
|
|
234
|
+
@column.custom((v) => String(v).toUpperCase()) status?: string;
|
|
191
235
|
```
|
|
192
236
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
@column.json<MyType>() data?: MyType; // Generic type unknown
|
|
198
|
-
@column.date() birth_date?: string; // date vs datetime distinction
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
Note: The explicit variants (`@column.boolean()`, `@column.datetime()`, etc.)
|
|
202
|
-
still work and can be used when you want to be explicit about the conversion.
|
|
237
|
+
Every family takes what the removed bare `@column()` took: a column name, or [ColumnOptions](interfaces/ColumnOptions.md).
|
|
238
|
+
The bare form inferred the type from `emitDecoratorMetadata`, which esbuild (tsx / vite / vitest)
|
|
239
|
+
never emits and TC39 standard decorators do not have, so it silently produced untyped reads; it now
|
|
240
|
+
reports the migration instead (see requireColumnFamily).
|
|
203
241
|
|
|
204
242
|
##### Type Declaration
|
|
205
243
|
|
|
206
244
|
| Name | Type | Description | Defined in |
|
|
207
245
|
| ------ | ------ | ------ | ------ |
|
|
208
|
-
| `
|
|
209
|
-
| `
|
|
210
|
-
| `
|
|
211
|
-
| `
|
|
212
|
-
| `
|
|
213
|
-
| `
|
|
214
|
-
| `
|
|
215
|
-
| `
|
|
216
|
-
| `
|
|
217
|
-
| `
|
|
218
|
-
| `
|
|
219
|
-
| `
|
|
220
|
-
| `
|
|
246
|
+
| `text()` | (`columnNameOrOptions?`: `string` \| [`ColumnOptions`](interfaces/ColumnOptions.md)) => [`ColumnDecorator`](interfaces/ColumnDecorator.md)\<`string` \| `null` \| `undefined`\> | Text type (TEXT / VARCHAR / CHAR / ENUM / citext) — the driver value is already a string, so no cast is applied. The family still DECLARES the column so the typed read types it as `TEXT`. **Examples** `@column.text() name?: string;` `@column.text('user_name') name?: string;` | [decorators.ts:612](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L612) |
|
|
247
|
+
| `decimal()` | (`columnNameOrOptions?`: `string` \| [`ColumnOptions`](interfaces/ColumnOptions.md)) => [`ColumnDecorator`](interfaces/ColumnDecorator.md)\<`string` \| `null` \| `undefined`\> | Exact decimal type (NUMERIC / DECIMAL) — read back as its exact decimal STRING (a JS number rounds past 2^53). The family states the column is `numeric`, so a write binds the string as a numeric — a batch write (`createMany` / `updateMany`) included. **Example** `@column.decimal() price?: string;` | [decorators.ts:626](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L626) |
|
|
248
|
+
| `boolean()` | (`columnNameOrOptions?`: `string` \| [`ColumnOptions`](interfaces/ColumnOptions.md)) => [`ColumnDecorator`](interfaces/ColumnDecorator.md)\<`boolean` \| `null` \| `undefined`\> | 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:639](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L639) |
|
|
249
|
+
| `number()` | (`columnNameOrOptions?`: `string` \| [`ColumnOptions`](interfaces/ColumnOptions.md)) => [`ColumnDecorator`](interfaces/ColumnDecorator.md)\<`number` \| `null` \| `undefined`\> | Number type conversion (from string) Preserves null for nullable columns, undefined stays undefined **Example** `@column.number() amount?: number;` | [decorators.ts:655](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L655) |
|
|
250
|
+
| `bigint()` | (`columnNameOrOptions?`: `string` \| [`ColumnOptions`](interfaces/ColumnOptions.md)) => [`ColumnDecorator`](interfaces/ColumnDecorator.md)\<`bigint` \| `null` \| `undefined`\> | BigInt type conversion Preserves null for nullable columns, undefined stays undefined **Example** `@column.bigint() large_id?: bigint; // bc `int` — a JS bigint, checked i64` | [decorators.ts:668](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L668) |
|
|
251
|
+
| `datetime()` | (`columnNameOrOptions?`: `string` \| [`ColumnOptions`](interfaces/ColumnOptions.md)) => [`ColumnDecorator`](interfaces/ColumnDecorator.md)\<`string` \| `null` \| `undefined`\> | 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?: string; // TZ-attached string, NOT a JS Date` | [decorators.ts:695](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L695) |
|
|
252
|
+
| `date()` | (`columnNameOrOptions?`: `string` \| [`ColumnOptions`](interfaces/ColumnOptions.md)) => [`ColumnDecorator`](interfaces/ColumnDecorator.md)\<`string` \| `null` \| `undefined`\> | 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; // 'YYYY-MM-DD'` | [decorators.ts:724](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L724) |
|
|
253
|
+
| `stringArray()` | (`columnNameOrOptions?`: `string` \| [`ColumnOptions`](interfaces/ColumnOptions.md)) => [`ColumnDecorator`](interfaces/ColumnDecorator.md)\<`string`[] \| `null` \| `undefined`\> | String array type conversion (text[]) Preserves null for nullable columns, undefined stays undefined **Example** `@column.stringArray() tags?: string[];` | [decorators.ts:762](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L762) |
|
|
254
|
+
| `intArray()` | (`columnNameOrOptions?`: `string` \| [`ColumnOptions`](interfaces/ColumnOptions.md)) => [`ColumnDecorator`](interfaces/ColumnDecorator.md)\<`number`[] \| `null` \| `undefined`\> | Integer array type conversion (integer[]) Preserves null for nullable columns, undefined stays undefined **Example** `@column.intArray() scores?: number[];` | [decorators.ts:778](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L778) |
|
|
255
|
+
| `numericArray()` | (`columnNameOrOptions?`: `string` \| [`ColumnOptions`](interfaces/ColumnOptions.md)) => [`ColumnDecorator`](interfaces/ColumnDecorator.md)\<(`number` \| `null`)[] \| `null` \| `undefined`\> | Numeric array type conversion (numeric[], allows null elements) Preserves null for nullable columns, undefined stays undefined **Example** `@column.numericArray() values?: (number | null)[];` | [decorators.ts:794](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L794) |
|
|
256
|
+
| `booleanArray()` | (`columnNameOrOptions?`: `string` \| [`ColumnOptions`](interfaces/ColumnOptions.md)) => [`ColumnDecorator`](interfaces/ColumnDecorator.md)\<(`boolean` \| `null`)[] \| `null` \| `undefined`\> | Boolean array type conversion (boolean[]) Preserves null for nullable columns, undefined stays undefined **Example** `@column.booleanArray() flags?: (boolean | null)[];` | [decorators.ts:810](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L810) |
|
|
257
|
+
| `datetimeArray()` | (`columnNameOrOptions?`: `string` \| [`ColumnOptions`](interfaces/ColumnOptions.md)) => [`ColumnDecorator`](interfaces/ColumnDecorator.md)\<(`string` \| `null`)[] \| `null` \| `undefined`\> | DateTime array type conversion (timestamp[]) Preserves null for nullable columns, undefined stays undefined **Example** `@column.datetimeArray() event_dates?: (string | null)[];` | [decorators.ts:826](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L826) |
|
|
258
|
+
| `json()` | \<`T`\>(`columnNameOrOptions?`: `string` \| [`ColumnOptions`](interfaces/ColumnOptions.md)) => [`ColumnDecorator`](interfaces/ColumnDecorator.md)\<`T` \| `null` \| `undefined`\> | 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:856](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L856) |
|
|
259
|
+
| `uuid()` | (`columnNameOrOptions?`: `string` \| [`ColumnOptions`](interfaces/ColumnOptions.md)) => [`ColumnDecorator`](interfaces/ColumnDecorator.md)\<`string` \| `null` \| `undefined`\> | 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:890](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L890) |
|
|
260
|
+
| `passthrough()` | (`columnNameOrOptions?`: `string` \| [`ColumnOptions`](interfaces/ColumnOptions.md)) => [`ColumnDecorator`](interfaces/ColumnDecorator.md)\<`unknown`\> | The driver's value, UNCAST — for a column whose type the library has no cast for (`BYTEA` / `BLOB` arrives as a driver Buffer, a vendor type as whatever the driver decodes). It states "this column is passed through", which is a DECLARATION; the removed bare `@column()` was the absence of one, and produced this same passthrough by accident for every unresolvable type. **Example** `@column.passthrough() payload?: unknown;` | [decorators.ts:913](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L913) |
|
|
261
|
+
| `custom()` | \<`T`\>(`castFn`: (`value`: `unknown`) => `T`, `serializeFn?`: `SerializeFn`, `columnNameOrOptions?`: `string` \| [`ColumnOptions`](interfaces/ColumnOptions.md)) => [`ColumnDecorator`](interfaces/ColumnDecorator.md)\<`T` \| `null` \| `undefined`\> | 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:921](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L921) |
|
|
221
262
|
|
|
222
263
|
### Other
|
|
223
264
|
|
|
@@ -227,7 +268,7 @@ still work and can be used when you want to be explicit about the conversion.
|
|
|
227
268
|
const SKIP: typeof SKIP;
|
|
228
269
|
```
|
|
229
270
|
|
|
230
|
-
Defined in: [Column.ts:
|
|
271
|
+
Defined in: [Column.ts:804](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L804)
|
|
231
272
|
|
|
232
273
|
Sentinel value to skip a field in create/update operations.
|
|
233
274
|
Use with conditional expressions to keep code as expressions instead of statements.
|
|
@@ -254,7 +295,6 @@ await User.update(conds, [
|
|
|
254
295
|
- [hasMany](functions/hasMany.md)
|
|
255
296
|
- [belongsTo](functions/belongsTo.md)
|
|
256
297
|
- [hasOne](functions/hasOne.md)
|
|
257
|
-
- [model](functions/model.md)
|
|
258
298
|
|
|
259
299
|
### Middleware
|
|
260
300
|
|
|
@@ -293,6 +333,7 @@ await User.update(conds, [
|
|
|
293
333
|
- [formatLocalDate](functions/formatLocalDate.md)
|
|
294
334
|
- [formatUTCDate](functions/formatUTCDate.md)
|
|
295
335
|
- [isConnectionError](functions/isConnectionError.md)
|
|
336
|
+
- [model](functions/model.md)
|
|
296
337
|
- [createPostgresDriver](functions/createPostgresDriver.md)
|
|
297
338
|
- [createSqliteDriver](functions/createSqliteDriver.md)
|
|
298
339
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[**litedbmodel v2.2.
|
|
1
|
+
[**litedbmodel v2.2.8**](../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:145](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L145)
|
|
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:147](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L147)
|
|
25
25
|
|
|
26
26
|
Call to get column name as string (for computed property keys)
|
|
27
27
|
|
|
@@ -33,13 +33,14 @@ 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="
|
|
36
|
+
| <a id="columnname"></a> `columnName` | `readonly` | `string` | The database column name | [Column.ts:150](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L150) |
|
|
37
|
+
| <a id="propertyname"></a> `propertyName` | `readonly` | `string` | The property name on the model class (may differ from columnName) | [Column.ts:153](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L153) |
|
|
38
|
+
| <a id="tablename"></a> `tableName` | `readonly` | `string` | The database table name | [Column.ts:156](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L156) |
|
|
39
|
+
| <a id="modelname"></a> `modelName` | `readonly` | `string` | The model class name (for debugging and static analysis) | [Column.ts:159](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L159) |
|
|
40
|
+
| <a id="_brand"></a> `_brand` | `readonly` | `"Column"` | Brand for type discrimination - enables static analysis to distinguish from regular variables | [Column.ts:162](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L162) |
|
|
41
|
+
| <a id="sqlcast"></a> `sqlCast?` | `readonly` | `string` | SQL type for automatic casting in conditions (e.g., 'uuid') | [Column.ts:165](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L165) |
|
|
42
|
+
| <a id="serialize"></a> `serialize?` | `readonly` | (`value`: `unknown`, `typeCast?`: `DriverTypeCast`) => `unknown` | The column family's serializer: a condition value binds exactly as a written value does | [Column.ts:168](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L168) |
|
|
43
|
+
| <a id="__model"></a> `__model?` | `readonly` | `ModelType` | Phantom type for model association (compile-time only, not used at runtime) | [Column.ts:171](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L171) |
|
|
43
44
|
|
|
44
45
|
## Methods
|
|
45
46
|
|
|
@@ -49,7 +50,7 @@ Call to get column name as string (for computed property keys)
|
|
|
49
50
|
eq(value: ValueType): Record<string, ValueType | DBCast>;
|
|
50
51
|
```
|
|
51
52
|
|
|
52
|
-
Defined in: [Column.ts:
|
|
53
|
+
Defined in: [Column.ts:181](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L181)
|
|
53
54
|
|
|
54
55
|
Equal condition (column = value)
|
|
55
56
|
|
|
@@ -77,7 +78,7 @@ User.id.eq(1) → { id: 1 }
|
|
|
77
78
|
ne(value: ValueType): Record<string, ValueType | DBCast>;
|
|
78
79
|
```
|
|
79
80
|
|
|
80
|
-
Defined in: [Column.ts:
|
|
81
|
+
Defined in: [Column.ts:187](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L187)
|
|
81
82
|
|
|
82
83
|
Not equal condition (column != value)
|
|
83
84
|
|
|
@@ -105,7 +106,7 @@ User.status.ne('deleted') → { 'status != ?': 'deleted' }
|
|
|
105
106
|
gt(value: ValueType): Record<string, ValueType | DBCast>;
|
|
106
107
|
```
|
|
107
108
|
|
|
108
|
-
Defined in: [Column.ts:
|
|
109
|
+
Defined in: [Column.ts:193](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L193)
|
|
109
110
|
|
|
110
111
|
Greater than condition (column > value)
|
|
111
112
|
|
|
@@ -133,7 +134,7 @@ User.age.gt(18) → { 'age > ?': 18 }
|
|
|
133
134
|
gte(value: ValueType): Record<string, ValueType | DBCast>;
|
|
134
135
|
```
|
|
135
136
|
|
|
136
|
-
Defined in: [Column.ts:
|
|
137
|
+
Defined in: [Column.ts:199](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L199)
|
|
137
138
|
|
|
138
139
|
Greater than or equal condition (column >= value)
|
|
139
140
|
|
|
@@ -161,7 +162,7 @@ User.age.gte(18) → { 'age >= ?': 18 }
|
|
|
161
162
|
lt(value: ValueType): Record<string, ValueType | DBCast>;
|
|
162
163
|
```
|
|
163
164
|
|
|
164
|
-
Defined in: [Column.ts:
|
|
165
|
+
Defined in: [Column.ts:205](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L205)
|
|
165
166
|
|
|
166
167
|
Less than condition (column < value)
|
|
167
168
|
|
|
@@ -189,7 +190,7 @@ User.age.lt(65) → { 'age < ?': 65 }
|
|
|
189
190
|
lte(value: ValueType): Record<string, ValueType | DBCast>;
|
|
190
191
|
```
|
|
191
192
|
|
|
192
|
-
Defined in: [Column.ts:
|
|
193
|
+
Defined in: [Column.ts:211](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L211)
|
|
193
194
|
|
|
194
195
|
Less than or equal condition (column <= value)
|
|
195
196
|
|
|
@@ -217,7 +218,7 @@ User.age.lte(65) → { 'age <= ?': 65 }
|
|
|
217
218
|
like(pattern: string): Record<string, string>;
|
|
218
219
|
```
|
|
219
220
|
|
|
220
|
-
Defined in: [Column.ts:
|
|
221
|
+
Defined in: [Column.ts:217](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L217)
|
|
221
222
|
|
|
222
223
|
LIKE condition (column LIKE pattern)
|
|
223
224
|
|
|
@@ -245,7 +246,7 @@ User.name.like('%test%') → { 'name LIKE ?': '%test%' }
|
|
|
245
246
|
notLike(pattern: string): Record<string, string>;
|
|
246
247
|
```
|
|
247
248
|
|
|
248
|
-
Defined in: [Column.ts:
|
|
249
|
+
Defined in: [Column.ts:223](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L223)
|
|
249
250
|
|
|
250
251
|
NOT LIKE condition (column NOT LIKE pattern)
|
|
251
252
|
|
|
@@ -273,7 +274,7 @@ User.name.notLike('%test%') → { 'name NOT LIKE ?': '%test%' }
|
|
|
273
274
|
ilike(pattern: string): Record<string, string>;
|
|
274
275
|
```
|
|
275
276
|
|
|
276
|
-
Defined in: [Column.ts:
|
|
277
|
+
Defined in: [Column.ts:229](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L229)
|
|
277
278
|
|
|
278
279
|
ILIKE condition (case-insensitive LIKE, PostgreSQL specific)
|
|
279
280
|
|
|
@@ -301,7 +302,7 @@ User.name.ilike('%TEST%') → { 'name ILIKE ?': '%TEST%' }
|
|
|
301
302
|
between(from: ValueType, to: ValueType): Record<string, [ValueType, ValueType]>;
|
|
302
303
|
```
|
|
303
304
|
|
|
304
|
-
Defined in: [Column.ts:
|
|
305
|
+
Defined in: [Column.ts:235](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L235)
|
|
305
306
|
|
|
306
307
|
BETWEEN condition (column BETWEEN from AND to)
|
|
307
308
|
|
|
@@ -330,7 +331,7 @@ User.age.between(18, 65) → { 'age BETWEEN ? AND ?': [18, 65] }
|
|
|
330
331
|
in(values: ValueType[]): Record<string, ValueType[] | DBCastArray>;
|
|
331
332
|
```
|
|
332
333
|
|
|
333
|
-
Defined in: [Column.ts:
|
|
334
|
+
Defined in: [Column.ts:242](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L242)
|
|
334
335
|
|
|
335
336
|
IN condition (column IN (values))
|
|
336
337
|
Note: Arrays are automatically converted to IN clause by litedbmodel
|
|
@@ -359,7 +360,7 @@ User.status.in(['active', 'pending']) → { status: ['active', 'pending'] }
|
|
|
359
360
|
notIn(values: ValueType[]): Record<string, ValueType[] | DBCastArray>;
|
|
360
361
|
```
|
|
361
362
|
|
|
362
|
-
Defined in: [Column.ts:
|
|
363
|
+
Defined in: [Column.ts:248](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L248)
|
|
363
364
|
|
|
364
365
|
NOT IN condition (column NOT IN (values))
|
|
365
366
|
|
|
@@ -387,7 +388,7 @@ User.status.notIn(['deleted', 'banned'])
|
|
|
387
388
|
isNull(): Record<string, null>;
|
|
388
389
|
```
|
|
389
390
|
|
|
390
|
-
Defined in: [Column.ts:
|
|
391
|
+
Defined in: [Column.ts:254](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L254)
|
|
391
392
|
|
|
392
393
|
IS NULL condition
|
|
393
394
|
|
|
@@ -409,7 +410,7 @@ User.deleted_at.isNull() → { deleted_at: null }
|
|
|
409
410
|
isNotNull(): Record<string, DBNotNullValue>;
|
|
410
411
|
```
|
|
411
412
|
|
|
412
|
-
Defined in: [Column.ts:
|
|
413
|
+
Defined in: [Column.ts:260](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L260)
|
|
413
414
|
|
|
414
415
|
IS NOT NULL condition
|
|
415
416
|
|
|
@@ -431,7 +432,7 @@ User.email.isNotNull() → { email: DBNotNullValue }
|
|
|
431
432
|
asc(): OrderColumn<ModelType>;
|
|
432
433
|
```
|
|
433
434
|
|
|
434
|
-
Defined in: [Column.ts:
|
|
435
|
+
Defined in: [Column.ts:270](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L270)
|
|
435
436
|
|
|
436
437
|
Ascending order
|
|
437
438
|
|
|
@@ -453,7 +454,7 @@ User.created_at.asc() → OrderColumn('created_at', 'ASC')
|
|
|
453
454
|
desc(): OrderColumn<ModelType>;
|
|
454
455
|
```
|
|
455
456
|
|
|
456
|
-
Defined in: [Column.ts:
|
|
457
|
+
Defined in: [Column.ts:276](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L276)
|
|
457
458
|
|
|
458
459
|
Descending order
|
|
459
460
|
|
|
@@ -475,7 +476,7 @@ User.created_at.desc() → OrderColumn('created_at', 'DESC')
|
|
|
475
476
|
ascNullsFirst(): OrderColumn<ModelType>;
|
|
476
477
|
```
|
|
477
478
|
|
|
478
|
-
Defined in: [Column.ts:
|
|
479
|
+
Defined in: [Column.ts:282](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L282)
|
|
479
480
|
|
|
480
481
|
Ascending order with NULLS FIRST
|
|
481
482
|
|
|
@@ -497,7 +498,7 @@ User.updated_at.ascNullsFirst() → OrderColumn with NULLS FIRST
|
|
|
497
498
|
ascNullsLast(): OrderColumn<ModelType>;
|
|
498
499
|
```
|
|
499
500
|
|
|
500
|
-
Defined in: [Column.ts:
|
|
501
|
+
Defined in: [Column.ts:288](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L288)
|
|
501
502
|
|
|
502
503
|
Ascending order with NULLS LAST
|
|
503
504
|
|
|
@@ -519,7 +520,7 @@ User.updated_at.ascNullsLast() → OrderColumn with NULLS LAST
|
|
|
519
520
|
descNullsFirst(): OrderColumn<ModelType>;
|
|
520
521
|
```
|
|
521
522
|
|
|
522
|
-
Defined in: [Column.ts:
|
|
523
|
+
Defined in: [Column.ts:294](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L294)
|
|
523
524
|
|
|
524
525
|
Descending order with NULLS FIRST
|
|
525
526
|
|
|
@@ -541,7 +542,7 @@ User.updated_at.descNullsFirst() → OrderColumn with NULLS FIRST
|
|
|
541
542
|
descNullsLast(): OrderColumn<ModelType>;
|
|
542
543
|
```
|
|
543
544
|
|
|
544
|
-
Defined in: [Column.ts:
|
|
545
|
+
Defined in: [Column.ts:300](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L300)
|
|
545
546
|
|
|
546
547
|
Descending order with NULLS LAST
|
|
547
548
|
|
|
@@ -563,7 +564,7 @@ User.updated_at.descNullsLast() → OrderColumn with NULLS LAST
|
|
|
563
564
|
toString(): string;
|
|
564
565
|
```
|
|
565
566
|
|
|
566
|
-
Defined in: [Column.ts:
|
|
567
|
+
Defined in: [Column.ts:310](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L310)
|
|
567
568
|
|
|
568
569
|
Returns column name (for template literals)
|
|
569
570
|
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
[**litedbmodel v2.2.8**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[litedbmodel](../globals.md) / ColumnDecorator
|
|
6
|
+
|
|
7
|
+
# Interface: ColumnDecorator()\<Value\>
|
|
8
|
+
|
|
9
|
+
Defined in: [decorators.ts:351](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L351)
|
|
10
|
+
|
|
11
|
+
What a `@column.*` decorator may be applied to, under EITHER protocol.
|
|
12
|
+
|
|
13
|
+
Both overloads are typed: `Value` is the decorated field's declared TS type, so a family whose read
|
|
14
|
+
contract yields a `string` (`@column.datetime()`, `@column.bigint()`, …) will not compile onto a
|
|
15
|
+
field declared `Date` / `bigint`. That is the compile-time half of the fix for the "declared type ≠
|
|
16
|
+
value `find()` returns" defect (issue #286), and it holds under BOTH protocols — the legacy
|
|
17
|
+
property decorator receives the prototype, whose property types a mapped type can constrain.
|
|
18
|
+
|
|
19
|
+
## Type Parameters
|
|
20
|
+
|
|
21
|
+
| Type Parameter |
|
|
22
|
+
| ------ |
|
|
23
|
+
| `Value` |
|
|
24
|
+
|
|
25
|
+
## Call Signature
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
ColumnDecorator<This, Key>(target: This, propertyKey: Key): void;
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Defined in: [decorators.ts:358](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L358)
|
|
32
|
+
|
|
33
|
+
Legacy (`experimentalDecorators`) property decorator. The prototype it receives IS typed, so the
|
|
34
|
+
decorated property's declared type is constrained here too — `@column.datetime() x?: Date` does
|
|
35
|
+
not compile under either protocol. (It was believed legacy carried no type information; it does,
|
|
36
|
+
and the majority of models are compiled that way.)
|
|
37
|
+
|
|
38
|
+
### Type Parameters
|
|
39
|
+
|
|
40
|
+
| Type Parameter |
|
|
41
|
+
| ------ |
|
|
42
|
+
| `This` *extends* `Partial`\<`Record`\<`Key`, `Value`\>\> |
|
|
43
|
+
| `Key` *extends* `string` \| `symbol` |
|
|
44
|
+
|
|
45
|
+
### Parameters
|
|
46
|
+
|
|
47
|
+
| Parameter | Type |
|
|
48
|
+
| ------ | ------ |
|
|
49
|
+
| `target` | `This` |
|
|
50
|
+
| `propertyKey` | `Key` |
|
|
51
|
+
|
|
52
|
+
### Returns
|
|
53
|
+
|
|
54
|
+
`void`
|
|
55
|
+
|
|
56
|
+
## Call Signature
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
ColumnDecorator<This>(value: undefined, context: ClassFieldDecoratorContext<This, Value>): void;
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Defined in: [decorators.ts:363](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L363)
|
|
63
|
+
|
|
64
|
+
TC39 standard class-field decorator.
|
|
65
|
+
|
|
66
|
+
### Type Parameters
|
|
67
|
+
|
|
68
|
+
| Type Parameter |
|
|
69
|
+
| ------ |
|
|
70
|
+
| `This` |
|
|
71
|
+
|
|
72
|
+
### Parameters
|
|
73
|
+
|
|
74
|
+
| Parameter | Type |
|
|
75
|
+
| ------ | ------ |
|
|
76
|
+
| `value` | `undefined` |
|
|
77
|
+
| `context` | `ClassFieldDecoratorContext`\<`This`, `Value`\> |
|
|
78
|
+
|
|
79
|
+
### Returns
|
|
80
|
+
|
|
81
|
+
`void`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[**litedbmodel v2.2.
|
|
1
|
+
[**litedbmodel v2.2.8**](../README.md)
|
|
2
2
|
|
|
3
3
|
***
|
|
4
4
|
|
|
@@ -6,18 +6,14 @@
|
|
|
6
6
|
|
|
7
7
|
# Interface: ColumnOptions
|
|
8
8
|
|
|
9
|
-
Defined in: [decorators.ts:
|
|
9
|
+
Defined in: [decorators.ts:327](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L327)
|
|
10
10
|
|
|
11
|
-
Options that can be passed to
|
|
12
|
-
|
|
13
|
-
## Column
|
|
14
|
-
|
|
15
|
-
decorator
|
|
11
|
+
Options that can be passed to any `@column.*` decorator
|
|
16
12
|
|
|
17
13
|
## Properties
|
|
18
14
|
|
|
19
15
|
| Property | Type | Description | Defined in |
|
|
20
16
|
| ------ | ------ | ------ | ------ |
|
|
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:
|
|
23
|
-
| <a id="autoincrement"></a> `autoIncrement?` | `boolean` | The SERVER assigns this column's value (`AUTO_INCREMENT` / `SERIAL` / `IDENTITY`) — a write does not supply it. Declare it on an auto-increment primary key so a `RETURNING` write can recover the rows it wrote on a dialect that has no native `RETURNING`. See ColumnMeta.autoIncrement. | [decorators.ts:
|
|
17
|
+
| <a id="columnname"></a> `columnName?` | `string` | Custom column name (defaults to property name) | [decorators.ts:329](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L329) |
|
|
18
|
+
| <a id="primarykey"></a> `primaryKey?` | `boolean` | Mark this column as part of the primary key | [decorators.ts:331](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L331) |
|
|
19
|
+
| <a id="autoincrement"></a> `autoIncrement?` | `boolean` | The SERVER assigns this column's value (`AUTO_INCREMENT` / `SERIAL` / `IDENTITY`) — a write does not supply it. Declare it on an auto-increment primary key so a `RETURNING` write can recover the rows it wrote on a dialect that has no native `RETURNING`. See ColumnMeta.autoIncrement. | [decorators.ts:337](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L337) |
|