@remix-run/data-table-mysql 0.1.0 → 0.3.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 +9 -17
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/lib/adapter.d.ts +100 -43
- package/dist/lib/adapter.d.ts.map +1 -1
- package/dist/lib/adapter.js +553 -23
- 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 +47 -77
- package/package.json +6 -7
- package/src/index.ts +0 -8
- package/src/lib/adapter.ts +686 -85
- package/src/lib/sql-compiler.ts +60 -99
package/README.md
CHANGED
|
@@ -5,12 +5,16 @@ Use this package when you want `data-table` APIs backed by `mysql2`.
|
|
|
5
5
|
|
|
6
6
|
## Features
|
|
7
7
|
|
|
8
|
-
- **Native `mysql2` Integration**: Works with `mysql2/promise`
|
|
8
|
+
- **Native `mysql2` Integration**: Works with `mysql2/promise` `Pool` and `PoolConnection` instances
|
|
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
|
- **MySQL Capabilities Enabled By Default**:
|
|
11
13
|
- `returning: false`
|
|
12
14
|
- `savepoints: true`
|
|
13
15
|
- `upsert: true`
|
|
16
|
+
- `transactionalDdl: false`
|
|
17
|
+
- `migrationLock: true`
|
|
14
18
|
|
|
15
19
|
## Installation
|
|
16
20
|
|
|
@@ -30,6 +34,7 @@ let db = createDatabase(createMysqlDatabaseAdapter(pool))
|
|
|
30
34
|
```
|
|
31
35
|
|
|
32
36
|
Use `db.query(...)`, relation loading, and transactions from `remix/data-table`.
|
|
37
|
+
Import any driver-specific types you need directly from `mysql2/promise`.
|
|
33
38
|
|
|
34
39
|
## Adapter Capabilities
|
|
35
40
|
|
|
@@ -38,24 +43,11 @@ Use `db.query(...)`, relation loading, and transactions from `remix/data-table`.
|
|
|
38
43
|
- `returning: false`
|
|
39
44
|
- `savepoints: true`
|
|
40
45
|
- `upsert: true`
|
|
46
|
+
- `transactionalDdl: false`
|
|
47
|
+
- `migrationLock: true`
|
|
41
48
|
|
|
42
49
|
## Advanced Usage
|
|
43
50
|
|
|
44
|
-
### Capability Overrides For Testing
|
|
45
|
-
|
|
46
|
-
Capability overrides are mainly for tests where you want to force or disable specific behavior
|
|
47
|
-
checks. In production, keep defaults so adapter behavior matches MySQL behavior.
|
|
48
|
-
|
|
49
|
-
```ts
|
|
50
|
-
import { createMysqlDatabaseAdapter } from 'remix/data-table-mysql'
|
|
51
|
-
|
|
52
|
-
let adapter = createMysqlDatabaseAdapter(pool, {
|
|
53
|
-
capabilities: {
|
|
54
|
-
upsert: false,
|
|
55
|
-
},
|
|
56
|
-
})
|
|
57
|
-
```
|
|
58
|
-
|
|
59
51
|
### `returning` On MySQL
|
|
60
52
|
|
|
61
53
|
MySQL does not natively support SQL `RETURNING`. In this adapter, using `returning` on write
|
|
@@ -81,7 +73,7 @@ try {
|
|
|
81
73
|
## Related Packages
|
|
82
74
|
|
|
83
75
|
- [`data-table`](https://github.com/remix-run/remix/tree/main/packages/data-table) - Core query/relations API
|
|
84
|
-
- [`data-schema`](https://github.com/remix-run/remix/tree/main/packages/data-schema) - Schema
|
|
76
|
+
- [`data-schema`](https://github.com/remix-run/remix/tree/main/packages/data-schema) - Schema parsing and validation
|
|
85
77
|
- [`data-table-postgres`](https://github.com/remix-run/remix/tree/main/packages/data-table-postgres) - PostgreSQL adapter
|
|
86
78
|
- [`data-table-sqlite`](https://github.com/remix-run/remix/tree/main/packages/data-table-sqlite) - SQLite adapter
|
|
87
79
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export type { MysqlDatabaseAdapterOptions, MysqlDatabaseConnection, MysqlDatabasePool, MysqlQueryResponse, MysqlQueryResultHeader, MysqlQueryRows, } from './lib/adapter.ts';
|
|
2
1
|
export { createMysqlDatabaseAdapter, MysqlDatabaseAdapter } from './lib/adapter.ts';
|
|
3
2
|
//# 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,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA"}
|
package/dist/lib/adapter.d.ts
CHANGED
|
@@ -1,69 +1,126 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export type MysqlQueryRows = Record<string, unknown>[];
|
|
6
|
-
/**
|
|
7
|
-
* Metadata shape for mysql write results.
|
|
8
|
-
*/
|
|
9
|
-
export type MysqlQueryResultHeader = {
|
|
10
|
-
affectedRows: number;
|
|
11
|
-
insertId: unknown;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Supported mysql `query()` response tuple.
|
|
15
|
-
*/
|
|
16
|
-
export type MysqlQueryResponse = [result: unknown, fields?: unknown];
|
|
17
|
-
/**
|
|
18
|
-
* Single mysql connection contract used by this adapter.
|
|
19
|
-
*/
|
|
20
|
-
export type MysqlDatabaseConnection = {
|
|
21
|
-
query(text: string, values?: unknown[]): Promise<MysqlQueryResponse>;
|
|
22
|
-
beginTransaction(): Promise<void>;
|
|
23
|
-
commit(): Promise<void>;
|
|
24
|
-
rollback(): Promise<void>;
|
|
25
|
-
release?: () => void;
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Mysql pool contract used by this adapter.
|
|
29
|
-
*/
|
|
30
|
-
export type MysqlDatabasePool = {
|
|
31
|
-
query(text: string, values?: unknown[]): Promise<MysqlQueryResponse>;
|
|
32
|
-
getConnection(): Promise<MysqlDatabaseConnection>;
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* Mysql adapter configuration.
|
|
36
|
-
*/
|
|
37
|
-
export type MysqlDatabaseAdapterOptions = {
|
|
38
|
-
capabilities?: AdapterCapabilityOverrides;
|
|
39
|
-
};
|
|
40
|
-
type MysqlQueryable = MysqlDatabasePool | MysqlDatabaseConnection;
|
|
1
|
+
import type { DataManipulationRequest, DataMigrationRequest, DataMigrationResult, DataMigrationOperation, DataManipulationResult, DataManipulationOperation, DatabaseAdapter, SqlStatement, TableRef, TransactionOptions, TransactionToken } from '@remix-run/data-table';
|
|
2
|
+
import type { Connection as MysqlConnection, Pool as MysqlPool, PoolConnection as MysqlPoolConnection } from 'mysql2/promise';
|
|
3
|
+
type MysqlTransactionConnection = MysqlConnection | MysqlPoolConnection;
|
|
4
|
+
type MysqlQueryable = MysqlPool | MysqlTransactionConnection;
|
|
41
5
|
/**
|
|
42
6
|
* `DatabaseAdapter` implementation for mysql-compatible clients.
|
|
43
7
|
*/
|
|
44
8
|
export declare class MysqlDatabaseAdapter implements DatabaseAdapter {
|
|
45
9
|
#private;
|
|
10
|
+
/**
|
|
11
|
+
* The SQL dialect identifier reported by this adapter.
|
|
12
|
+
*/
|
|
46
13
|
dialect: string;
|
|
14
|
+
/**
|
|
15
|
+
* Feature flags describing the mysql behaviors supported by this adapter.
|
|
16
|
+
*/
|
|
47
17
|
capabilities: {
|
|
48
18
|
returning: boolean;
|
|
49
19
|
savepoints: boolean;
|
|
50
20
|
upsert: boolean;
|
|
21
|
+
transactionalDdl: boolean;
|
|
22
|
+
migrationLock: boolean;
|
|
51
23
|
};
|
|
52
|
-
constructor(client: MysqlQueryable
|
|
53
|
-
|
|
24
|
+
constructor(client: MysqlQueryable);
|
|
25
|
+
/**
|
|
26
|
+
* Compiles a data or migration operation to mysql SQL statements.
|
|
27
|
+
* @param operation Operation to compile.
|
|
28
|
+
* @returns Compiled SQL statements.
|
|
29
|
+
*/
|
|
30
|
+
compileSql(operation: DataManipulationOperation | DataMigrationOperation): SqlStatement[];
|
|
31
|
+
/**
|
|
32
|
+
* Executes a mysql data-manipulation request.
|
|
33
|
+
* @param request Request to execute.
|
|
34
|
+
* @returns Execution result.
|
|
35
|
+
*/
|
|
36
|
+
execute(request: DataManipulationRequest): Promise<DataManipulationResult>;
|
|
37
|
+
/**
|
|
38
|
+
* Executes mysql migration operations.
|
|
39
|
+
* @param request Migration request to execute.
|
|
40
|
+
* @returns Migration result.
|
|
41
|
+
*/
|
|
42
|
+
migrate(request: DataMigrationRequest): Promise<DataMigrationResult>;
|
|
43
|
+
/**
|
|
44
|
+
* Checks whether a table exists in mysql.
|
|
45
|
+
* @param table Table reference to inspect.
|
|
46
|
+
* @param transaction Optional transaction token.
|
|
47
|
+
* @returns `true` when the table exists.
|
|
48
|
+
*/
|
|
49
|
+
hasTable(table: TableRef, transaction?: TransactionToken): Promise<boolean>;
|
|
50
|
+
/**
|
|
51
|
+
* Checks whether a column exists in mysql.
|
|
52
|
+
* @param table Table reference to inspect.
|
|
53
|
+
* @param column Column name to look up.
|
|
54
|
+
* @param transaction Optional transaction token.
|
|
55
|
+
* @returns `true` when the column exists.
|
|
56
|
+
*/
|
|
57
|
+
hasColumn(table: TableRef, column: string, transaction?: TransactionToken): Promise<boolean>;
|
|
58
|
+
/**
|
|
59
|
+
* Starts a mysql transaction.
|
|
60
|
+
* @param options Transaction options.
|
|
61
|
+
* @returns Transaction token.
|
|
62
|
+
*/
|
|
54
63
|
beginTransaction(options?: TransactionOptions): Promise<TransactionToken>;
|
|
64
|
+
/**
|
|
65
|
+
* Commits an open mysql transaction.
|
|
66
|
+
* @param token Transaction token to commit.
|
|
67
|
+
* @returns A promise that resolves when the transaction is committed.
|
|
68
|
+
*/
|
|
55
69
|
commitTransaction(token: TransactionToken): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Rolls back an open mysql transaction.
|
|
72
|
+
* @param token Transaction token to roll back.
|
|
73
|
+
* @returns A promise that resolves when the transaction is rolled back.
|
|
74
|
+
*/
|
|
56
75
|
rollbackTransaction(token: TransactionToken): Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Creates a savepoint in an open mysql transaction.
|
|
78
|
+
* @param token Transaction token to use.
|
|
79
|
+
* @param name Savepoint name.
|
|
80
|
+
* @returns A promise that resolves when the savepoint is created.
|
|
81
|
+
*/
|
|
57
82
|
createSavepoint(token: TransactionToken, name: string): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Rolls back to a savepoint in an open mysql transaction.
|
|
85
|
+
* @param token Transaction token to use.
|
|
86
|
+
* @param name Savepoint name.
|
|
87
|
+
* @returns A promise that resolves when the rollback completes.
|
|
88
|
+
*/
|
|
58
89
|
rollbackToSavepoint(token: TransactionToken, name: string): Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Releases a savepoint in an open mysql transaction.
|
|
92
|
+
* @param token Transaction token to use.
|
|
93
|
+
* @param name Savepoint name.
|
|
94
|
+
* @returns A promise that resolves when the savepoint is released.
|
|
95
|
+
*/
|
|
59
96
|
releaseSavepoint(token: TransactionToken, name: string): Promise<void>;
|
|
97
|
+
/**
|
|
98
|
+
* Acquires the mysql migration lock.
|
|
99
|
+
* @returns A promise that resolves when the lock is acquired.
|
|
100
|
+
*/
|
|
101
|
+
acquireMigrationLock(): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Releases the mysql migration lock.
|
|
104
|
+
* @returns A promise that resolves when the lock is released.
|
|
105
|
+
*/
|
|
106
|
+
releaseMigrationLock(): Promise<void>;
|
|
60
107
|
}
|
|
61
108
|
/**
|
|
62
109
|
* Creates a mysql `DatabaseAdapter`.
|
|
63
110
|
* @param client Mysql pool or connection.
|
|
64
111
|
* @param options Optional adapter capability overrides.
|
|
65
112
|
* @returns A configured mysql adapter.
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* import { createPool } from 'mysql2/promise'
|
|
116
|
+
* import { createDatabase } from 'remix/data-table'
|
|
117
|
+
* import { createMysqlDatabaseAdapter } from 'remix/data-table-mysql'
|
|
118
|
+
*
|
|
119
|
+
* let pool = createPool({ uri: process.env.DATABASE_URL })
|
|
120
|
+
* let adapter = createMysqlDatabaseAdapter(pool)
|
|
121
|
+
* let db = createDatabase(adapter)
|
|
122
|
+
* ```
|
|
66
123
|
*/
|
|
67
|
-
export declare function createMysqlDatabaseAdapter(client: MysqlQueryable
|
|
124
|
+
export declare function createMysqlDatabaseAdapter(client: MysqlQueryable): MysqlDatabaseAdapter;
|
|
68
125
|
export {};
|
|
69
126
|
//# 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,
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/lib/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,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,EACV,UAAU,IAAI,eAAe,EAC7B,IAAI,IAAI,SAAS,EACjB,cAAc,IAAI,mBAAmB,EAGtC,MAAM,gBAAgB,CAAA;AAcvB,KAAK,0BAA0B,GAAG,eAAe,GAAG,mBAAmB,CAAA;AACvE,KAAK,cAAc,GAAG,SAAS,GAAG,0BAA0B,CAAA;AAE5D;;GAEG;AACH,qBAAa,oBAAqB,YAAW,eAAe;;IAC1D;;OAEG;IACH,OAAO,SAAU;IAEjB;;OAEG;IACH,YAAY;;;;;;MAAA;IAMZ,YAAY,MAAM,EAAE,cAAc,EASjC;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