@dockstat/sqlite-wrapper 1.2.4 → 1.2.5
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/index.ts +1 -2
- package/package.json +1 -1
- package/types.ts +10 -5
package/index.ts
CHANGED
|
@@ -209,8 +209,7 @@ class DB {
|
|
|
209
209
|
*/
|
|
210
210
|
createTable<_T extends Record<string, unknown>>(
|
|
211
211
|
tableName: string,
|
|
212
|
-
columns: string | Record<string, string> | TableSchema,
|
|
213
|
-
options?: TableOptions
|
|
212
|
+
columns: string | Record<string, string> | Partial<Record<Extract<keyof _T, string>, ColumnDefinition>> | TableSchema, options?: TableOptions<_T>,
|
|
214
213
|
): QueryBuilder<_T> {
|
|
215
214
|
const temp = options?.temporary ? 'TEMPORARY ' : ''
|
|
216
215
|
const ifNot = options?.ifNotExists ? 'IF NOT EXISTS ' : ''
|
package/package.json
CHANGED
package/types.ts
CHANGED
|
@@ -223,6 +223,9 @@ export interface ColumnDefinition extends ColumnConstraints {
|
|
|
223
223
|
*/
|
|
224
224
|
export type TableSchema = Record<string, ColumnDefinition>;
|
|
225
225
|
|
|
226
|
+
|
|
227
|
+
export type TypedTableSchema<T extends string = string> = Record<T, ColumnDefinition>;
|
|
228
|
+
|
|
226
229
|
/**
|
|
227
230
|
* Table constraint types
|
|
228
231
|
*/
|
|
@@ -248,7 +251,7 @@ export interface TableConstraints {
|
|
|
248
251
|
/**
|
|
249
252
|
* Enhanced table options
|
|
250
253
|
*/
|
|
251
|
-
export interface TableOptions {
|
|
254
|
+
export interface TableOptions<T> {
|
|
252
255
|
/** Add IF NOT EXISTS clause */
|
|
253
256
|
ifNotExists?: boolean;
|
|
254
257
|
/** Create WITHOUT ROWID table */
|
|
@@ -259,6 +262,8 @@ export interface TableOptions {
|
|
|
259
262
|
temporary?: boolean;
|
|
260
263
|
/** Table comment */
|
|
261
264
|
comment?: string;
|
|
265
|
+
/** JSON config for table creation and returned query builder */
|
|
266
|
+
jsonConfig?: Array<keyof T>;
|
|
262
267
|
}
|
|
263
268
|
|
|
264
269
|
/**
|
|
@@ -372,10 +377,10 @@ export const column = {
|
|
|
372
377
|
* Create a JSON column (stored as TEXT)
|
|
373
378
|
*/
|
|
374
379
|
json: (
|
|
375
|
-
constraints
|
|
380
|
+
constraints: ColumnConstraints & { validateJson?: boolean },
|
|
376
381
|
): ColumnDefinition => ({
|
|
377
382
|
type: SQLiteTypes.JSON,
|
|
378
|
-
check: constraints?.validateJson
|
|
383
|
+
check: constraints?.validateJson ?? true
|
|
379
384
|
? "JSON_VALID({{COLUMN}})"
|
|
380
385
|
: constraints?.check,
|
|
381
386
|
...constraints,
|
|
@@ -431,8 +436,8 @@ export const column = {
|
|
|
431
436
|
length: 36,
|
|
432
437
|
default: constraints?.generateDefault
|
|
433
438
|
? defaultExpr(
|
|
434
|
-
|
|
435
|
-
|
|
439
|
+
"lower(hex(randomblob(4))) || '-' || lower(hex(randomblob(2))) || '-4' || substr(lower(hex(randomblob(2))),2) || '-' || substr('89ab',abs(random()) % 4 + 1, 1) || substr(lower(hex(randomblob(2))),2) || '-' || lower(hex(randomblob(6)))",
|
|
440
|
+
)
|
|
436
441
|
: constraints?.default,
|
|
437
442
|
...constraints,
|
|
438
443
|
}),
|