litedbmodel 2.2.6 → 2.2.7

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 (116) hide show
  1. package/README.md +145 -86
  2. package/dist/Column.d.ts +17 -4
  3. package/dist/Column.d.ts.map +1 -1
  4. package/dist/Column.js.map +1 -1
  5. package/dist/DBModel.d.ts +13 -14
  6. package/dist/DBModel.d.ts.map +1 -1
  7. package/dist/DBModel.js +20 -21
  8. package/dist/DBModel.js.map +1 -1
  9. package/dist/LazyRelation.d.ts +2 -2
  10. package/dist/LazyRelation.js +2 -2
  11. package/dist/decorators.d.ts +120 -60
  12. package/dist/decorators.d.ts.map +1 -1
  13. package/dist/decorators.js +379 -248
  14. package/dist/decorators.js.map +1 -1
  15. package/dist/index.cjs +283 -217
  16. package/dist/index.d.ts +2 -2
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/scp/coltype.d.ts +14 -5
  20. package/dist/scp/coltype.d.ts.map +1 -1
  21. package/dist/scp/coltype.js +35 -36
  22. package/dist/scp/coltype.js.map +1 -1
  23. package/dist/scp/decorator-adapter.d.ts +11 -15
  24. package/dist/scp/decorator-adapter.d.ts.map +1 -1
  25. package/dist/scp/decorator-adapter.js +11 -15
  26. package/dist/scp/decorator-adapter.js.map +1 -1
  27. package/dist/scp/index.cjs +186 -193
  28. package/dist/scp/index.mjs +186 -193
  29. package/dist/scp/makesql/json-array.d.ts +6 -0
  30. package/dist/scp/makesql/json-array.d.ts.map +1 -1
  31. package/dist/scp/makesql/json-array.js +17 -2
  32. package/dist/scp/makesql/json-array.js.map +1 -1
  33. package/dist/scp/makesql/tx.d.ts.map +1 -1
  34. package/dist/scp/makesql/tx.js +1 -3
  35. package/dist/scp/makesql/tx.js.map +1 -1
  36. package/dist/scp/relation.d.ts.map +1 -1
  37. package/dist/scp/relation.js +8 -10
  38. package/dist/scp/relation.js.map +1 -1
  39. package/docs/BENCHMARK.md +3 -3
  40. package/docs/COMPARISON.md +7 -7
  41. package/docs/api/README.md +18 -18
  42. package/docs/api/classes/Conditions.md +1 -1
  43. package/docs/api/classes/DBHandler.md +1 -1
  44. package/docs/api/classes/DBModel.md +82 -82
  45. package/docs/api/classes/LimitExceededError.md +1 -1
  46. package/docs/api/classes/Middleware.md +1 -1
  47. package/docs/api/classes/SqlRaw.md +1 -1
  48. package/docs/api/classes/SqlRef.md +1 -1
  49. package/docs/api/classes/Values.md +1 -1
  50. package/docs/api/classes/WriteInReadOnlyContextError.md +1 -1
  51. package/docs/api/classes/WriteOutsideTransactionError.md +1 -1
  52. package/docs/api/functions/belongsTo.md +10 -4
  53. package/docs/api/functions/closeAllPools.md +1 -1
  54. package/docs/api/functions/condsToRecord.md +2 -2
  55. package/docs/api/functions/createMiddleware.md +1 -1
  56. package/docs/api/functions/createPostgresDriver.md +1 -1
  57. package/docs/api/functions/createSqliteDriver.md +1 -1
  58. package/docs/api/functions/dbCast.md +1 -1
  59. package/docs/api/functions/dbCastIn.md +1 -1
  60. package/docs/api/functions/dbDynamic.md +1 -1
  61. package/docs/api/functions/dbFalse.md +1 -1
  62. package/docs/api/functions/dbImmediate.md +1 -1
  63. package/docs/api/functions/dbIn.md +1 -1
  64. package/docs/api/functions/dbNotNull.md +1 -1
  65. package/docs/api/functions/dbNow.md +1 -1
  66. package/docs/api/functions/dbNull.md +1 -1
  67. package/docs/api/functions/dbRaw.md +1 -1
  68. package/docs/api/functions/dbTrue.md +1 -1
  69. package/docs/api/functions/dbUuid.md +1 -1
  70. package/docs/api/functions/dbUuidIn.md +1 -1
  71. package/docs/api/functions/formatLocalDate.md +1 -1
  72. package/docs/api/functions/formatUTCDate.md +1 -1
  73. package/docs/api/functions/getDBConfig.md +1 -1
  74. package/docs/api/functions/getDBHandler.md +1 -1
  75. package/docs/api/functions/getTransactionConnection.md +1 -1
  76. package/docs/api/functions/getTransactionContext.md +1 -1
  77. package/docs/api/functions/hasMany.md +11 -5
  78. package/docs/api/functions/hasOne.md +10 -4
  79. package/docs/api/functions/initDBHandler.md +1 -1
  80. package/docs/api/functions/isAnySqlFragment.md +1 -1
  81. package/docs/api/functions/isConnectionError.md +1 -1
  82. package/docs/api/functions/isSqlCondition.md +1 -1
  83. package/docs/api/functions/isSqlFragment.md +1 -1
  84. package/docs/api/functions/isSqlRaw.md +1 -1
  85. package/docs/api/functions/isSqlRef.md +1 -1
  86. package/docs/api/functions/isSqlTypedFragment.md +1 -1
  87. package/docs/api/functions/model.md +8 -155
  88. package/docs/api/functions/parentRef.md +1 -1
  89. package/docs/api/functions/sql.md +1 -1
  90. package/docs/api/globals.md +96 -58
  91. package/docs/api/interfaces/Column.md +1 -1
  92. package/docs/api/interfaces/ColumnDecorator.md +81 -0
  93. package/docs/api/interfaces/ColumnOptions.md +6 -10
  94. package/docs/api/interfaces/CreatedMiddlewareClass.md +1 -1
  95. package/docs/api/interfaces/DBConfig.md +1 -1
  96. package/docs/api/interfaces/DBConfigOptions.md +1 -1
  97. package/docs/api/interfaces/DeleteOptions.md +1 -1
  98. package/docs/api/interfaces/InsertOptions.md +1 -1
  99. package/docs/api/interfaces/LimitConfig.md +1 -1
  100. package/docs/api/interfaces/MiddlewareConfig.md +1 -1
  101. package/docs/api/interfaces/ModelClassDecorator.md +64 -0
  102. package/docs/api/interfaces/ModelOptions.md +1 -1
  103. package/docs/api/interfaces/PkeyResult.md +1 -1
  104. package/docs/api/interfaces/RelationDecorator.md +72 -0
  105. package/docs/api/interfaces/SelectOptions.md +1 -1
  106. package/docs/api/interfaces/SqlCondition.md +1 -1
  107. package/docs/api/interfaces/SqlFragment.md +1 -1
  108. package/docs/api/interfaces/SqlTypedFragment.md +1 -1
  109. package/docs/api/interfaces/TransactionOptions.md +1 -1
  110. package/docs/api/interfaces/UpdateManyOptions.md +1 -1
  111. package/docs/api/interfaces/UpdateOptions.md +1 -1
  112. package/docs/api-guide.md +17 -17
  113. package/docs/architecture.md +3 -3
  114. package/docs/sql-tagged-template.md +5 -5
  115. package/eslint-plugin/rules/require-declare-for-relations.js +59 -4
  116. package/package.json +8 -7
