@remix-run/data-table-sqlite 0.1.0 → 0.2.0
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 +8 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/lib/adapter.d.ts +87 -8
- package/dist/lib/adapter.d.ts.map +1 -1
- package/dist/lib/adapter.js +501 -20
- package/dist/lib/sql-compiler.d.ts +2 -7
- package/dist/lib/sql-compiler.d.ts.map +1 -1
- package/dist/lib/sql-compiler.js +50 -80
- package/package.json +6 -7
- package/src/index.ts +1 -1
- package/src/lib/adapter.ts +606 -38
- package/src/lib/sql-compiler.ts +66 -105
package/README.md
CHANGED
|
@@ -7,10 +7,14 @@ Use this package when you want `data-table` APIs backed by `better-sqlite3`.
|
|
|
7
7
|
|
|
8
8
|
- **Native `better-sqlite3` Integration**: Works well for local and embedded deployments
|
|
9
9
|
- **Full `data-table` API Support**: Queries, relations, writes, and transactions
|
|
10
|
+
- **Adapter-Owned Compiler**: SQL compilation lives in this adapter, with optional shared pure helpers from `data-table`
|
|
11
|
+
- **Migration DDL Support**: Compiles and executes `DataMigrationOperation` operations for `remix/data-table/migrations`
|
|
10
12
|
- **SQLite Capabilities Enabled By Default**:
|
|
11
13
|
- `returning: true`
|
|
12
14
|
- `savepoints: true`
|
|
13
15
|
- `upsert: true`
|
|
16
|
+
- `transactionalDdl: true`
|
|
17
|
+
- `migrationLock: false`
|
|
14
18
|
|
|
15
19
|
## Installation
|
|
16
20
|
|
|
@@ -30,6 +34,7 @@ let db = createDatabase(createSqliteDatabaseAdapter(sqlite))
|
|
|
30
34
|
```
|
|
31
35
|
|
|
32
36
|
This is a good fit for local development, embedded deployments, and single-node services.
|
|
37
|
+
Import any driver-specific types you need directly from `better-sqlite3`.
|
|
33
38
|
|
|
34
39
|
## Adapter Capabilities
|
|
35
40
|
|
|
@@ -38,6 +43,8 @@ This is a good fit for local development, embedded deployments, and single-node
|
|
|
38
43
|
- `returning: true`
|
|
39
44
|
- `savepoints: true`
|
|
40
45
|
- `upsert: true`
|
|
46
|
+
- `transactionalDdl: true`
|
|
47
|
+
- `migrationLock: false`
|
|
41
48
|
|
|
42
49
|
## Advanced Usage
|
|
43
50
|
|
|
@@ -67,7 +74,7 @@ let adapter = createSqliteDatabaseAdapter(sqlite, {
|
|
|
67
74
|
## Related Packages
|
|
68
75
|
|
|
69
76
|
- [`data-table`](https://github.com/remix-run/remix/tree/main/packages/data-table) - Core query/relations API
|
|
70
|
-
- [`data-schema`](https://github.com/remix-run/remix/tree/main/packages/data-schema) - Schema
|
|
77
|
+
- [`data-schema`](https://github.com/remix-run/remix/tree/main/packages/data-schema) - Schema parsing and validation
|
|
71
78
|
- [`data-table-postgres`](https://github.com/remix-run/remix/tree/main/packages/data-table-postgres) - PostgreSQL adapter
|
|
72
79
|
- [`data-table-mysql`](https://github.com/remix-run/remix/tree/main/packages/data-table-mysql) - MySQL adapter
|
|
73
80
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export type { SqliteDatabaseAdapterOptions
|
|
1
|
+
export type { SqliteDatabaseAdapterOptions } from './lib/adapter.ts';
|
|
2
2
|
export { createSqliteDatabaseAdapter, SqliteDatabaseAdapter } from './lib/adapter.ts';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,4BAA4B,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,4BAA4B,EAAE,MAAM,kBAAkB,CAAA;AACpE,OAAO,EAAE,2BAA2B,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA"}
|
package/dist/lib/adapter.d.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import type { AdapterCapabilityOverrides,
|
|
1
|
+
import type { AdapterCapabilityOverrides, DataManipulationRequest, DataMigrationRequest, DataMigrationResult, DataMigrationOperation, DataManipulationResult, DataManipulationOperation, DatabaseAdapter, SqlStatement, TableRef, TransactionOptions, TransactionToken } from '@remix-run/data-table';
|
|
2
2
|
import type { Database as BetterSqliteDatabase } from 'better-sqlite3';
|
|
3
|
-
/**
|
|
4
|
-
* Better SQLite3 database handle accepted by the sqlite adapter.
|
|
5
|
-
*/
|
|
6
|
-
export type SqliteDatabaseConnection = BetterSqliteDatabase;
|
|
7
3
|
/**
|
|
8
4
|
* Sqlite adapter configuration.
|
|
9
5
|
*/
|
|
@@ -15,19 +11,92 @@ export type SqliteDatabaseAdapterOptions = {
|
|
|
15
11
|
*/
|
|
16
12
|
export declare class SqliteDatabaseAdapter implements DatabaseAdapter {
|
|
17
13
|
#private;
|
|
14
|
+
/**
|
|
15
|
+
* The SQL dialect identifier reported by this adapter.
|
|
16
|
+
*/
|
|
18
17
|
dialect: string;
|
|
18
|
+
/**
|
|
19
|
+
* Feature flags describing the sqlite behaviors supported by this adapter.
|
|
20
|
+
*/
|
|
19
21
|
capabilities: {
|
|
20
22
|
returning: boolean;
|
|
21
23
|
savepoints: boolean;
|
|
22
24
|
upsert: boolean;
|
|
25
|
+
transactionalDdl: boolean;
|
|
26
|
+
migrationLock: boolean;
|
|
23
27
|
};
|
|
24
|
-
constructor(database:
|
|
25
|
-
|
|
28
|
+
constructor(database: BetterSqliteDatabase, options?: SqliteDatabaseAdapterOptions);
|
|
29
|
+
/**
|
|
30
|
+
* Compiles a data or migration operation to sqlite SQL statements.
|
|
31
|
+
* @param operation Operation to compile.
|
|
32
|
+
* @returns Compiled SQL statements.
|
|
33
|
+
*/
|
|
34
|
+
compileSql(operation: DataManipulationOperation | DataMigrationOperation): SqlStatement[];
|
|
35
|
+
/**
|
|
36
|
+
* Executes a sqlite data-manipulation request.
|
|
37
|
+
* @param request Request to execute.
|
|
38
|
+
* @returns Execution result.
|
|
39
|
+
*/
|
|
40
|
+
execute(request: DataManipulationRequest): Promise<DataManipulationResult>;
|
|
41
|
+
/**
|
|
42
|
+
* Executes sqlite migration operations.
|
|
43
|
+
* @param request Migration request to execute.
|
|
44
|
+
* @returns Migration result.
|
|
45
|
+
*/
|
|
46
|
+
migrate(request: DataMigrationRequest): Promise<DataMigrationResult>;
|
|
47
|
+
/**
|
|
48
|
+
* Checks whether a table exists in sqlite.
|
|
49
|
+
* @param table Table reference to inspect.
|
|
50
|
+
* @param transaction Optional transaction token.
|
|
51
|
+
* @returns `true` when the table exists.
|
|
52
|
+
*/
|
|
53
|
+
hasTable(table: TableRef, transaction?: TransactionToken): Promise<boolean>;
|
|
54
|
+
/**
|
|
55
|
+
* Checks whether a column exists in sqlite.
|
|
56
|
+
* @param table Table reference to inspect.
|
|
57
|
+
* @param column Column name to look up.
|
|
58
|
+
* @param transaction Optional transaction token.
|
|
59
|
+
* @returns `true` when the column exists.
|
|
60
|
+
*/
|
|
61
|
+
hasColumn(table: TableRef, column: string, transaction?: TransactionToken): Promise<boolean>;
|
|
62
|
+
/**
|
|
63
|
+
* Starts a sqlite transaction.
|
|
64
|
+
* @param options Transaction options.
|
|
65
|
+
* @returns Transaction token.
|
|
66
|
+
*/
|
|
26
67
|
beginTransaction(options?: TransactionOptions): Promise<TransactionToken>;
|
|
68
|
+
/**
|
|
69
|
+
* Commits an open sqlite transaction.
|
|
70
|
+
* @param token Transaction token to commit.
|
|
71
|
+
* @returns A promise that resolves when the transaction is committed.
|
|
72
|
+
*/
|
|
27
73
|
commitTransaction(token: TransactionToken): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Rolls back an open sqlite transaction.
|
|
76
|
+
* @param token Transaction token to roll back.
|
|
77
|
+
* @returns A promise that resolves when the transaction is rolled back.
|
|
78
|
+
*/
|
|
28
79
|
rollbackTransaction(token: TransactionToken): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Creates a savepoint in an open sqlite transaction.
|
|
82
|
+
* @param token Transaction token to use.
|
|
83
|
+
* @param name Savepoint name.
|
|
84
|
+
* @returns A promise that resolves when the savepoint is created.
|
|
85
|
+
*/
|
|
29
86
|
createSavepoint(token: TransactionToken, name: string): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Rolls back to a savepoint in an open sqlite transaction.
|
|
89
|
+
* @param token Transaction token to use.
|
|
90
|
+
* @param name Savepoint name.
|
|
91
|
+
* @returns A promise that resolves when the rollback completes.
|
|
92
|
+
*/
|
|
30
93
|
rollbackToSavepoint(token: TransactionToken, name: string): Promise<void>;
|
|
94
|
+
/**
|
|
95
|
+
* Releases a savepoint in an open sqlite transaction.
|
|
96
|
+
* @param token Transaction token to use.
|
|
97
|
+
* @param name Savepoint name.
|
|
98
|
+
* @returns A promise that resolves when the savepoint is released.
|
|
99
|
+
*/
|
|
31
100
|
releaseSavepoint(token: TransactionToken, name: string): Promise<void>;
|
|
32
101
|
}
|
|
33
102
|
/**
|
|
@@ -35,6 +104,16 @@ export declare class SqliteDatabaseAdapter implements DatabaseAdapter {
|
|
|
35
104
|
* @param database Better SQLite3 database instance.
|
|
36
105
|
* @param options Optional adapter capability overrides.
|
|
37
106
|
* @returns A configured sqlite adapter.
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* import BetterSqlite3 from 'better-sqlite3'
|
|
110
|
+
* import { createDatabase } from 'remix/data-table'
|
|
111
|
+
* import { createSqliteDatabaseAdapter } from 'remix/data-table-sqlite'
|
|
112
|
+
*
|
|
113
|
+
* let sqlite = new BetterSqlite3('./data/app.db')
|
|
114
|
+
* let adapter = createSqliteDatabaseAdapter(sqlite)
|
|
115
|
+
* let db = createDatabase(adapter)
|
|
116
|
+
* ```
|
|
38
117
|
*/
|
|
39
|
-
export declare function createSqliteDatabaseAdapter(database:
|
|
118
|
+
export declare function createSqliteDatabaseAdapter(database: BetterSqliteDatabase, options?: SqliteDatabaseAdapterOptions): SqliteDatabaseAdapter;
|
|
40
119
|
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/lib/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/lib/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,sBAAsB,EACtB,sBAAsB,EACtB,yBAAyB,EACzB,eAAe,EAEf,YAAY,EACZ,QAAQ,EACR,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,uBAAuB,CAAA;AAO9B,OAAO,KAAK,EAAE,QAAQ,IAAI,oBAAoB,EAAa,MAAM,gBAAgB,CAAA;AAIjF;;GAEG;AACH,MAAM,MAAM,4BAA4B,GAAG;IACzC,YAAY,CAAC,EAAE,0BAA0B,CAAA;CAC1C,CAAA;AAED;;GAEG;AACH,qBAAa,qBAAsB,YAAW,eAAe;;IAC3D;;OAEG;IACH,OAAO,SAAW;IAElB;;OAEG;IACH,YAAY;;;;;;MAAA;IAMZ,YAAY,QAAQ,EAAE,oBAAoB,EAAE,OAAO,CAAC,EAAE,4BAA4B,EASjF;IAED;;;;OAIG;IACH,UAAU,CAAC,SAAS,EAAE,yBAAyB,GAAG,sBAAsB,GAAG,YAAY,EAAE,CAOxF;IAED;;;;OAIG;IACG,OAAO,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAgC/E;IAED;;;;OAIG;IACG,OAAO,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAWzE;IAED;;;;;OAKG;IACG,QAAQ,CAAC,KAAK,EAAE,QAAQ,EAAE,WAAW,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAA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