@holo-js/db-mysql 0.1.3 → 0.1.5
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/dist/index.d.ts +3 -23
- package/dist/index.mjs +11 -14
- package/package.json +6 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,27 +1,7 @@
|
|
|
1
1
|
import { PoolOptions } from 'mysql2/promise';
|
|
2
|
+
import { DriverAdapter, DriverQueryResult, DriverExecutionResult } from '@holo-js/db';
|
|
3
|
+
export { DriverAdapter, DriverExecutionResult, DriverQueryResult } from '@holo-js/db';
|
|
2
4
|
|
|
3
|
-
interface DriverQueryResult<TRow extends Record<string, unknown> = Record<string, unknown>> {
|
|
4
|
-
rows: TRow[];
|
|
5
|
-
rowCount: number;
|
|
6
|
-
}
|
|
7
|
-
interface DriverExecutionResult {
|
|
8
|
-
affectedRows?: number;
|
|
9
|
-
lastInsertId?: number | string;
|
|
10
|
-
}
|
|
11
|
-
interface DriverAdapter {
|
|
12
|
-
initialize(): Promise<void>;
|
|
13
|
-
disconnect(): Promise<void>;
|
|
14
|
-
isConnected(): boolean;
|
|
15
|
-
runWithTransactionScope?<T>(callback: () => Promise<T>): Promise<T>;
|
|
16
|
-
query<TRow extends Record<string, unknown> = Record<string, unknown>>(sql: string, bindings?: readonly unknown[]): Promise<DriverQueryResult<TRow>>;
|
|
17
|
-
execute(sql: string, bindings?: readonly unknown[]): Promise<DriverExecutionResult>;
|
|
18
|
-
beginTransaction(): Promise<void>;
|
|
19
|
-
commit(): Promise<void>;
|
|
20
|
-
rollback(): Promise<void>;
|
|
21
|
-
createSavepoint?(name: string): Promise<void>;
|
|
22
|
-
rollbackToSavepoint?(name: string): Promise<void>;
|
|
23
|
-
releaseSavepoint?(name: string): Promise<void>;
|
|
24
|
-
}
|
|
25
5
|
interface MySQLQueryableLike {
|
|
26
6
|
query(sql: string, bindings?: readonly unknown[]): Promise<readonly [unknown, unknown]>;
|
|
27
7
|
}
|
|
@@ -72,4 +52,4 @@ declare class MySQLAdapter implements DriverAdapter {
|
|
|
72
52
|
}
|
|
73
53
|
declare function createMySQLAdapter(options?: MySQLAdapterOptions): MySQLAdapter;
|
|
74
54
|
|
|
75
|
-
export {
|
|
55
|
+
export { MySQLAdapter, type MySQLAdapterOptions, type MySQLClientLike, type MySQLPoolLike, type MySQLQueryableLike, createMySQLAdapter };
|
package/dist/index.mjs
CHANGED
|
@@ -38,8 +38,8 @@ var MySQLAdapter = class {
|
|
|
38
38
|
leasedTransactionClient = false;
|
|
39
39
|
transactionScope = new AsyncLocalStorage();
|
|
40
40
|
constructor(options = {}) {
|
|
41
|
-
this.directClient = options.client
|
|
42
|
-
this.pool = options.pool
|
|
41
|
+
this.directClient = options.client;
|
|
42
|
+
this.pool = options.pool;
|
|
43
43
|
this.createPoolInstance = options.createPool ?? (options.client || options.pool ? void 0 : (config) => wrapMySQLPool(mysql.createPool(config)));
|
|
44
44
|
this.config = options.config ?? (options.uri ? { uri: options.uri } : {});
|
|
45
45
|
this.connected = !!(options.client || options.pool);
|
|
@@ -82,8 +82,7 @@ var MySQLAdapter = class {
|
|
|
82
82
|
if (this.directClient) {
|
|
83
83
|
return this.transactionScope.run({
|
|
84
84
|
client: this.directClient,
|
|
85
|
-
leased: false
|
|
86
|
-
released: false
|
|
85
|
+
leased: false
|
|
87
86
|
}, callback);
|
|
88
87
|
}
|
|
89
88
|
if (!this.pool) {
|
|
@@ -91,8 +90,7 @@ var MySQLAdapter = class {
|
|
|
91
90
|
}
|
|
92
91
|
const state = {
|
|
93
92
|
client: await this.pool.getConnection(),
|
|
94
|
-
leased: true
|
|
95
|
-
released: false
|
|
93
|
+
leased: true
|
|
96
94
|
};
|
|
97
95
|
return this.transactionScope.run(state, async () => {
|
|
98
96
|
try {
|
|
@@ -125,26 +123,26 @@ var MySQLAdapter = class {
|
|
|
125
123
|
}
|
|
126
124
|
async beginTransaction() {
|
|
127
125
|
const client = await this.leaseTransactionClient();
|
|
128
|
-
await client.query("START TRANSACTION");
|
|
126
|
+
await client.query("START TRANSACTION", []);
|
|
129
127
|
}
|
|
130
128
|
async commit() {
|
|
131
129
|
const client = this.requireTransactionClient();
|
|
132
|
-
await client.query("COMMIT");
|
|
130
|
+
await client.query("COMMIT", []);
|
|
133
131
|
this.releaseTransactionClient();
|
|
134
132
|
}
|
|
135
133
|
async rollback() {
|
|
136
134
|
const client = this.requireTransactionClient();
|
|
137
|
-
await client.query("ROLLBACK");
|
|
135
|
+
await client.query("ROLLBACK", []);
|
|
138
136
|
this.releaseTransactionClient();
|
|
139
137
|
}
|
|
140
138
|
async createSavepoint(name) {
|
|
141
|
-
await this.requireTransactionClient().query(`SAVEPOINT ${this.normalizeSavepointName(name)}
|
|
139
|
+
await this.requireTransactionClient().query(`SAVEPOINT ${this.normalizeSavepointName(name)}`, []);
|
|
142
140
|
}
|
|
143
141
|
async rollbackToSavepoint(name) {
|
|
144
|
-
await this.requireTransactionClient().query(`ROLLBACK TO SAVEPOINT ${this.normalizeSavepointName(name)}
|
|
142
|
+
await this.requireTransactionClient().query(`ROLLBACK TO SAVEPOINT ${this.normalizeSavepointName(name)}`, []);
|
|
145
143
|
}
|
|
146
144
|
async releaseSavepoint(name) {
|
|
147
|
-
await this.requireTransactionClient().query(`RELEASE SAVEPOINT ${this.normalizeSavepointName(name)}
|
|
145
|
+
await this.requireTransactionClient().query(`RELEASE SAVEPOINT ${this.normalizeSavepointName(name)}`, []);
|
|
148
146
|
}
|
|
149
147
|
async getQueryable() {
|
|
150
148
|
const scoped = this.transactionScope.getStore();
|
|
@@ -202,11 +200,10 @@ var MySQLAdapter = class {
|
|
|
202
200
|
this.leasedTransactionClient = false;
|
|
203
201
|
}
|
|
204
202
|
releaseScopedTransaction(state) {
|
|
205
|
-
if (!state.leased
|
|
203
|
+
if (!state.leased) {
|
|
206
204
|
return;
|
|
207
205
|
}
|
|
208
206
|
state.client.release?.();
|
|
209
|
-
state.released = true;
|
|
210
207
|
}
|
|
211
208
|
normalizeSavepointName(name) {
|
|
212
209
|
if (!/^[A-Z_]\w*$/i.test(name)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@holo-js/db-mysql",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Holo-JS Framework - MySQL database adapter",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,18 +20,19 @@
|
|
|
20
20
|
"build": "tsup",
|
|
21
21
|
"stub": "tsup --watch",
|
|
22
22
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
23
|
-
"test": "vitest --run"
|
|
23
|
+
"test": "vitest --run",
|
|
24
|
+
"test:integration": "HOLO_MYSQL_INTEGRATION=1 vitest --run tests/mysql.test.ts"
|
|
24
25
|
},
|
|
25
26
|
"peerDependencies": {
|
|
26
|
-
"@holo-js/db": "^0.1.
|
|
27
|
+
"@holo-js/db": "^0.1.5"
|
|
27
28
|
},
|
|
28
29
|
"dependencies": {
|
|
29
30
|
"mysql2": "^3.17.1"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
|
-
"@holo-js/db": "
|
|
33
|
+
"@holo-js/db": "^0.1.5",
|
|
33
34
|
"tsup": "^8.3.5",
|
|
34
35
|
"typescript": "^5.7.2",
|
|
35
|
-
"vitest": "^
|
|
36
|
+
"vitest": "^4.1.5"
|
|
36
37
|
}
|
|
37
38
|
}
|