@@ -1,8 +1,8 @@
1
- [**litedbmodel v2.2.6**](README.md)
1
+ [**litedbmodel v2.2.7**](README.md)
2
2
 
3
3
  ***
4
4
 
5
- # litedbmodel v2.2.6
5
+ # litedbmodel v2.2.7
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
- ### SkipType
72
+ ### Column
73
+
74
+ #### WriteValue
75
+
76
+ ```ts
77
+ type WriteValue<V> = V | V extends string ? Date | bigint : never;
78
+ ```
79
+
80
+ Defined in: [Column.ts:769](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L769)
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
67
100
 
68
101
  ```ts
69
102
  type SkipType = typeof SKIP;
70
103
  ```
71
104
 
72
- Defined in: [Column.ts:780](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L780)
105
+ Defined in: [Column.ts:794](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L794)
73
106
 
74
107
  ***
75
108
 
76
- ### MiddlewareClass
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
- #### Methods
134
+ ##### Methods
102
135
 
103
- ##### getCurrentContext()
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
- ### SqlInterpolation
150
+ #### SqlInterpolation
118
151
 
119
152
  ```ts
120
153
  type SqlInterpolation =
@@ -155,69 +188,74 @@ Union of all types allowed as interpolated values in `sql` tagged templates.
155
188
  #### column
156
189
 
157
190
  ```ts
