@spinajs/orm-sqlite 2.0.480 → 2.0.482
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 +63 -3
- package/lib/cjs/compilers.d.ts +52 -1
- package/lib/cjs/compilers.d.ts.map +1 -1
- package/lib/cjs/compilers.js +105 -5
- package/lib/cjs/compilers.js.map +1 -1
- package/lib/cjs/converters.d.ts.map +1 -1
- package/lib/cjs/converters.js +20 -2
- package/lib/cjs/converters.js.map +1 -1
- package/lib/cjs/index.d.ts +46 -5
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/index.js +170 -88
- package/lib/cjs/index.js.map +1 -1
- package/lib/mjs/compilers.d.ts +52 -1
- package/lib/mjs/compilers.d.ts.map +1 -1
- package/lib/mjs/compilers.js +106 -6
- package/lib/mjs/compilers.js.map +1 -1
- package/lib/mjs/converters.d.ts.map +1 -1
- package/lib/mjs/converters.js +20 -2
- package/lib/mjs/converters.js.map +1 -1
- package/lib/mjs/index.d.ts +46 -5
- package/lib/mjs/index.d.ts.map +1 -1
- package/lib/mjs/index.js +173 -91
- package/lib/mjs/index.js.map +1 -1
- package/lib/tsconfig.cjs.tsbuildinfo +1 -1
- package/lib/tsconfig.mjs.tsbuildinfo +1 -1
- package/package.json +18 -19
package/README.md
CHANGED
|
@@ -1,11 +1,71 @@
|
|
|
1
1
|
# `@spinajs/orm-sqlite`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The SQLite dialect driver for [`@spinajs/orm`](../orm), built on
|
|
4
|
+
[`@spinajs/orm-sql`](../orm-sql).
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install @spinajs/orm @spinajs/orm-sqlite
|
|
10
|
+
```
|
|
4
11
|
|
|
5
12
|
## Usage
|
|
6
13
|
|
|
14
|
+
```ts
|
|
15
|
+
import { DI } from '@spinajs/di';
|
|
16
|
+
import { Orm } from '@spinajs/orm';
|
|
17
|
+
import { SqliteOrmDriver } from '@spinajs/orm-sqlite';
|
|
18
|
+
|
|
19
|
+
DI.register(SqliteOrmDriver).as('orm-driver-sqlite');
|
|
20
|
+
await DI.resolve(Orm);
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
// configuration
|
|
25
|
+
{
|
|
26
|
+
db: {
|
|
27
|
+
DefaultConnection: 'sqlite',
|
|
28
|
+
Connections: [
|
|
29
|
+
{
|
|
30
|
+
Name: 'sqlite',
|
|
31
|
+
Driver: 'orm-driver-sqlite',
|
|
32
|
+
Filename: './data/app.sqlite', // or ':memory:'
|
|
33
|
+
Pool: { Max: 4 }, // sizes the READ-ONLY handle pool
|
|
34
|
+
Migration: { OnStartup: true },
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
}
|
|
7
39
|
```
|
|
8
|
-
const ormSqlite = require('@spinajs/orm-sqlite');
|
|
9
40
|
|
|
10
|
-
|
|
41
|
+
## What is distinctive
|
|
42
|
+
|
|
43
|
+
- **`Pool.Max` sizes read-only handles, not writers.** SQLite serializes writers at the file
|
|
44
|
+
level, so extra writer handles buy nothing and invite `SQLITE_BUSY`. The driver opens
|
|
45
|
+
`Max - 1` read handles instead, skipped entirely for `:memory:` and anonymous temporary
|
|
46
|
+
databases.
|
|
47
|
+
- **The only driver with `RETURNING`** (`insertReturning: true`), so generated keys come back
|
|
48
|
+
exactly — including from multi-row inserts.
|
|
49
|
+
- **`SERIALIZABLE` is the only isolation level**, because sqlite3 outside shared-cache mode
|
|
50
|
+
serializes file access and that *is* SERIALIZABLE.
|
|
51
|
+
- **No database events**, **no `TRUNCATE`** (a `DELETE` stands in, and the auto-increment counter
|
|
52
|
+
is not reset), and **multi-column `ORDER BY` is reduced to one column**.
|
|
53
|
+
- **No auto-increment column inside a composite primary key** — the compiler throws rather than
|
|
54
|
+
emit invalid SQL.
|
|
55
|
+
|
|
56
|
+
## Documentation
|
|
57
|
+
|
|
58
|
+
Full documentation lives in **[docs/](docs/)**.
|
|
59
|
+
|
|
60
|
+
| | Page |
|
|
61
|
+
| --- | --- |
|
|
62
|
+
| 01 | [Configuration](docs/01-configuration.md) |
|
|
63
|
+
| 02 | [Dialect notes](docs/02-dialect-notes.md) |
|
|
64
|
+
|
|
65
|
+
## Development
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
npm test # unit suite, no server needed
|
|
69
|
+
npm run test:integration # creates and removes a temporary on-disk database
|
|
70
|
+
npm run build
|
|
11
71
|
```
|
package/lib/cjs/compilers.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { SqlColumnQueryCompiler, SqlTableQueryCompiler, SqlOnDuplicateQueryCompiler, SqlInsertQueryCompiler } from '@spinajs/orm-sql';
|
|
1
|
+
import { SqlColumnQueryCompiler, SqlTableQueryCompiler, SqlOnDuplicateQueryCompiler, SqlInsertQueryCompiler, SqlAlterColumnQueryCompiler } from '@spinajs/orm-sql';
|
|
2
2
|
import { ICompilerOutput, OrderByBuilder, OrderByQueryCompiler, OnDuplicateQueryBuilder, InsertQueryBuilder, TableExistsCompiler, TableExistsQueryBuilder, TableQueryCompiler, TableQueryBuilder } from '@spinajs/orm';
|
|
3
3
|
import { Container, IContainer } from '@spinajs/di';
|
|
4
|
+
import { Log } from '@spinajs/log';
|
|
4
5
|
export declare class SqliteTruncateTableQueryCompiler extends TableQueryCompiler {
|
|
5
6
|
protected container: Container;
|
|
6
7
|
protected builder: TableQueryBuilder;
|
|
@@ -33,10 +34,60 @@ export declare class SqliteInsertQueryCompiler extends SqlInsertQueryCompiler {
|
|
|
33
34
|
bindings: any[];
|
|
34
35
|
expression: string;
|
|
35
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* RETURNING on a plain INSERT. Skipped when an upsert clause is present — the ON CONFLICT
|
|
39
|
+
* compiler emits its own RETURNING and two would be invalid SQL.
|
|
40
|
+
*/
|
|
41
|
+
protected returning(): string;
|
|
36
42
|
protected into(): string;
|
|
37
43
|
}
|
|
38
44
|
export declare class SqliteColumnCompiler extends SqlColumnQueryCompiler {
|
|
39
45
|
compile(): ICompilerOutput;
|
|
46
|
+
/**
|
|
47
|
+
* CREATE TABLE renders a boolean as a non-nullable 0/1 domain.
|
|
48
|
+
* Overridable: ADD COLUMN cannot carry an unconditional NOT NULL - see
|
|
49
|
+
* {@link SqliteAddColumnCompiler}.
|
|
50
|
+
*/
|
|
51
|
+
protected _booleanDefinition(): string;
|
|
40
52
|
protected _defaultCompiler(): string;
|
|
41
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Column body for `ALTER TABLE ... ADD COLUMN`.
|
|
56
|
+
*
|
|
57
|
+
* sqlite refuses to add a NOT NULL column without a non-null default, so the
|
|
58
|
+
* unconditional NOT NULL that CREATE TABLE bakes into a boolean makes every
|
|
59
|
+
* boolean add fail against a table that already holds rows. The CHECK is kept -
|
|
60
|
+
* it is legal in ADD COLUMN and still enforces the 0/1 domain - and NOT NULL is
|
|
61
|
+
* left to the generic `notNull()` flag, so `.notNull().default().value(0)` still
|
|
62
|
+
* yields a non-nullable column.
|
|
63
|
+
*/
|
|
64
|
+
export declare class SqliteAddColumnCompiler extends SqliteColumnCompiler {
|
|
65
|
+
protected _booleanDefinition(): string;
|
|
66
|
+
}
|
|
67
|
+
export interface SqliteAlterColumnQueryCompiler {
|
|
68
|
+
}
|
|
69
|
+
export declare class SqliteAlterColumnQueryCompiler extends SqlAlterColumnQueryCompiler {
|
|
70
|
+
protected Log: Log;
|
|
71
|
+
/**
|
|
72
|
+
* The ADD path needs a body free of CREATE-TABLE-only syntax.
|
|
73
|
+
*
|
|
74
|
+
* Note PRIMARY KEY / UNIQUE are deliberately NOT stripped here: sqlite cannot
|
|
75
|
+
* add such a column at all (it rejects both the mysql and the sqlite spelling),
|
|
76
|
+
* so suppressing the clause would silently produce a column WITHOUT the
|
|
77
|
+
* constraint the caller asked for. Letting sqlite's own error surface is honest.
|
|
78
|
+
*/
|
|
79
|
+
protected _columnDefinition(): ICompilerOutput;
|
|
80
|
+
/**
|
|
81
|
+
* sqlite cannot change a column's type: it has no MODIFY / ALTER COLUMN.
|
|
82
|
+
* It is also dynamically typed and renders enum/string/date as unconstrained
|
|
83
|
+
* TEXT, so a type-only change is a semantic no-op here anyway.
|
|
84
|
+
*
|
|
85
|
+
* Constraint changes (NOT NULL / DEFAULT / UNIQUE) ARE enforced by sqlite and
|
|
86
|
+
* are NOT applied - they need an explicit table-rebuild migration. Warn rather
|
|
87
|
+
* than throw: portable migrations legitimately restate existing constraints
|
|
88
|
+
* (mysql's MODIFY drops any attribute you omit), and throwing would break them.
|
|
89
|
+
*/
|
|
90
|
+
protected _modify(_definition: string): string | null;
|
|
91
|
+
protected _add(definition: string): string | null;
|
|
92
|
+
}
|
|
42
93
|
//# sourceMappingURL=compilers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compilers.d.ts","sourceRoot":"","sources":["../../src/compilers.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,2BAA2B,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"compilers.d.ts","sourceRoot":"","sources":["../../src/compilers.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,2BAA2B,EAAE,sBAAsB,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AACnK,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,oBAAoB,EAAY,uBAAuB,EAAmB,kBAAkB,EAAE,mBAAmB,EAAE,uBAAuB,EAAgB,kBAAkB,EAAE,iBAAiB,EAA4C,MAAM,cAAc,CAAC;AAC1S,OAAO,EAAuB,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAU,GAAG,EAAE,MAAM,cAAc,CAAC;AAG3C,qBACa,gCAAiC,SAAQ,kBAAkB;IAC1D,S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AAW,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAKrD,SAAS,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;CAIlD"}
|
package/lib/cjs/compilers.js
CHANGED
|
@@ -14,10 +14,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.SqliteColumnCompiler = exports.SqliteInsertQueryCompiler = exports.SqliteTableQueryCompiler = exports.SqliteTableExistsCompiler = exports.SqliteOnDuplicateQueryCompiler = exports.SqliteOrderByCompiler = exports.SqliteTruncateTableQueryCompiler = void 0;
|
|
17
|
+
exports.SqliteAlterColumnQueryCompiler = exports.SqliteAddColumnCompiler = exports.SqliteColumnCompiler = exports.SqliteInsertQueryCompiler = exports.SqliteTableQueryCompiler = exports.SqliteTableExistsCompiler = exports.SqliteOnDuplicateQueryCompiler = exports.SqliteOrderByCompiler = exports.SqliteTruncateTableQueryCompiler = void 0;
|
|
18
18
|
const orm_sql_1 = require("@spinajs/orm-sql");
|
|
19
19
|
const orm_1 = require("@spinajs/orm");
|
|
20
20
|
const di_1 = require("@spinajs/di");
|
|
21
|
+
const log_1 = require("@spinajs/log");
|
|
21
22
|
const lodash_1 = __importDefault(require("lodash"));
|
|
22
23
|
let SqliteTruncateTableQueryCompiler = class SqliteTruncateTableQueryCompiler extends orm_1.TableQueryCompiler {
|
|
23
24
|
constructor(container, builder) {
|
|
@@ -122,13 +123,30 @@ exports.SqliteTableExistsCompiler = SqliteTableExistsCompiler = __decorate([
|
|
|
122
123
|
], SqliteTableExistsCompiler);
|
|
123
124
|
let SqliteTableQueryCompiler = class SqliteTableQueryCompiler extends orm_sql_1.SqlTableQueryCompiler {
|
|
124
125
|
compile() {
|
|
126
|
+
const pkColumns = this.builder.Columns.filter((c) => c.PrimaryKey);
|
|
127
|
+
// SQLite has no syntax for two inline PRIMARY KEY column constraints - it rejects
|
|
128
|
+
// `table ... has more than one primary key` - and AUTOINCREMENT is only legal on a single
|
|
129
|
+
// INTEGER PRIMARY KEY. Composite keys therefore move to a table-level constraint and
|
|
130
|
+
// cannot include an auto-increment column.
|
|
131
|
+
if (pkColumns.length > 1) {
|
|
132
|
+
const auto = pkColumns.find((c) => c.AutoIncrement);
|
|
133
|
+
if (auto) {
|
|
134
|
+
throw new orm_1.OrmException(`sqlite cannot auto-increment column ${auto.Name}: it is part of the composite primary key of ${this.builder.Table}`);
|
|
135
|
+
}
|
|
136
|
+
pkColumns.forEach((c) => (c.InlinePrimaryKey = false));
|
|
137
|
+
}
|
|
125
138
|
const _table = this._table();
|
|
126
139
|
const _columns = this._columns();
|
|
127
140
|
const _foreignKeys = this._foreignKeys();
|
|
141
|
+
const _primaryKey = pkColumns.length > 1 ? this._primaryKeys() : '';
|
|
142
|
+
// Built by concatenation rather than one template literal so that a table with neither a
|
|
143
|
+
// table-level primary key nor foreign keys emits byte-identically to the pre-composite
|
|
144
|
+
// compiler ( a template with two empty interpolations leaves a double space behind ).
|
|
145
|
+
const _extra = `${_primaryKey ? ',' + _primaryKey : ''}${_foreignKeys ? ',' + _foreignKeys : ''}`;
|
|
128
146
|
return [
|
|
129
147
|
{
|
|
130
148
|
bindings: [],
|
|
131
|
-
expression: `${_table} (${_columns}
|
|
149
|
+
expression: `${_table} (${_columns}${_extra} )`,
|
|
132
150
|
},
|
|
133
151
|
];
|
|
134
152
|
}
|
|
@@ -147,11 +165,23 @@ let SqliteInsertQueryCompiler = class SqliteInsertQueryCompiler extends orm_sql_
|
|
|
147
165
|
const columns = this.columns();
|
|
148
166
|
const values = this.values();
|
|
149
167
|
const upsort = this.upsort();
|
|
168
|
+
const returning = this.returning();
|
|
150
169
|
return {
|
|
151
170
|
bindings: values.bindings.concat(upsort.bindings),
|
|
152
|
-
expression: `${into} ${columns} ${values.data} ${upsort.expression}`.trim(),
|
|
171
|
+
expression: `${into} ${columns} ${values.data} ${upsort.expression}${returning}`.trim(),
|
|
153
172
|
};
|
|
154
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* RETURNING on a plain INSERT. Skipped when an upsert clause is present — the ON CONFLICT
|
|
176
|
+
* compiler emits its own RETURNING and two would be invalid SQL.
|
|
177
|
+
*/
|
|
178
|
+
returning() {
|
|
179
|
+
if (this._builder.Update || this._builder.Returning.length === 0) {
|
|
180
|
+
return '';
|
|
181
|
+
}
|
|
182
|
+
const cols = this._builder.Returning[0] === '*' ? ['*'] : this._builder.Returning.map((c) => `\`${c}\``);
|
|
183
|
+
return ` RETURNING ${cols.join(',')}`;
|
|
184
|
+
}
|
|
155
185
|
into() {
|
|
156
186
|
return `INSERT${this._builder.Ignore ? ' OR IGNORE' : ''}${this._builder.Replace ? ' OR REPLACE' : ''} INTO \`${this._builder.Table}\``;
|
|
157
187
|
}
|
|
@@ -201,7 +231,7 @@ let SqliteColumnCompiler = class SqliteColumnCompiler extends orm_sql_1.SqlColum
|
|
|
201
231
|
_stmt.push('INTEGER');
|
|
202
232
|
break;
|
|
203
233
|
case 'boolean':
|
|
204
|
-
_stmt.push(
|
|
234
|
+
_stmt.push(this._booleanDefinition());
|
|
205
235
|
break;
|
|
206
236
|
}
|
|
207
237
|
if (this.builder.Unsigned) {
|
|
@@ -222,7 +252,7 @@ let SqliteColumnCompiler = class SqliteColumnCompiler extends orm_sql_1.SqlColum
|
|
|
222
252
|
if (this.builder.Comment) {
|
|
223
253
|
_stmt.push(`COMMENT '${this.builder.Comment}'`);
|
|
224
254
|
}
|
|
225
|
-
if (this.builder.PrimaryKey) {
|
|
255
|
+
if (this.builder.PrimaryKey && this.builder.InlinePrimaryKey) {
|
|
226
256
|
_stmt.push(`PRIMARY KEY`);
|
|
227
257
|
}
|
|
228
258
|
if (this.builder.AutoIncrement) {
|
|
@@ -236,6 +266,14 @@ let SqliteColumnCompiler = class SqliteColumnCompiler extends orm_sql_1.SqlColum
|
|
|
236
266
|
expression: _stmt.filter((x) => !lodash_1.default.isEmpty(x)).join(' '),
|
|
237
267
|
};
|
|
238
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* CREATE TABLE renders a boolean as a non-nullable 0/1 domain.
|
|
271
|
+
* Overridable: ADD COLUMN cannot carry an unconditional NOT NULL - see
|
|
272
|
+
* {@link SqliteAddColumnCompiler}.
|
|
273
|
+
*/
|
|
274
|
+
_booleanDefinition() {
|
|
275
|
+
return `BOOLEAN NOT NULL CHECK ( \`${this.builder.Name}\` IN (0, 1))`;
|
|
276
|
+
}
|
|
239
277
|
_defaultCompiler() {
|
|
240
278
|
let _stmt = '';
|
|
241
279
|
if (lodash_1.default.isNil(this.builder.Default) || (lodash_1.default.isString(this.builder.Default) && lodash_1.default.isEmpty(this.builder.Default.trim()))) {
|
|
@@ -257,4 +295,66 @@ exports.SqliteColumnCompiler = SqliteColumnCompiler;
|
|
|
257
295
|
exports.SqliteColumnCompiler = SqliteColumnCompiler = __decorate([
|
|
258
296
|
(0, di_1.NewInstance)()
|
|
259
297
|
], SqliteColumnCompiler);
|
|
298
|
+
/**
|
|
299
|
+
* Column body for `ALTER TABLE ... ADD COLUMN`.
|
|
300
|
+
*
|
|
301
|
+
* sqlite refuses to add a NOT NULL column without a non-null default, so the
|
|
302
|
+
* unconditional NOT NULL that CREATE TABLE bakes into a boolean makes every
|
|
303
|
+
* boolean add fail against a table that already holds rows. The CHECK is kept -
|
|
304
|
+
* it is legal in ADD COLUMN and still enforces the 0/1 domain - and NOT NULL is
|
|
305
|
+
* left to the generic `notNull()` flag, so `.notNull().default().value(0)` still
|
|
306
|
+
* yields a non-nullable column.
|
|
307
|
+
*/
|
|
308
|
+
let SqliteAddColumnCompiler = class SqliteAddColumnCompiler extends SqliteColumnCompiler {
|
|
309
|
+
_booleanDefinition() {
|
|
310
|
+
return `BOOLEAN CHECK ( \`${this.builder.Name}\` IN (0, 1))`;
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
exports.SqliteAddColumnCompiler = SqliteAddColumnCompiler;
|
|
314
|
+
exports.SqliteAddColumnCompiler = SqliteAddColumnCompiler = __decorate([
|
|
315
|
+
(0, di_1.NewInstance)()
|
|
316
|
+
], SqliteAddColumnCompiler);
|
|
317
|
+
let SqliteAlterColumnQueryCompiler = class SqliteAlterColumnQueryCompiler extends orm_sql_1.SqlAlterColumnQueryCompiler {
|
|
318
|
+
/**
|
|
319
|
+
* The ADD path needs a body free of CREATE-TABLE-only syntax.
|
|
320
|
+
*
|
|
321
|
+
* Note PRIMARY KEY / UNIQUE are deliberately NOT stripped here: sqlite cannot
|
|
322
|
+
* add such a column at all (it rejects both the mysql and the sqlite spelling),
|
|
323
|
+
* so suppressing the clause would silently produce a column WITHOUT the
|
|
324
|
+
* constraint the caller asked for. Letting sqlite's own error surface is honest.
|
|
325
|
+
*/
|
|
326
|
+
_columnDefinition() {
|
|
327
|
+
if (this.builder.AlterType === orm_1.ColumnAlterationType.Add) {
|
|
328
|
+
return this.container.resolve(SqliteAddColumnCompiler, [this.builder]).compile();
|
|
329
|
+
}
|
|
330
|
+
return super._columnDefinition();
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* sqlite cannot change a column's type: it has no MODIFY / ALTER COLUMN.
|
|
334
|
+
* It is also dynamically typed and renders enum/string/date as unconstrained
|
|
335
|
+
* TEXT, so a type-only change is a semantic no-op here anyway.
|
|
336
|
+
*
|
|
337
|
+
* Constraint changes (NOT NULL / DEFAULT / UNIQUE) ARE enforced by sqlite and
|
|
338
|
+
* are NOT applied - they need an explicit table-rebuild migration. Warn rather
|
|
339
|
+
* than throw: portable migrations legitimately restate existing constraints
|
|
340
|
+
* (mysql's MODIFY drops any attribute you omit), and throwing would break them.
|
|
341
|
+
*/
|
|
342
|
+
_modify(_definition) {
|
|
343
|
+
this.Log.warn(`sqlite cannot MODIFY column '${this.builder.Name}' - skipping. Type changes are a no-op (sqlite is dynamically typed); any NOT NULL / DEFAULT / UNIQUE change was NOT applied. Write an explicit table-rebuild migration if you need one.`);
|
|
344
|
+
return null;
|
|
345
|
+
}
|
|
346
|
+
_add(definition) {
|
|
347
|
+
// AFTER is mysql-only; sqlite rejects it
|
|
348
|
+
return `ADD ${definition}`;
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
exports.SqliteAlterColumnQueryCompiler = SqliteAlterColumnQueryCompiler;
|
|
352
|
+
__decorate([
|
|
353
|
+
(0, log_1.Logger)('ORM'),
|
|
354
|
+
__metadata("design:type", log_1.Log)
|
|
355
|
+
], SqliteAlterColumnQueryCompiler.prototype, "Log", void 0);
|
|
356
|
+
exports.SqliteAlterColumnQueryCompiler = SqliteAlterColumnQueryCompiler = __decorate([
|
|
357
|
+
(0, di_1.NewInstance)(),
|
|
358
|
+
(0, di_1.Inject)(di_1.Container)
|
|
359
|
+
], SqliteAlterColumnQueryCompiler);
|
|
260
360
|
//# sourceMappingURL=compilers.js.map
|
package/lib/cjs/compilers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compilers.js","sourceRoot":"","sources":["../../src/compilers.ts"],"names":[],"mappings":";AAAA,qDAAqD;AACrD,sCAAsC;;;;;;;;;;;;;;;AAEtC,
|
|
1
|
+
{"version":3,"file":"compilers.js","sourceRoot":"","sources":["../../src/compilers.ts"],"names":[],"mappings":";AAAA,qDAAqD;AACrD,sCAAsC;;;;;;;;;;;;;;;AAEtC,8CAAmK;AACnK,sCAA0S;AAC1S,oCAAyE;AACzE,sCAA2C;AAC3C,oDAAuB;AAGhB,IAAM,gCAAgC,GAAtC,MAAM,gCAAiC,SAAQ,wBAAkB;IACtE,YAAsB,SAAoB,EAAY,OAA0B;QAC9E,KAAK,EAAE,CAAC;QADY,cAAS,GAAT,SAAS,CAAW;QAAY,YAAO,GAAP,OAAO,CAAmB;IAEhF,CAAC;IAEM,OAAO;QACZ,OAAO;YACL,QAAQ,EAAE,EAAE;YACZ,UAAU,EAAE,eAAe,IAAI,CAAC,SAAS,CAA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wEAA8B;AAE/B;IADT,IAAA,YAAM,EAAC,KAAK,CAAC;8BACC,SAAG;2DAAC;yCAFR,8BAA8B;IAF1C,IAAA,gBAAW,GAAE;IACb,IAAA,WAAM,EAAC,cAAS,CAAC;GACL,8BAA8B,CAuC1C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"converters.d.ts","sourceRoot":"","sources":["../../src/converters.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAA8B,MAAM,cAAc,CAAC;AAE1F,qBAAa,yBAA0B,SAAQ,mBAAmB;IACzD,KAAK,CAAC,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG,OAAO;
|
|
1
|
+
{"version":3,"file":"converters.d.ts","sourceRoot":"","sources":["../../src/converters.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAA8B,MAAM,cAAc,CAAC;AAE1F,qBAAa,yBAA0B,SAAQ,mBAAmB;IACzD,KAAK,CAAC,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG,OAAO;CAqDjD"}
|
package/lib/cjs/converters.js
CHANGED
|
@@ -10,7 +10,14 @@ class SqliteModelToSqlConverter extends orm_1.ModelToSqlConverter {
|
|
|
10
10
|
toSql(model) {
|
|
11
11
|
const obj = {};
|
|
12
12
|
const relArr = [...model.ModelDescriptor.Relations.values()];
|
|
13
|
-
|
|
13
|
+
// Foreign-key columns are normally written via their relation (the loop
|
|
14
|
+
// below sets obj[ForeignKey] from the related model). But a FK column with no
|
|
15
|
+
// backing relation on the model (e.g. a plain owner-id column such as
|
|
16
|
+
// user_sessions.UserId) would otherwise never be serialized at all, breaking
|
|
17
|
+
// INSERTs that hit its NOT NULL constraint. So only skip FK columns that an
|
|
18
|
+
// actual relation manages; serialize unrelated FK columns like normal ones.
|
|
19
|
+
const relationForeignKeys = new Set(relArr.map((r) => r.ForeignKey));
|
|
20
|
+
model.ModelDescriptor.Columns?.filter((x) => !x.IsForeignKey || !relationForeignKeys.has(x.Name)).forEach((c) => {
|
|
14
21
|
const val = model[c.Name];
|
|
15
22
|
if (!c.PrimaryKey && !c.Nullable && (val === null || val === undefined || val === '')) {
|
|
16
23
|
throw new orm_1.OrmException(`Field ${c.Name} cannot be null`);
|
|
@@ -25,9 +32,20 @@ class SqliteModelToSqlConverter extends orm_1.ModelToSqlConverter {
|
|
|
25
32
|
});
|
|
26
33
|
for (const val of relArr) {
|
|
27
34
|
if (val.Type === orm_1.RelationType.One) {
|
|
28
|
-
if (model[val.Name]
|
|
35
|
+
if (model[val.Name]?.Value) {
|
|
29
36
|
obj[val.ForeignKey] = model[val.Name].Value.PrimaryKeyValue;
|
|
30
37
|
}
|
|
38
|
+
else if (model[val.ForeignKey] != null) {
|
|
39
|
+
// Fallback: when the BelongsTo SingleRelation has no Value (e.g. the relation was
|
|
40
|
+
// never populated, or the foreign key was written directly), fall back to the raw
|
|
41
|
+
// FK column. Without this the column is dropped from every payload, because the
|
|
42
|
+
// filter above already excluded it as relation-managed - so a row whose owner
|
|
43
|
+
// changed would silently keep its old foreign key.
|
|
44
|
+
//
|
|
45
|
+
// Mirrors StandardModelToSqlConverter in @spinajs/orm, which grew this branch
|
|
46
|
+
// while this override did not.
|
|
47
|
+
obj[val.ForeignKey] = model[val.ForeignKey];
|
|
48
|
+
}
|
|
31
49
|
}
|
|
32
50
|
// HACK: This is a hack to fix the issue with the recursive relation
|
|
33
51
|
// recursive relations usually dont ahve set @belongsTo but @HasMany decorator and are not in list of relaitons
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"converters.js","sourceRoot":"","sources":["../../src/converters.ts"],"names":[],"mappings":";;;AAAA,qDAAqD;AACrD,uDAAuD;AACvD,+DAA+D;AAC/D,4DAA4D;AAC5D,sCAA0F;AAE1F,MAAa,yBAA0B,SAAQ,yBAAmB;IACzD,KAAK,CAAC,KAAyB;QACpC,MAAM,GAAG,GAAG,EAAE,CAAC;QACf,MAAM,MA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gBACjB,GAAW,CAAC,GAAG,CAAC,UAAU,CAAC,GAAI,KAAa,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YAChE,CAAC;QACH,CAAC;QAED,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AAtDD,8DAsDC"}
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -1,23 +1,64 @@
|
|
|
1
1
|
export * from './compilers.js';
|
|
2
|
-
import { IColumnDescriptor, QueryContext, OrmDriver,
|
|
2
|
+
import { IColumnDescriptor, QueryContext, OrmDriver, ServerResponseMapper, ISupportedFeature, IsolationLevel, ITransactionContext, ITransactionOptions, IPoolMetrics } from '@spinajs/orm';
|
|
3
3
|
import sqlite3 from 'sqlite3';
|
|
4
4
|
import { SqlDriver } from '@spinajs/orm-sql';
|
|
5
5
|
export declare class SqliteServerResponseMapper extends ServerResponseMapper {
|
|
6
|
-
read(data: any,
|
|
6
|
+
read(data: any, pkNames?: string[]): {
|
|
7
|
+
RowsAffected: any;
|
|
7
8
|
LastInsertId: any;
|
|
9
|
+
Returning: any;
|
|
8
10
|
};
|
|
9
11
|
}
|
|
10
12
|
export declare class SqliteOrmDriver extends SqlDriver {
|
|
11
|
-
protected executionId: number;
|
|
12
13
|
protected Db: sqlite3.Database;
|
|
13
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Read-only handles. SQLite serializes writers at the file level no matter how many handles are
|
|
16
|
+
* open, so a second WRITER handle buys nothing and invites SQLITE_BUSY; extra READ handles do
|
|
17
|
+
* parallelize SELECTs. Empty for `:memory:` and anonymous temporary databases, where each handle
|
|
18
|
+
* would open its own private database, and when `Pool.Max` is 1.
|
|
19
|
+
*/
|
|
20
|
+
protected ReadPool: sqlite3.Database[];
|
|
21
|
+
private _readCursor;
|
|
22
|
+
/**
|
|
23
|
+
* sqlite3 outside shared-cache mode serializes access to the database file, which is
|
|
24
|
+
* SERIALIZABLE and nothing else. Any other requested level is rejected by the base class
|
|
25
|
+
* rather than silently ignored.
|
|
26
|
+
*/
|
|
27
|
+
readonly SupportedIsolationLevels: IsolationLevel[];
|
|
28
|
+
/**
|
|
29
|
+
* Picks the handle for a query. Everything that mutates, changes schema, or runs inside a
|
|
30
|
+
* transaction stays on the single writer handle — scattering a transaction's statements across
|
|
31
|
+
* handles would run them outside the transaction, and a read handle cannot see uncommitted
|
|
32
|
+
* writes made on the writer.
|
|
33
|
+
*/
|
|
34
|
+
protected handleFor(queryContext: QueryContext): sqlite3.Database;
|
|
35
|
+
/**
|
|
36
|
+
* The writer handle plus every read handle. SQLite has no queue of waiting callers — sqlite3
|
|
37
|
+
* serializes internally per handle — so InUse and Waiting are always zero.
|
|
38
|
+
*/
|
|
39
|
+
poolMetrics(): IPoolMetrics;
|
|
14
40
|
executeOnDb(stmt: string, params: unknown[], queryContext: QueryContext): Promise<unknown>;
|
|
15
41
|
supportedFeatures(): ISupportedFeature;
|
|
16
42
|
ping(): Promise<boolean>;
|
|
17
43
|
connect(): Promise<OrmDriver>;
|
|
44
|
+
/**
|
|
45
|
+
* Opens `Pool.Max - 1` read-only handles. Skipped for `:memory:` and for anonymous temporary
|
|
46
|
+
* databases, where every handle gets its own private database and a read pool would query empty
|
|
47
|
+
* files. A handle that fails to open is dropped rather than failing the connection — the driver
|
|
48
|
+
* is fully usable on the writer alone.
|
|
49
|
+
*/
|
|
50
|
+
protected openReadPool(filename: string): Promise<void>;
|
|
51
|
+
/** Closes every read handle. Safe to call when none are open. */
|
|
52
|
+
protected closeReadPool(): Promise<void>;
|
|
18
53
|
disconnect(): Promise<OrmDriver>;
|
|
19
54
|
resolve(): void;
|
|
20
|
-
|
|
55
|
+
protected _begin(_options?: ITransactionOptions): Promise<ITransactionContext>;
|
|
56
|
+
protected _commit(_ctx: ITransactionContext): Promise<void>;
|
|
57
|
+
protected _rollback(_ctx: ITransactionContext): Promise<void>;
|
|
58
|
+
protected _savepoint(_ctx: ITransactionContext, name: string): Promise<void>;
|
|
59
|
+
protected _releaseSavepoint(_ctx: ITransactionContext, name: string): Promise<void>;
|
|
60
|
+
protected _rollbackToSavepoint(_ctx: ITransactionContext, name: string): Promise<void>;
|
|
61
|
+
protected _dispose(_ctx: ITransactionContext): Promise<void>;
|
|
21
62
|
/**
|
|
22
63
|
*
|
|
23
64
|
* Retrieves information about specific DB table if exists. If table not exists returns null
|
package/lib/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AASA,cAAc,gBAAgB,CAAC;AAO/B,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAqE,SAAS,EAA+M,oBAAoB,EAAE,iBAAiB,EAAE,cAAc,EAAE,mBAAmB,EAAE,mBAAmB,EAAmB,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5d,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAoB,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAS/D,qBAAa,0BAA2B,SAAQ,oBAAoB;IAC3D,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE;;;;;CAuB1C;AAED,qBAEa,eAAgB,SAAQ,SAAS;IAC5C,SAAS,CAAC,EAAE,EAAE,OAAO,CAAC,QAAQ,CAAC;IAE/B;;;;;OAKG;IACH,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAM;IAE5C,OAAO,CAAC,WAAW,CAAM;IAEzB;;;;OAIG;IACH,SAAgB,wBAAwB,EAAE,cAAc,EAAE,CAAoB;IAK9E;;;;;OAKG;IACH,SAAS,CAAC,SAAS,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,QAAQ;IAcjE;;;OAGG;IACI,WAAW,IAAI,YAAY;IAQ3B,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,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