@remix-run/data-table-mysql 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 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,97 @@
1
- # Placeholder package
1
+ # data-table-mysql
2
2
 
3
- This package is intentionally empty and published only as a temporary placeholder.
3
+ MySQL 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 `mysql2`.
5
+
6
+ ## Features
7
+
8
+ - **Native `mysql2` Integration**: Works with `mysql2/promise` `Pool` and `PoolConnection` instances
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
+ - **MySQL Capabilities Enabled By Default**:
13
+ - `returning: false`
14
+ - `savepoints: true`
15
+ - `upsert: true`
16
+ - `transactionalDdl: false`
17
+ - `migrationLock: true`
18
+
19
+ ## Installation
20
+
21
+ ```sh
22
+ npm i remix mysql2
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ```ts
28
+ import { createPool } from 'mysql2/promise'
29
+ import { createDatabase } from 'remix/data-table'
30
+ import { createMysqlDatabaseAdapter } from 'remix/data-table-mysql'
31
+
32
+ let pool = createPool(process.env.DATABASE_URL as string)
33
+ let db = createDatabase(createMysqlDatabaseAdapter(pool))
34
+ ```
35
+
36
+ Use `db.query(...)`, relation loading, and transactions from `remix/data-table`.
37
+ Import any driver-specific types you need directly from `mysql2/promise`.
38
+
39
+ ## Adapter Capabilities
40
+
41
+ `data-table-mysql` reports this capability set by default:
42
+
43
+ - `returning: false`
44
+ - `savepoints: true`
45
+ - `upsert: true`
46
+ - `transactionalDdl: false`
47
+ - `migrationLock: true`
48
+
49
+ ## Advanced Usage
50
+
51
+ ### Capability Overrides For Testing
52
+
53
+ Capability overrides are mainly for tests where you want to force or disable specific behavior
54
+ checks. In production, keep defaults so adapter behavior matches MySQL behavior.
55
+
56
+ ```ts
57
+ import { createMysqlDatabaseAdapter } from 'remix/data-table-mysql'
58
+
59
+ let adapter = createMysqlDatabaseAdapter(pool, {
60
+ capabilities: {
61
+ upsert: false,
62
+ },
63
+ })
64
+ ```
65
+
66
+ ### `returning` On MySQL
67
+
68
+ MySQL does not natively support SQL `RETURNING`. In this adapter, using `returning` on write
69
+ operations throws `DataTableQueryError`.
70
+
71
+ Use write metadata (`affectedRows`, `insertId`) on MySQL, or switch adapters when returned rows
72
+ are required.
73
+
74
+ ```ts
75
+ import { DataTableQueryError } from 'remix/data-table'
76
+
77
+ try {
78
+ await db
79
+ .query(Accounts)
80
+ .insert({ email: 'a@example.com', status: 'active' }, { returning: ['id'] })
81
+ } catch (error) {
82
+ if (error instanceof DataTableQueryError) {
83
+ // insert() returning is not supported by this adapter
84
+ }
85
+ }
86
+ ```
87
+
88
+ ## Related Packages
89
+
90
+ - [`data-table`](https://github.com/remix-run/remix/tree/main/packages/data-table) - Core query/relations API
91
+ - [`data-schema`](https://github.com/remix-run/remix/tree/main/packages/data-schema) - Schema parsing and validation
92
+ - [`data-table-postgres`](https://github.com/remix-run/remix/tree/main/packages/data-table-postgres) - PostgreSQL adapter
93
+ - [`data-table-sqlite`](https://github.com/remix-run/remix/tree/main/packages/data-table-sqlite) - SQLite adapter
94
+
95
+ ## License
96
+
97
+ See [LICENSE](https://github.com/remix-run/remix/blob/main/LICENSE)
@@ -0,0 +1,3 @@
1
+ export type { MysqlDatabaseAdapterOptions } from './lib/adapter.ts';
2
+ export { createMysqlDatabaseAdapter, MysqlDatabaseAdapter } from './lib/adapter.ts';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAA;AACnE,OAAO,EAAE,0BAA0B,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export { createMysqlDatabaseAdapter, MysqlDatabaseAdapter } from "./lib/adapter.js";
@@ -0,0 +1,132 @@
1
+ import type { AdapterCapabilityOverrides, 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
+ /**
4
+ * Mysql adapter configuration.
5
+ */
6
+ export type MysqlDatabaseAdapterOptions = {
7
+ capabilities?: AdapterCapabilityOverrides;
8
+ };
9
+ type MysqlTransactionConnection = MysqlConnection | MysqlPoolConnection;
10
+ type MysqlQueryable = MysqlPool | MysqlTransactionConnection;
11
+ /**
12
+ * `DatabaseAdapter` implementation for mysql-compatible clients.
13
+ */
14
+ export declare class MysqlDatabaseAdapter implements DatabaseAdapter {
15
+ #private;
16
+ /**
17
+ * The SQL dialect identifier reported by this adapter.
18
+ */
19
+ dialect: string;
20
+ /**
21
+ * Feature flags describing the mysql behaviors supported by this adapter.
22
+ */
23
+ capabilities: {
24
+ returning: boolean;
25
+ savepoints: boolean;
26
+ upsert: boolean;
27
+ transactionalDdl: boolean;
28
+ migrationLock: boolean;
29
+ };
30
+ constructor(client: MysqlQueryable, options?: MysqlDatabaseAdapterOptions);
31
+ /**
32
+ * Compiles a data or migration operation to mysql SQL statements.
33
+ * @param operation Operation to compile.
34
+ * @returns Compiled SQL statements.
35
+ */
36
+ compileSql(operation: DataManipulationOperation | DataMigrationOperation): SqlStatement[];
37
+ /**
38
+ * Executes a mysql data-manipulation request.
39
+ * @param request Request to execute.
40
+ * @returns Execution result.
41
+ */
42
+ execute(request: DataManipulationRequest): Promise<DataManipulationResult>;
43
+ /**
44
+ * Executes mysql migration operations.
45
+ * @param request Migration request to execute.
46
+ * @returns Migration result.
47
+ */
48
+ migrate(request: DataMigrationRequest): Promise<DataMigrationResult>;
49
+ /**
50
+ * Checks whether a table exists in mysql.
51
+ * @param table Table reference to inspect.
52
+ * @param transaction Optional transaction token.
53
+ * @returns `true` when the table exists.
54
+ */
55
+ hasTable(table: TableRef, transaction?: TransactionToken): Promise<boolean>;
56
+ /**
57
+ * Checks whether a column exists in mysql.
58
+ * @param table Table reference to inspect.
59
+ * @param column Column name to look up.
60
+ * @param transaction Optional transaction token.
61
+ * @returns `true` when the column exists.
62
+ */
63
+ hasColumn(table: TableRef, column: string, transaction?: TransactionToken): Promise<boolean>;
64
+ /**
65
+ * Starts a mysql transaction.
66
+ * @param options Transaction options.
67
+ * @returns Transaction token.
68
+ */
69
+ beginTransaction(options?: TransactionOptions): Promise<TransactionToken>;
70
+ /**
71
+ * Commits an open mysql transaction.
72
+ * @param token Transaction token to commit.
73
+ * @returns A promise that resolves when the transaction is committed.
74
+ */
75
+ commitTransaction(token: TransactionToken): Promise<void>;
76
+ /**
77
+ * Rolls back an open mysql transaction.
78
+ * @param token Transaction token to roll back.
79
+ * @returns A promise that resolves when the transaction is rolled back.
80
+ */
81
+ rollbackTransaction(token: TransactionToken): Promise<void>;
82
+ /**
83
+ * Creates a savepoint in an open mysql transaction.
84
+ * @param token Transaction token to use.
85
+ * @param name Savepoint name.
86
+ * @returns A promise that resolves when the savepoint is created.
87
+ */
88
+ createSavepoint(token: TransactionToken, name: string): Promise<void>;
89
+ /**
90
+ * Rolls back to a savepoint in an open mysql transaction.
91
+ * @param token Transaction token to use.
92
+ * @param name Savepoint name.
93
+ * @returns A promise that resolves when the rollback completes.
94
+ */
95
+ rollbackToSavepoint(token: TransactionToken, name: string): Promise<void>;
96
+ /**
97
+ * Releases a savepoint in an open mysql transaction.
98
+ * @param token Transaction token to use.
99
+ * @param name Savepoint name.
100
+ * @returns A promise that resolves when the savepoint is released.
101
+ */
102
+ releaseSavepoint(token: TransactionToken, name: string): Promise<void>;
103
+ /**
104
+ * Acquires the mysql migration lock.
105
+ * @returns A promise that resolves when the lock is acquired.
106
+ */
107
+ acquireMigrationLock(): Promise<void>;
108
+ /**
109
+ * Releases the mysql migration lock.
110
+ * @returns A promise that resolves when the lock is released.
111
+ */
112
+ releaseMigrationLock(): Promise<void>;
113
+ }
114
+ /**
115
+ * Creates a mysql `DatabaseAdapter`.
116
+ * @param client Mysql pool or connection.
117
+ * @param options Optional adapter capability overrides.
118
+ * @returns A configured mysql adapter.
119
+ * @example
120
+ * ```ts
121
+ * import { createPool } from 'mysql2/promise'
122
+ * import { createDatabase } from 'remix/data-table'
123
+ * import { createMysqlDatabaseAdapter } from 'remix/data-table-mysql'
124
+ *
125
+ * let pool = createPool({ uri: process.env.DATABASE_URL })
126
+ * let adapter = createMysqlDatabaseAdapter(pool)
127
+ * let db = createDatabase(adapter)
128
+ * ```
129
+ */
130
+ export declare function createMysqlDatabaseAdapter(client: MysqlQueryable, options?: MysqlDatabaseAdapterOptions): MysqlDatabaseAdapter;
131
+ export {};
132
+ //# 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,EACV,UAAU,IAAI,eAAe,EAC7B,IAAI,IAAI,SAAS,EACjB,cAAc,IAAI,mBAAmB,EAGtC,MAAM,gBAAgB,CAAA;AAIvB;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC,YAAY,CAAC,EAAE,0BAA0B,CAAA;CAC1C,CAAA;AAYD,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,EAAE,OAAO,CAAC,EAAE,2BAA2B,EASxE;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,CA8B/E;IAED;;;;OAIG;IACG,O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