158
- const column: (columnNameOrOptions?: string | ColumnOptions) => PropertyDecorator & {
159
- boolean: (columnName?: string) => PropertyDecorator;
160
- number: (columnName?: string) => PropertyDecorator;
161
- bigint: (columnName?: string) => PropertyDecorator;
162
- datetime: (columnName?: string) => PropertyDecorator;
163
- date: (columnName?: string) => PropertyDecorator;
164
- stringArray: (columnName?: string) => PropertyDecorator;
165
- intArray: (columnName?: string) => PropertyDecorator;
166
- numericArray: (columnName?: string) => PropertyDecorator;
167
- booleanArray: (columnName?: string) => PropertyDecorator;
168
- datetimeArray: (columnName?: string) => PropertyDecorator;
169
- json: <T>(columnName?: string) => PropertyDecorator;
170
- uuid: (columnNameOrOptions?: string | ColumnOptions) => PropertyDecorator;
171
- custom: <T>(castFn: (value: unknown) => T, serializeFn?: SerializeFn, columnName?: string) => PropertyDecorator;
191
+ const column: (_columnNameOrOptions?: string | ColumnOptions) => never & {
192
+ text: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<string | null | undefined>;
193
+ boolean: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<boolean | null | undefined>;
194
+ number: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<number | null | undefined>;
195
+ bigint: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<bigint | null | undefined>;
196
+ datetime: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<string | null | undefined>;
197
+ date: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<string | null | undefined>;
198
+ stringArray: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<string[] | null | undefined>;
199
+ intArray: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<number[] | null | undefined>;
200
+ numericArray: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<(number | null)[] | null | undefined>;
201
+ booleanArray: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<(boolean | null)[] | null | undefined>;
202
+ datetimeArray: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<(string | null)[] | null | undefined>;
203
+ json: <T>(columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<T | null | undefined>;
204
+ uuid: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<string | null | undefined>;
205
+ passthrough: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<unknown>;
206
+ custom: <T>(castFn: (value: unknown) => T, serializeFn?: SerializeFn, columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<T | null | undefined>;
172
207
  };
173
208
  ```
174
209
 
175
- Defined in: [decorators.ts:516](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L516)
210
+ Defined in: [decorators.ts:582](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L582)
176
211
 
177
212
  Column decorator for defining model properties.
178
213
 
179
- **Auto-inference**: For simple types (boolean, number, Date, bigint),
180
- type conversion is automatically inferred from the TypeScript property type.
181
- No need to use explicit variants like `@column.boolean()`.
214
+ **A column declares its own type with a family** — the family decides both the TypeScript type the
215
+ model declares and the value `find()` gives back, on every toolchain and under either decorator
216
+ protocol. Nothing is inferred from the TypeScript type annotation.
182
217
 
183
- Auto-inferred types:
184
218
  ```typescript
185
- @column() id?: number; // Auto: Number conversion
186
- @column() name?: string; // No conversion needed
187
- @column() is_active?: boolean; // Auto: Boolean conversion
188
- @column() created_at?: Date; // Auto: DateTime conversion
189
- @column() large_id?: bigint; // Auto: BigInt conversion
190
- @column('custom_name') prop?: string; // Custom column name
219
+ @column.number({ primaryKey: true, autoIncrement: true }) id?: number;
220
+ @column.text() name?: string; // TEXT / VARCHAR / CHAR / ENUM — no cast needed
221
+ @column.text('custom_name') prop?: string; // custom column name
222
+ @column.boolean() is_active?: boolean;
223
+ @column.datetime() created_at?: string; // TZ-attached string, NOT a JS Date
224
+ @column.date() birth_date?: string; // 'YYYY-MM-DD'
225
+ @column.bigint() large_id?: bigint; // bc `int` — a JS bigint
226
+ @column.uuid() ext_id?: string;
227
+ @column.stringArray() tags?: string[];
228
+ @column.intArray() scores?: number[];
229
+ @column.json<MyType>() data?: MyType;
230
+ @column.date() birth_date?: string; // 'YYYY-MM-DD' — not a datetime
231
+ @column.passthrough() payload?: unknown; // BYTEA / BLOB — no cast exists
232
+ @column.custom((v) => String(v).toUpperCase()) status?: string;
191
233
  ```
192
234
 
193
- Explicit type conversion required (cannot be auto-inferred):
194
- ```typescript
195
- @column.stringArray() tags?: string[]; // Array element type unknown
196
- @column.intArray() scores?: number[]; // Array element type unknown
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.
235
+ Every family takes what the removed bare `@column()` took: a column name, or [ColumnOptions](interfaces/ColumnOptions.md).
236
+ The bare form inferred the type from `emitDecoratorMetadata`, which esbuild (tsx / vite / vitest)
237
+ never emits and TC39 standard decorators do not have, so it silently produced untyped reads; it now
238
+ reports the migration instead (see requireColumnFamily).
203
239
 
204
240
  ##### Type Declaration
205
241
 
206
242
  | Name | Type | Description | Defined in |
207
243
  | ------ | ------ | ------ | ------ |
208
- | `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:530](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L530) |
209
- | `number()` | (`columnName?`: `string`) => `PropertyDecorator` | Number type conversion (from string) Preserves null for nullable columns, undefined stays undefined **Example** `@column.number() amount?: number;` | [decorators.ts:547](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L547) |
210
- | `bigint()` | (`columnName?`: `string`) => `PropertyDecorator` | BigInt type conversion Preserves null for nullable columns, undefined stays undefined **Example** `@column.bigint() large_id?: bigint;` | [decorators.ts:560](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L560) |
211
- | `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:588](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L588) |
212
- | `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:618](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L618) |
213
- | `stringArray()` | (`columnName?`: `string`) => `PropertyDecorator` | String array type conversion (text[]) Preserves null for nullable columns, undefined stays undefined **Example** `@column.stringArray() tags?: string[];` | [decorators.ts:657](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L657) |
214
- | `intArray()` | (`columnName?`: `string`) => `PropertyDecorator` | Integer array type conversion (integer[]) Preserves null for nullable columns, undefined stays undefined **Example** `@column.intArray() scores?: number[];` | [decorators.ts:674](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L674) |
215
- | `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:691](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L691) |
216
- | `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:708](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L708) |
217
- | `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:725](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L725) |
218
- | `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:751](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L751) |
219
- | `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:786](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L786) |
220
- | `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:808](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L808) |
244
+ | `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:596](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L596) |
245
+ | `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:621](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L621) |
246
+ | `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:637](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L637) |
247
+ | `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:650](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L650) |
248
+ | `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:677](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L677) |
249
+ | `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:706](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L706) |
250
+ | `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:744](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L744) |
251
+ | `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:760](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L760) |
252
+ | `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:776](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L776) |
253
+ | `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:792](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L792) |
254
+ | `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:808](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L808) |
255
+ | `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:838](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L838) |
256
+ | `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:872](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L872) |
257
+ | `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:895](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L895) |
258
+ | `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:903](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L903) |
221
259
 
