@remix-run/data-table-sqlite 0.0.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/LICENSE +21 -0
- package/README.md +82 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/lib/adapter.d.ts +119 -0
- package/dist/lib/adapter.d.ts.map +1 -0
- package/dist/lib/adapter.js +652 -0
- package/dist/lib/sql-compiler.d.ts +3 -0
- package/dist/lib/sql-compiler.d.ts.map +1 -0
- package/dist/lib/sql-compiler.js +347 -0
- package/package.json +48 -7
- package/src/index.ts +2 -0
- package/src/lib/adapter.ts +831 -0
- package/src/lib/sql-compiler.ts +487 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Shopify Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,83 @@
|
|
|
1
|
-
#
|
|
1
|
+
# data-table-sqlite
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
SQLite adapter for [`remix/data-table`](https://github.com/remix-run/remix/tree/main/packages/data-table).
|
|
4
|
+
Use this package when you want `data-table` APIs backed by `better-sqlite3`.
|
|
5
|
+
|
|
6
|
+
## Features
|
|
7
|
+
|
|
8
|
+
- **Native `better-sqlite3` Integration**: Works well for local and embedded deployments
|
|
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`
|
|
12
|
+
- **SQLite Capabilities Enabled By Default**:
|
|
13
|
+
- `returning: true`
|
|
14
|
+
- `savepoints: true`
|
|
15
|
+
- `upsert: true`
|
|
16
|
+
- `transactionalDdl: true`
|
|
17
|
+
- `migrationLock: false`
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
npm i remix better-sqlite3
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import Database from 'better-sqlite3'
|
|
29
|
+
import { createDatabase } from 'remix/data-table'
|
|
30
|
+
import { createSqliteDatabaseAdapter } from 'remix/data-table-sqlite'
|
|
31
|
+
|
|
32
|
+
let sqlite = new Database('app.db')
|
|
33
|
+
let db = createDatabase(createSqliteDatabaseAdapter(sqlite))
|
|
34
|
+
```
|
|
35
|
+
|
|
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`.
|
|
38
|
+
|
|
39
|
+
## Adapter Capabilities
|
|
40
|
+
|
|
41
|
+
`data-table-sqlite` reports this capability set by default:
|
|
42
|
+
|
|
43
|
+
- `returning: true`
|
|
44
|
+
- `savepoints: true`
|
|
45
|
+
- `upsert: true`
|
|
46
|
+
- `transactionalDdl: true`
|
|
47
|
+
- `migrationLock: false`
|
|
48
|
+
|
|
49
|
+
## Advanced Usage
|
|
50
|
+
|
|
51
|
+
### In-Memory Database For Tests
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import Database from 'better-sqlite3'
|
|
55
|
+
import { createDatabase } from 'remix/data-table'
|
|
56
|
+
import { createSqliteDatabaseAdapter } from 'remix/data-table-sqlite'
|
|
57
|
+
|
|
58
|
+
let sqlite = new Database(':memory:')
|
|
59
|
+
let db = createDatabase(createSqliteDatabaseAdapter(sqlite))
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Capability Overrides For Fallback Testing
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import { createSqliteDatabaseAdapter } from 'remix/data-table-sqlite'
|
|
66
|
+
|
|
67
|
+
let adapter = createSqliteDatabaseAdapter(sqlite, {
|
|
68
|
+
capabilities: {
|
|
69
|
+
returning: false,
|
|
70
|
+
},
|
|
71
|
+
})
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Related Packages
|
|
75
|
+
|
|
76
|
+
- [`data-table`](https://github.com/remix-run/remix/tree/main/packages/data-table) - Core query/relations API
|
|
77
|
+
- [`data-schema`](https://github.com/remix-run/remix/tree/main/packages/data-schema) - Schema parsing and validation
|
|
78
|
+
- [`data-table-postgres`](https://github.com/remix-run/remix/tree/main/packages/data-table-postgres) - PostgreSQL adapter
|
|
79
|
+
- [`data-table-mysql`](https://github.com/remix-run/remix/tree/main/packages/data-table-mysql) - MySQL adapter
|
|
80
|
+
|
|
81
|
+
## License
|
|
82
|
+
|
|
83
|
+
See [LICENSE](https://github.com/remix-run/remix/blob/main/LICENSE)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
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/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createSqliteDatabaseAdapter, SqliteDatabaseAdapter } from "./lib/adapter.js";
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { AdapterCapabilityOverrides, DataManipulationRequest, DataMigrationRequest, DataMigrationResult, DataMigrationOperation, DataManipulationResult, DataManipulationOperation, DatabaseAdapter, SqlStatement, TableRef, TransactionOptions, TransactionToken } from '@remix-run/data-table';
|
|
2
|
+
import type { Database as BetterSqliteDatabase } from 'better-sqlite3';
|
|
3
|
+
/**
|
|
4
|
+
* Sqlite adapter configuration.
|
|
5
|
+
*/
|
|
6
|
+
export type SqliteDatabaseAdapterOptions = {
|
|
7
|
+
capabilities?: AdapterCapabilityOverrides;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* `DatabaseAdapter` implementation for Better SQLite3.
|
|
11
|
+
*/
|
|
12
|
+
export declare class SqliteDatabaseAdapter implements DatabaseAdapter {
|
|
13
|
+
#private;
|
|
14
|
+
/**
|
|
15
|
+
* The SQL dialect identifier reported by this adapter.
|
|
16
|
+
*/
|
|
17
|
+
dialect: string;
|
|
18
|
+
/**
|
|
19
|
+
* Feature flags describing the sqlite behaviors supported by this adapter.
|
|
20
|
+
*/
|
|
21
|
+
capabilities: {
|
|
22
|
+
returning: boolean;
|
|
23
|
+
savepoints: boolean;
|
|
24
|
+
upsert: boolean;
|
|
25
|
+
transactionalDdl: boolean;
|
|
26
|
+
migrationLock: boolean;
|
|
27
|
+
};
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
100
|
+
releaseSavepoint(token: TransactionToken, name: string): Promise<void>;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Creates a sqlite `DatabaseAdapter`.
|
|
104
|
+
* @param database Better SQLite3 database instance.
|
|
105
|
+
* @param options Optional adapter capability overrides.
|
|
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
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
export declare function createSqliteDatabaseAdapter(database: BetterSqliteDatabase, options?: SqliteDatabaseAdapterOptions): SqliteDatabaseAdapter;
|
|
119
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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,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