@zmdb/mysql 1.0.0-beta.1
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 +6 -0
- package/README.md +111 -0
- package/dist/dialect.d.ts +2 -0
- package/dist/dialect.d.ts.map +1 -0
- package/dist/dialect.js +91 -0
- package/dist/dialect.js.map +1 -0
- package/dist/driver.d.ts +48 -0
- package/dist/driver.d.ts.map +1 -0
- package/dist/driver.js +125 -0
- package/dist/driver.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/introspect.d.ts +11 -0
- package/dist/introspect.d.ts.map +1 -0
- package/dist/introspect.js +306 -0
- package/dist/introspect.js.map +1 -0
- package/dist/migrations.d.ts +25 -0
- package/dist/migrations.d.ts.map +1 -0
- package/dist/migrations.js +471 -0
- package/dist/migrations.js.map +1 -0
- package/package.json +59 -0
- package/src/__fixtures__/mysql-8.4.11.json +261 -0
- package/src/dialect.ts +99 -0
- package/src/driver.ts +219 -0
- package/src/index.ts +35 -0
- package/src/introspect.ts +430 -0
- package/src/migrations.ts +637 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
|
|
3
|
+
This package is part of zmdb and is licensed under the GNU General Public
|
|
4
|
+
License, version 3 or (at your option) any later version. The complete license
|
|
5
|
+
text is distributed in the root LICENSE file of the source repository:
|
|
6
|
+
https://github.com/ambasta/zmdb/blob/main/LICENSE
|
package/README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# @zmdb/mysql
|
|
2
|
+
|
|
3
|
+
The MySQL vertical owns the immutable `mysql` dialect, its migration hooks and catalog introspector, and the `mysqlDriver` adapter. The shared query compiler comes from `@zmdb/sql`; repository and
|
|
4
|
+
driver contracts come from `@zmdb/orm`. `mysqlVertical` pairs this dialect with its driver factory.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
yarn add @zmdb/mysql@1.0.0-beta.1 @zmdb/sql@1.0.0-beta.1 @zmdb/migrations@1.0.0-beta.1 mysql2@^3.24.3
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
For the TypeScript snippets, install the declaration inputs used by the packed consumer:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
yarn add --dev typescript@7.0.2 @types/node@26.4.1
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Use Node.js 26+ and ESM. Keep the required `@zmdb/sql` and `@zmdb/orm` peers aligned with this package's version; npm resolves those peers. An application already using `zmdb` adds its selected
|
|
19
|
+
database package and client rather than replacing the product facade.
|
|
20
|
+
|
|
21
|
+
`mysql2` is an optional peer in package metadata; install it explicitly for this recipe. The vertical neither imports the SDK nor creates a pool. Applications choose pool options such as charset and
|
|
22
|
+
large-number representation.
|
|
23
|
+
|
|
24
|
+
## Configure
|
|
25
|
+
|
|
26
|
+
The snippets below are successive steps in one module.
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { createPool } from 'mysql2/promise';
|
|
30
|
+
import { mysql, mysqlDriver } from '@zmdb/mysql';
|
|
31
|
+
|
|
32
|
+
const address = process.env.DATABASE_URL;
|
|
33
|
+
if (address === undefined) throw new Error('DATABASE_URL is required');
|
|
34
|
+
const client = createPool(address);
|
|
35
|
+
const driver = mysqlDriver(client);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The application owns the client and closes it with `await client.end()` in a `finally` block after its work. Hosted services that accept this client's protocol are connection recipes, not additional
|
|
39
|
+
official database packages or automatically qualified server variants.
|
|
40
|
+
|
|
41
|
+
## Compile
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import { createQueryCompiler } from '@zmdb/sql';
|
|
45
|
+
|
|
46
|
+
const compiler = createQueryCompiler(mysql);
|
|
47
|
+
const query = compiler.selectFrom('users').where('id', '=', 7).compile();
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Compilation is pure: the result carries SQL text and a separate parameter array. It does not create the `users` table or open a connection.
|
|
51
|
+
|
|
52
|
+
## Migrate
|
|
53
|
+
|
|
54
|
+
Use `mysql.migrations.emitUp(operation)` to obtain this database's DDL and `mysql.migrations.connection(driver)` to create its migration connection. Pass reviewed migration records to `up` and `down`
|
|
55
|
+
from `@zmdb/migrations`; transactional behavior follows the capability table below. The [complete installed workflow](../../fixtures/consumer-database-publication/runtime.mjs) creates a fresh table,
|
|
56
|
+
applies and rolls back its migration, and closes the supplied client.
|
|
57
|
+
|
|
58
|
+
## Introspect
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
const snapshot = await mysql.introspector.snapshot(driver);
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
The snapshot comes from the selected database's real catalog through the same driver. `mysqlIntrospector` is also exported directly. Introspection and generated DDL use this vertical's semantics.
|
|
65
|
+
|
|
66
|
+
## Execute
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
const rows = await driver.execute(query);
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Run this after migrating or otherwise creating the table. Use `driver.transaction(async transaction => ...)` for a pinned transactional driver; the application decides whether to retry. Query values
|
|
73
|
+
travel as parameters, not SQL string interpolation.
|
|
74
|
+
|
|
75
|
+
## Capabilities
|
|
76
|
+
|
|
77
|
+
These entries describe `mysql.capabilities`; a true entry can still require the client support described below.
|
|
78
|
+
|
|
79
|
+
| Capability | Advertised support |
|
|
80
|
+
| ------------------------------------- | ------------------ |
|
|
81
|
+
| INSERT/upsert/UPDATE/DELETE returning | no |
|
|
82
|
+
| Transactional DDL | no |
|
|
83
|
+
| Schemas | yes |
|
|
84
|
+
| Sequences | no |
|
|
85
|
+
| Generated columns | yes |
|
|
86
|
+
| Partial indexes | no |
|
|
87
|
+
| Foreign keys | yes |
|
|
88
|
+
| Row-level security | no |
|
|
89
|
+
| Streaming | no |
|
|
90
|
+
| Server-side cancellation | no |
|
|
91
|
+
|
|
92
|
+
## Refusals and ownership
|
|
93
|
+
|
|
94
|
+
The compiler and migration hooks refuse `RETURNING`, standalone sequences, partial indexes and row-level security. DDL is not transactional. `execute` returns an empty row array for commands; use the
|
|
95
|
+
public `executeResult` method when affected-row or insert-ID metadata is needed. Streaming and server-side cancellation are not advertised.
|
|
96
|
+
|
|
97
|
+
MySQL owns the parent dialect and structural mysql2 adapter. `@zmdb/singlestore` depends on its public family factories and supplies a distinct dialect, migration hooks and introspector. The parent
|
|
98
|
+
does not depend on its child, and a MySQL connection is not a SingleStore qualification.
|
|
99
|
+
|
|
100
|
+
## Testing evidence
|
|
101
|
+
|
|
102
|
+
The [database publication qualification](../../fixtures/consumer-database-publication) builds real npm archives and installs this selected package in an independent consumer. Its public workflow
|
|
103
|
+
covers strict declarations, package/client ownership, parameterized CRUD, transaction rollback, migration application/rollback and catalog introspection. The
|
|
104
|
+
[MySQL consumer](../../fixtures/database-mysql) adds the database-specific capability and refusal checks.
|
|
105
|
+
|
|
106
|
+
Issue [#676](https://github.com/ambasta/zmdb/issues/676) records the completed installed workflows. Those observations are scoped to their recorded clients and servers; they do not certify every
|
|
107
|
+
compatible hosted service. Qualification reports identify their source, archive and server inputs. See the [MySQL guide](../../docs-site/content/dialect-mysql.md) for the detailed contract.
|
|
108
|
+
|
|
109
|
+
## License
|
|
110
|
+
|
|
111
|
+
GNU General Public License v3.0 or later (GPL-3.0-or-later) — see [LICENSE](./LICENSE).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialect.d.ts","sourceRoot":"","sources":["../src/dialect.ts"],"names":[],"mappings":"AAmFA,eAAO,MAAM,KAAK,yCAehB,CAAC"}
|
package/dist/dialect.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { defineSqlDialect, } from '@zmdb/sql';
|
|
2
|
+
import { mysqlIntrospector } from './introspect.js';
|
|
3
|
+
import { createMysqlMigrations } from './migrations.js';
|
|
4
|
+
const OPERATOR_TOKEN = /^(?!.*--)[A-Za-z@<>=!~*&|?-]{1,4}$/;
|
|
5
|
+
function acceptsOperator(operator) {
|
|
6
|
+
if (operator === '#>' || operator === '#>>')
|
|
7
|
+
return false;
|
|
8
|
+
return OPERATOR_TOKEN.test(operator) && !operator.includes('?');
|
|
9
|
+
}
|
|
10
|
+
function paginate({ limit, offset }) {
|
|
11
|
+
if (limit === undefined && offset !== undefined) {
|
|
12
|
+
return ` LIMIT 18446744073709551615 OFFSET ${String(offset)}`;
|
|
13
|
+
}
|
|
14
|
+
let text = '';
|
|
15
|
+
if (limit !== undefined)
|
|
16
|
+
text += ` LIMIT ${String(limit)}`;
|
|
17
|
+
if (offset !== undefined)
|
|
18
|
+
text += ` OFFSET ${String(offset)}`;
|
|
19
|
+
return text;
|
|
20
|
+
}
|
|
21
|
+
const traits = {
|
|
22
|
+
placeholder: 'positional',
|
|
23
|
+
quote: Object.freeze(['`', '`']),
|
|
24
|
+
paginate,
|
|
25
|
+
paginationRequiresOrder: false,
|
|
26
|
+
rowValueIn: true,
|
|
27
|
+
returning: Object.freeze({
|
|
28
|
+
insert: 'none',
|
|
29
|
+
upsert: 'none',
|
|
30
|
+
update: 'none',
|
|
31
|
+
delete: 'none',
|
|
32
|
+
}),
|
|
33
|
+
upsert: 'onDuplicateKey',
|
|
34
|
+
fts: 'match',
|
|
35
|
+
concat: 'function',
|
|
36
|
+
booleanNot: 'not',
|
|
37
|
+
types: Object.freeze({
|
|
38
|
+
serial: 'INT AUTO_INCREMENT',
|
|
39
|
+
integer: 'INT',
|
|
40
|
+
bigint: 'BIGINT',
|
|
41
|
+
numeric: 'DECIMAL',
|
|
42
|
+
text: 'TEXT',
|
|
43
|
+
varchar: 'VARCHAR',
|
|
44
|
+
boolean: 'TINYINT(1)',
|
|
45
|
+
timestamp: 'DATETIME(3)',
|
|
46
|
+
json: 'JSON',
|
|
47
|
+
jsonEnum: 'TEXT',
|
|
48
|
+
}),
|
|
49
|
+
paramLimit: 60000,
|
|
50
|
+
retryableCodes: Object.freeze([]),
|
|
51
|
+
acceptsOperator,
|
|
52
|
+
functions: true,
|
|
53
|
+
procedures: true,
|
|
54
|
+
tableFunctions: false,
|
|
55
|
+
vectorDistance: false,
|
|
56
|
+
spatialPredicates: false,
|
|
57
|
+
};
|
|
58
|
+
const capabilities = {
|
|
59
|
+
returning: Object.freeze({
|
|
60
|
+
insert: false,
|
|
61
|
+
upsert: false,
|
|
62
|
+
update: false,
|
|
63
|
+
delete: false,
|
|
64
|
+
}),
|
|
65
|
+
transactionalDdl: false,
|
|
66
|
+
schemas: true,
|
|
67
|
+
sequences: false,
|
|
68
|
+
generatedColumns: true,
|
|
69
|
+
partialIndexes: false,
|
|
70
|
+
foreignKeys: true,
|
|
71
|
+
rowLevelSecurity: false,
|
|
72
|
+
streaming: false,
|
|
73
|
+
cancellation: false,
|
|
74
|
+
};
|
|
75
|
+
export const mysql = defineSqlDialect({
|
|
76
|
+
name: 'mysql',
|
|
77
|
+
family: 'mysql',
|
|
78
|
+
telemetrySystem: 'mysql',
|
|
79
|
+
traits,
|
|
80
|
+
capabilities,
|
|
81
|
+
migrations: createMysqlMigrations('mysql'),
|
|
82
|
+
introspector: mysqlIntrospector,
|
|
83
|
+
outbox: Object.freeze({
|
|
84
|
+
createTable: 'CREATE TABLE',
|
|
85
|
+
pendingIndex: 'full',
|
|
86
|
+
epochLiteral: "'1970-01-01 00:00:00.000'",
|
|
87
|
+
createdAtDefault: 'CURRENT_TIMESTAMP(3)',
|
|
88
|
+
boundedTextType: (length) => `VARCHAR(${String(length)})`,
|
|
89
|
+
}),
|
|
90
|
+
});
|
|
91
|
+
//# sourceMappingURL=dialect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialect.js","sourceRoot":"","sources":["../src/dialect.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,GAIjB,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE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AM;QACpB,YAAY,EAAE,2BAA2B;QACzC,gBAAgB,EAAE,sBAAsB;QACxC,eAAe,EAAE,CAAC,MAAc,EAAE,EAAE,CAAC,WAAW,MAAM,CAAC,MAAM,CAAC,GAAG;KAClE,CAAC;CACH,CAAC,CAAC"}
|
package/dist/driver.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type ExecuteOptions, type TransactionalDriver } from '@zmdb/orm';
|
|
2
|
+
import { type CompiledQuery, type SqlDialect } from '@zmdb/sql';
|
|
3
|
+
export interface MysqlResultHeader {
|
|
4
|
+
readonly affectedRows: number;
|
|
5
|
+
readonly insertId: number | string | bigint;
|
|
6
|
+
readonly warningStatus?: number;
|
|
7
|
+
}
|
|
8
|
+
export type MysqlQueryResult = readonly Readonly<Record<string, unknown>>[] | MysqlResultHeader;
|
|
9
|
+
export type MysqlParameter = string | number | bigint | boolean | Date | null | Uint8Array | MysqlParameter[] | {
|
|
10
|
+
readonly [key: string]: MysqlParameter;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* The mysql2/promise surface used by the adapter. It is deliberately structural:
|
|
14
|
+
* importing @zmdb/mysql does not resolve or load mysql2.
|
|
15
|
+
*/
|
|
16
|
+
export interface MysqlQueryable {
|
|
17
|
+
execute(sql: string, values?: MysqlParameter[]): Promise<readonly [unknown, readonly unknown[]]>;
|
|
18
|
+
/** Optional mysql2 text protocol for metadata statements that the prepared protocol rejects. */
|
|
19
|
+
query?(sql: string, values?: MysqlParameter[]): Promise<readonly [unknown, readonly unknown[]]>;
|
|
20
|
+
}
|
|
21
|
+
export interface MysqlConnection extends MysqlQueryable {
|
|
22
|
+
beginTransaction(): Promise<unknown>;
|
|
23
|
+
commit(): Promise<unknown>;
|
|
24
|
+
rollback(): Promise<unknown>;
|
|
25
|
+
release?(): void;
|
|
26
|
+
}
|
|
27
|
+
export interface MysqlPool extends MysqlQueryable {
|
|
28
|
+
getConnection(): Promise<MysqlConnection>;
|
|
29
|
+
}
|
|
30
|
+
export interface MysqlOptions {
|
|
31
|
+
/** Optional application-to-wire conversion applied before mysql2 receives a value. */
|
|
32
|
+
readonly mapParameter?: (value: unknown, index: number) => MysqlParameter;
|
|
33
|
+
}
|
|
34
|
+
export type MysqlExecutionResult = {
|
|
35
|
+
readonly kind: 'rows';
|
|
36
|
+
readonly rows: readonly Readonly<Record<string, unknown>>[];
|
|
37
|
+
} | {
|
|
38
|
+
readonly kind: 'command';
|
|
39
|
+
readonly affectedRows: number;
|
|
40
|
+
readonly insertId: number | string | bigint;
|
|
41
|
+
readonly warningStatus?: number;
|
|
42
|
+
};
|
|
43
|
+
export interface MysqlDriver<Name extends string = 'mysql'> extends TransactionalDriver<Name> {
|
|
44
|
+
readonly dialect: SqlDialect<Name>;
|
|
45
|
+
executeResult(query: CompiledQuery, options?: ExecuteOptions): Promise<MysqlExecutionResult>;
|
|
46
|
+
}
|
|
47
|
+
export declare function mysqlFamilyDriver<Name extends string>(dialect: SqlDialect<Name>, client: MysqlQueryable, options?: MysqlOptions): MysqlDriver<Name>;
|
|
48
|
+
//# sourceMappingURL=driver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"driver.d.ts","sourceRoot":"","sources":["../src/driver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAuB,KAAK,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAC/F,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AAEhE,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IAC5C,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;CACjC;AAED,MAAM,MAAM,gBAAgB,GAAG,SAAS,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,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,CAAC;CAC7D,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IAC5C,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;CACjC,CAAC;AAEN,MAAM,WAAW,WAAW,CAAC,IAAI,SAAS,MAAM,GAAG,OAAO,CAAE,SAAQ,mBAAmB,CAAC,IAAI,CAAC;IAC3F,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;IACnC,aAAa,CAAC,KAAK,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;CAC9F;AAqJD,wBAAgB,iBAAiB,CAAC,IAAI,SAAS,MAAM,EACnD,OAAO,EAAE,UAAU,CAAC,IAAI,CAAC,EACzB,MAAM,EAAE,cAAc,EACtB,OAAO,CAAC,EAAE,YAAY,GACrB,WAAW,CAAC,IAAI,CAAC,CAEnB"}
|
package/dist/driver.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import {} from '@zmdb/orm';
|
|
2
|
+
import {} from '@zmdb/sql';
|
|
3
|
+
function isPool(client) {
|
|
4
|
+
return typeof Reflect.get(client, 'getConnection') === 'function';
|
|
5
|
+
}
|
|
6
|
+
function isConnection(client) {
|
|
7
|
+
return (typeof Reflect.get(client, 'beginTransaction') === 'function' &&
|
|
8
|
+
typeof Reflect.get(client, 'commit') === 'function' &&
|
|
9
|
+
typeof Reflect.get(client, 'rollback') === 'function');
|
|
10
|
+
}
|
|
11
|
+
function resultHeader(value) {
|
|
12
|
+
if (value === null || typeof value !== 'object') {
|
|
13
|
+
throw new TypeError('mysql2 returned neither rows nor a result header');
|
|
14
|
+
}
|
|
15
|
+
const affectedRows = Reflect.get(value, 'affectedRows');
|
|
16
|
+
const insertId = Reflect.get(value, 'insertId');
|
|
17
|
+
const warningStatus = Reflect.get(value, 'warningStatus');
|
|
18
|
+
if (typeof affectedRows !== 'number' || !Number.isSafeInteger(affectedRows) || affectedRows < 0) {
|
|
19
|
+
throw new TypeError('mysql2 result header affectedRows must be a non-negative safe integer');
|
|
20
|
+
}
|
|
21
|
+
if ((typeof insertId !== 'number' || !Number.isSafeInteger(insertId)) &&
|
|
22
|
+
typeof insertId !== 'string' &&
|
|
23
|
+
typeof insertId !== 'bigint') {
|
|
24
|
+
throw new TypeError('mysql2 result header insertId must be a safe integer, string, or bigint');
|
|
25
|
+
}
|
|
26
|
+
if (warningStatus !== undefined &&
|
|
27
|
+
(typeof warningStatus !== 'number' || !Number.isSafeInteger(warningStatus) || warningStatus < 0)) {
|
|
28
|
+
throw new TypeError('mysql2 result header warningStatus must be a non-negative safe integer');
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
affectedRows,
|
|
32
|
+
insertId,
|
|
33
|
+
...(warningStatus === undefined ? {} : { warningStatus }),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function isPlainRecord(value) {
|
|
37
|
+
const prototype = Object.getPrototypeOf(value);
|
|
38
|
+
return prototype === Object.prototype || prototype === null;
|
|
39
|
+
}
|
|
40
|
+
function mysqlParameter(value, label) {
|
|
41
|
+
if (value === null ||
|
|
42
|
+
typeof value === 'string' ||
|
|
43
|
+
typeof value === 'number' ||
|
|
44
|
+
typeof value === 'bigint' ||
|
|
45
|
+
typeof value === 'boolean' ||
|
|
46
|
+
value instanceof Date ||
|
|
47
|
+
value instanceof Uint8Array) {
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
if (Array.isArray(value)) {
|
|
51
|
+
return value.map((entry, index) => mysqlParameter(entry, `${label}[${String(index)}]`));
|
|
52
|
+
}
|
|
53
|
+
if (typeof value === 'object' && isPlainRecord(value)) {
|
|
54
|
+
return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, mysqlParameter(entry, `${label}.${key}`)]));
|
|
55
|
+
}
|
|
56
|
+
throw new TypeError(`${label} is not a mysql2 execute parameter`);
|
|
57
|
+
}
|
|
58
|
+
function mapParameters(query, options) {
|
|
59
|
+
const map = options?.mapParameter;
|
|
60
|
+
return query.parameters.map((value, index) => map === undefined ? mysqlParameter(value, `query parameter ${String(index + 1)}`) : map(value, index));
|
|
61
|
+
}
|
|
62
|
+
async function runTransaction(dialect, connection, options, run) {
|
|
63
|
+
await connection.beginTransaction();
|
|
64
|
+
const transactionDriver = createMysqlDriver(dialect, connection, options, true);
|
|
65
|
+
try {
|
|
66
|
+
const result = await run(transactionDriver);
|
|
67
|
+
await connection.commit();
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
await connection.rollback();
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function createMysqlDriver(dialect, client, options, pinned) {
|
|
76
|
+
const driver = {
|
|
77
|
+
dialect,
|
|
78
|
+
async executeResult(query, executeOptions) {
|
|
79
|
+
const signal = executeOptions?.signal;
|
|
80
|
+
signal?.throwIfAborted();
|
|
81
|
+
const parameters = mapParameters(query, options);
|
|
82
|
+
const textQuery = /^\s*(?:SHOW|DESCRIBE)\b/iu.test(query.text) ? client.query : undefined;
|
|
83
|
+
const [result] = textQuery === undefined
|
|
84
|
+
? await client.execute(query.text, parameters)
|
|
85
|
+
: await textQuery.call(client, query.text, parameters);
|
|
86
|
+
signal?.throwIfAborted();
|
|
87
|
+
if (Array.isArray(result)) {
|
|
88
|
+
if (result.some(row => row === null || typeof row !== 'object' || Array.isArray(row))) {
|
|
89
|
+
throw new TypeError('mysql2 row results must contain objects');
|
|
90
|
+
}
|
|
91
|
+
return { kind: 'rows', rows: result };
|
|
92
|
+
}
|
|
93
|
+
return { kind: 'command', ...resultHeader(result) };
|
|
94
|
+
},
|
|
95
|
+
async execute(query, executeOptions) {
|
|
96
|
+
const result = await driver.executeResult(query, executeOptions);
|
|
97
|
+
return result.kind === 'rows' ? result.rows : [];
|
|
98
|
+
},
|
|
99
|
+
async transaction(run) {
|
|
100
|
+
if (pinned) {
|
|
101
|
+
if (!isConnection(client))
|
|
102
|
+
throw new TypeError('a pinned mysql transaction lost its connection');
|
|
103
|
+
return runTransaction(dialect, client, options, run);
|
|
104
|
+
}
|
|
105
|
+
if (isPool(client)) {
|
|
106
|
+
const connection = await client.getConnection();
|
|
107
|
+
try {
|
|
108
|
+
return await runTransaction(dialect, connection, options, run);
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
connection.release?.();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (!isConnection(client)) {
|
|
115
|
+
throw new TypeError('mysqlDriver.transaction requires a mysql2 pool or connection');
|
|
116
|
+
}
|
|
117
|
+
return runTransaction(dialect, client, options, run);
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
return driver;
|
|
121
|
+
}
|
|
122
|
+
export function mysqlFamilyDriver(dialect, client, options) {
|
|
123
|
+
return createMysqlDriver(dialect, client, options, false);
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=driver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"driver.js","sourceRoot":"","sources":["../src/driver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsE,MAAM,WAAW,CAAC;AAC/F,OAAO,EAAuC,MAAM,WAAW,CAAC;AAgEhE,SAAS,MAAM,CAAC,MAAsB;IACpC,OAAO,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,KAAK,UAAU,CAAC;AACpE,CAAC;AAED,SAAS,YAAY,CAAC,MAAsB;IAC1C,OAAO,CACL,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,KAAK,UAAU;QAC7D,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,UAAU;QACnD,OAAO,OAAO,CAAC,GA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MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;YACvD,CAAC;YACD,IAAI,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;gBACnB,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,aAAa,EAAE,CAAC;gBAChD,IAAI,CAAC;oBACH,OAAO,MAAM,cAAc,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;gBACjE,CAAC;wBAAS,CAAC;oBACT,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC;gBACzB,CAAC;YACH,CAAC;YACD,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC1B,MAAM,IAAI,SAAS,CAAC,8DAA8D,CAAC,CAAC;YACtF,CAAC;YACD,OAAO,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;QACvD,CAAC;KACF,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,OAAyB,EACzB,MAAsB,EACtB,OAAsB;IAEtB,OAAO,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AAC5D,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type DatabaseVertical } from '@zmdb/orm';
|
|
2
|
+
import { type MysqlDriver, type MysqlOptions, type MysqlQueryable } from './driver.js';
|
|
3
|
+
export { mysql } from './dialect.js';
|
|
4
|
+
export { mysqlFamilyDriver, type MysqlConnection, type MysqlDriver, type MysqlExecutionResult, type MysqlOptions, type MysqlParameter, type MysqlPool, type MysqlQueryable, type MysqlQueryResult, type MysqlResultHeader, } from './driver.js';
|
|
5
|
+
export { mysqlFamilyIntrospector, mysqlIntrospector, mysqlSnapshot, type MysqlCatalogOverrides } from './introspect.js';
|
|
6
|
+
export { createMysqlMigrations, mysqlFamilyMigrations, type MysqlMigrationOverrides, type MysqlTableDdlExtension, type MysqlTableDdlHelpers, } from './migrations.js';
|
|
7
|
+
export declare function mysqlDriver(client: MysqlQueryable, options?: MysqlOptions): MysqlDriver<'mysql'>;
|
|
8
|
+
export declare const mysqlVertical: DatabaseVertical<'mysql', MysqlQueryable, MysqlOptions>;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAGlD,OAAO,EAAqB,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAE1G,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EACL,iBAAiB,EACjB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,oBAAoB,EACzB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,GACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,aAAa,EAAE,KAAK,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxH,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,GAC1B,MAAM,iBAAiB,CAAC;AAEzB,wBAAgB,WAAW,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,WAAW,CAAC,OAAO,CAAC,CAEhG;AAED,eAAO,MAAM,aAAa,EAAE,gBAAgB,CAAC,OAAO,EAAE,cAAc,EAAE,YAAY,CAGhF,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {} from '@zmdb/orm';
|
|
2
|
+
import { mysql } from './dialect.js';
|
|
3
|
+
import { mysqlFamilyDriver } from './driver.js';
|
|
4
|
+
export { mysql } from './dialect.js';
|
|
5
|
+
export { mysqlFamilyDriver, } from './driver.js';
|
|
6
|
+
export { mysqlFamilyIntrospector, mysqlIntrospector, mysqlSnapshot } from './introspect.js';
|
|
7
|
+
export { createMysqlMigrations, mysqlFamilyMigrations, } from './migrations.js';
|
|
8
|
+
export function mysqlDriver(client, options) {
|
|
9
|
+
return mysqlFamilyDriver(mysql, client, options);
|
|
10
|
+
}
|
|
11
|
+
export const mysqlVertical = Object.freeze({
|
|
12
|
+
dialect: mysql,
|
|
13
|
+
driver: mysqlDriver,
|
|
14
|
+
});
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,MAAM,WAAW,CAAC;AAElD,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,iBAAiB,EAA4D,MAAM,aAAa,CAAC;AAE1G,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EACL,iBAAiB,GAUlB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,aAAa,EAA8B,MAAM,iBAAiB,CAAC;AACxH,OAAO,EACL,qBAAqB,EACrB,qBAAqB,GAItB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,UAAU,WAAW,CAAC,MAAsB,EAAE,OAAsB;IACxE,OAAO,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,CAAC,MAAM,aAAa,GAA4D,MAAM,CAAC,MAAM,CAAC;IAClG,OAAO,EAAE,KAAK;IACd,MAAM,EAAE,WAAW;CACpB,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SchemaSnapshot } from '@zmdb/migrations';
|
|
2
|
+
import { type CatalogSchemaSnapshot } from '@zmdb/migrations/introspect/runtime';
|
|
3
|
+
import { type IntrospectionDriver, type Introspector, type IntrospectOptions } from '@zmdb/sql';
|
|
4
|
+
export interface MysqlCatalogOverrides {
|
|
5
|
+
readonly snapshot?: (driver: IntrospectionDriver, options: IntrospectOptions, parent: (driver: IntrospectionDriver, options?: IntrospectOptions) => Promise<CatalogSchemaSnapshot>) => Promise<CatalogSchemaSnapshot>;
|
|
6
|
+
readonly normalizeForDrift?: (snapshot: SchemaSnapshot, role: 'live' | 'declared', parent: (snapshot: SchemaSnapshot, role: 'live' | 'declared') => SchemaSnapshot) => SchemaSnapshot;
|
|
7
|
+
}
|
|
8
|
+
export declare function mysqlSnapshot(driver: IntrospectionDriver, options?: IntrospectOptions): Promise<CatalogSchemaSnapshot>;
|
|
9
|
+
export declare function mysqlFamilyIntrospector<Name extends string>(name: Name, overrides?: MysqlCatalogOverrides): Introspector<Name>;
|
|
10
|
+
export declare const mysqlIntrospector: Introspector<'mysql'>;
|
|
11
|
+
//# sourceMappingURL=introspect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"introspect.d.ts","sourceRoot":"","sources":["../src/introspect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAiBL,KAAK,qBAAqB,EAG3B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,KAAK,mBAAmB,EAAE,KAAK,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAyChG,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAClB,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,iBAAiB,EAC1B,MAAM,EAAE,CAAC,MAAM,EAAE,mBAAmB,EAAE,OAAO,CAAC,EAAE,iBAAiB,KAAK,OAAO,CAAC,qBAAqB,CAAC,KACjG,OAAO,CAAC,qBAAqB,CAAC,CAAC;IACpC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,CAC3B,QAAQ,EAAE,cAAc,EACxB,IAAI,EAAE,MAAM,GAAG,UAAU,EACzB,MAAM,EAAE,CAAC,QAAQ,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,KAAK,cAAc,KAC5E,cAAc,CAAC;CACrB;AA2ND,wBAAsB,aAAa,CACjC,MAAM,EAAE,mBAAmB,EAC3B,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,qBAAqB,CAAC,CA+GhC;AAMD,wBAAgB,uBAAuB,CAAC,IAAI,SAAS,MAAM,EACzD,IAAI,EAAE,IAAI,EACV,SAAS,GAAE,qBAA0B,GACpC,YAAY,CAAC,IAAI,CAAC,CAWpB;AAED,eAAO,MAAM,iBAAiB,EAAE,YAAY,CAAC,OAAO,CAAoC,CAAC"}
|