222
260
  ### Other
223
261
 
@@ -227,7 +265,7 @@ still work and can be used when you want to be explicit about the conversion.
227
265
  const SKIP: typeof SKIP;
228
266
  ```
229
267
 
230
- Defined in: [Column.ts:779](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L779)
268
+ Defined in: [Column.ts:793](https://github.com/foo-ogawa/litedbmodel/blob/main/src/Column.ts#L793)
231
269
 
232
270
  Sentinel value to skip a field in create/update operations.
233
271
  Use with conditional expressions to keep code as expressions instead of statements.
@@ -254,7 +292,6 @@ await User.update(conds, [
254
292
  - [hasMany](functions/hasMany.md)
255
293
  - [belongsTo](functions/belongsTo.md)
256
294
  - [hasOne](functions/hasOne.md)
257
- - [model](functions/model.md)
258
295
 
259
296
  ### Middleware
260
297
 
@@ -293,6 +330,7 @@ await User.update(conds, [
293
330
  - [formatLocalDate](functions/formatLocalDate.md)
294
331
  - [formatUTCDate](functions/formatUTCDate.md)
295
332
  - [isConnectionError](functions/isConnectionError.md)
333
+ - [model](functions/model.md)
296
334
  - [createPostgresDriver](functions/createPostgresDriver.md)
297
335
  - [createSqliteDriver](functions/createSqliteDriver.md)
298
336
 
@@ -1,4 +1,4 @@
1
- [**litedbmodel v2.2.6**](../README.md)
1
+ [**litedbmodel v2.2.7**](../README.md)
2
2
 
3
3
  ***
4
4
 
@@ -0,0 +1,81 @@
1
+ [**litedbmodel v2.2.7**](../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.6**](../README.md)
1
+ [**litedbmodel v2.2.7**](../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:348](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L348)
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:350](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L350) |
22
- | <a id="primarykey"></a> `primaryKey?` | `boolean` | Mark this column as part of the primary key | [decorators.ts:352](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L352) |
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:358](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L358) |
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) |
@@ -1,4 +1,4 @@
1
- [**litedbmodel v2.2.6**](../README.md)
1
+ [**litedbmodel v2.2.7**](../README.md)
2
2
 
3
3
  ***
4
4
 
@@ -1,4 +1,4 @@
1
- [**litedbmodel v2.2.6**](../README.md)
1
+ [**litedbmodel v2.2.7**](../README.md)
2
2
 
3
3
  ***
4
4
 
@@ -1,4 +1,4 @@
1
- [**litedbmodel v2.2.6**](../README.md)
1
+ [**litedbmodel v2.2.7**](../README.md)
2
2
 
3
3
  ***
4
4
 
@@ -1,4 +1,4 @@
1
- [**litedbmodel v2.2.6**](../README.md)
1
+ [**litedbmodel v2.2.7**](../README.md)
2
2
 
3
3
  ***
4
4
 
@@ -1,4 +1,4 @@
1
- [**litedbmodel v2.2.6**](../README.md)
1
+ [**litedbmodel v2.2.7**](../README.md)
2
2
 
3
3
  ***
4
4
 
@@ -1,4 +1,4 @@
1
- [**litedbmodel v2.2.6**](../README.md)
1
+ [**litedbmodel v2.2.7**](../README.md)
2
2
 
3
3
  ***
4
4
 
@@ -1,4 +1,4 @@
1
- [**litedbmodel v2.2.6**](../README.md)
1
+ [**litedbmodel v2.2.7**](../README.md)
2
2
 
3
3
  ***
4
4
 
@@ -0,0 +1,64 @@
1
+ [**litedbmodel v2.2.7**](../README.md)
2
+
3
+ ***
4
+
5
+ [litedbmodel](../globals.md) / ModelClassDecorator
6
+
7
+ # Interface: ModelClassDecorator()
8
+
9
+ Defined in: [decorators.ts:1125](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L1125)
10
+
11
+ A class decorator that works under both protocols.
12
+
13
+ ## Call Signature
14
+
15
+ ```ts
16
+ ModelClassDecorator<T>(constructor: T): T;
17
+ ```
18
+
19
+ Defined in: [decorators.ts:1126](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L1126)
20
+
21
+ A class decorator that works under both protocols.
22
+
23
+ ### Type Parameters
24
+
25
+ | Type Parameter |
26
+ | ------ |
27
+ | `T` *extends* (...`args`: `unknown`[]) => `object` |
28
+
29
+ ### Parameters
30
+
31
+ | Parameter | Type |
32
+ | ------ | ------ |
33
+ | `constructor` | `T` |
34
+
35
+ ### Returns
36
+
37
+ `T`
38
+
39
+ ## Call Signature
40
+
41
+ ```ts
42
+ ModelClassDecorator<T>(value: T, context: ClassDecoratorContext): T;
43
+ ```
44
+
45
+ Defined in: [decorators.ts:1127](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L1127)
46
+
47
+ A class decorator that works under both protocols.
48
+
49
+ ### Type Parameters
50
+
51
+ | Type Parameter |
52
+ | ------ |
53
+ | `T` *extends* (...`args`: `unknown`[]) => `object` |
54
+
55
+ ### Parameters
56
+
57
+ | Parameter | Type |
58
+ | ------ | ------ |
59
+ | `value` | `T` |
60
+ | `context` | `ClassDecoratorContext` |
61
+
62
+ ### Returns
63
+
64
+ `T`
@@ -1,4 +1,4 @@
1
- [**litedbmodel v2.2.6**](../README.md)
1
+ [**litedbmodel v2.2.7**](../README.md)
2
2
 
3
3
  ***
4
4
 
@@ -1,4 +1,4 @@
1
- [**litedbmodel v2.2.6**](../README.md)
1
+ [**litedbmodel v2.2.7**](../README.md)
2
2
 
3
3
  ***
4
4
 
@@ -0,0 +1,72 @@
1
+ [**litedbmodel v2.2.7**](../README.md)
2
+
3
+ ***
4
+
5
+ [litedbmodel](../globals.md) / RelationDecorator
6
+
7
+ # Interface: RelationDecorator()\<Value\>
8
+
9
+ Defined in: [decorators.ts:367](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L367)
10
+
11
+ What a relation decorator may be applied to, under either protocol.
12
+
13
+ ## Type Parameters
14
+
15
+ | Type Parameter |
16
+ | ------ |
17
+ | `Value` |
18
+
19
+ ## Call Signature
20
+
21
+ ```ts
22
+ RelationDecorator<This, Key>(target: This, propertyKey: Key): void;
23
+ ```
24
+
25
+ Defined in: [decorators.ts:368](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L368)
26
+
27
+ What a relation decorator may be applied to, under either protocol.
28
+
29
+ ### Type Parameters
30
+
31
+ | Type Parameter |
32
+ | ------ |
33
+ | `This` *extends* `Partial`\<`Record`\<`Key`, `Value`\>\> |
34
+ | `Key` *extends* `string` \| `symbol` |
35
+
36
+ ### Parameters
37
+
38
+ | Parameter | Type |
39
+ | ------ | ------ |
40
+ | `target` | `This` |
41
+ | `propertyKey` | `Key` |
42
+
43
+ ### Returns
44
+
45
+ `void`
46
+
47
+ ## Call Signature
48
+
49
+ ```ts
50
+ RelationDecorator<This>(value: undefined, context: ClassFieldDecoratorContext<This, Value>): void;
51
+ ```
52
+
53
+ Defined in: [decorators.ts:372](https://github.com/foo-ogawa/litedbmodel/blob/main/src/decorators.ts#L372)
54
+
55
+ What a relation decorator may be applied to, under either protocol.
56
+
57
+ ### Type Parameters
58
+
59
+ | Type Parameter |
60
+ | ------ |
61
+ | `This` |
62
+
63
+ ### Parameters
64
+
65
+ | Parameter | Type |
66
+ | ------ | ------ |
67
+ | `value` | `undefined` |
68
+ | `context` | `ClassFieldDecoratorContext`\<`This`, `Value`\> |
69
+
70
+ ### Returns
71
+
72
+ `void`
@@ -1,4 +1,4 @@
1
- [**litedbmodel v2.2.6**](../README.md)
1
+ [**litedbmodel v2.2.7**](../README.md)
2
2
 
3
3
  ***
4
4
 
@@ -1,4 +1,4 @@
1
- [**litedbmodel v2.2.6**](../README.md)
1
+ [**litedbmodel v2.2.7**](../README.md)
2
2
 
3
3
  ***
4
4
 
@@ -1,4 +1,4 @@
1
- [**litedbmodel v2.2.6**](../README.md)
1
+ [**litedbmodel v2.2.7**](../README.md)
2
2
 
3
3
  ***
4
4
 
@@ -1,4 +1,4 @@
1
- [**litedbmodel v2.2.6**](../README.md)
1
+ [**litedbmodel v2.2.7**](../README.md)
2
2
 
3
3
  ***
4
4
 
@@ -1,4 +1,4 @@
1
- [**litedbmodel v2.2.6**](../README.md)
1
+ [**litedbmodel v2.2.7**](../README.md)
2
2
 
3
3
  ***
4
4
 
@@ -1,4 +1,4 @@
1
- [**litedbmodel v2.2.6**](../README.md)
1
+ [**litedbmodel v2.2.7**](../README.md)
2
2
 
3
3
  ***
4
4
 
@@ -1,4 +1,4 @@
1
- [**litedbmodel v2.2.6**](../README.md)
1
+ [**litedbmodel v2.2.7**](../README.md)
2
2
 
3
3
  ***
4
4