@faasjs/knex 1.4.1 → 1.4.2
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.mts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +29 -26
- package/dist/index.mjs +29 -26
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -29,9 +29,9 @@ declare class Knex implements Plugin {
|
|
|
29
29
|
*
|
|
30
30
|
* - Support 'commit' and 'rollback' event.
|
|
31
31
|
*/
|
|
32
|
-
transaction<TResult = any>(scope: (trx: Knex$1.Transaction<any, any>) => Promise<TResult
|
|
32
|
+
transaction<TResult = any>(scope: (trx: Knex$1.Transaction<any, any>) => Promise<TResult>, config?: Knex$1.TransactionConfig, options?: {
|
|
33
33
|
trx?: Knex$1.Transaction;
|
|
34
|
-
}): Promise<TResult
|
|
34
|
+
}): Promise<TResult>;
|
|
35
35
|
schema(): Knex$1.SchemaBuilder;
|
|
36
36
|
quit(): Promise<void>;
|
|
37
37
|
}
|
|
@@ -46,9 +46,9 @@ declare function query<TName extends Knex$1.TableNames>(table: TName): Knex$1.Qu
|
|
|
46
46
|
_unionProps: never;
|
|
47
47
|
}[]>;
|
|
48
48
|
declare function query<TName extends {} = any, TResult = any[]>(table: string): Knex$1.QueryBuilder<TName, TResult>;
|
|
49
|
-
declare function transaction<TResult = any>(scope: (trx: Knex$1.Transaction<any, any>) => Promise<TResult
|
|
49
|
+
declare function transaction<TResult = any>(scope: (trx: Knex$1.Transaction<any, any>) => Promise<TResult>, config?: Knex$1.TransactionConfig, options?: {
|
|
50
50
|
trx?: Knex$1.Transaction;
|
|
51
|
-
}): Promise<TResult
|
|
52
|
-
declare function raw<TResult = any>(sql: string, bindings?: Knex$1.RawBinding[] | Knex$1.ValueDict): Promise<TResult
|
|
51
|
+
}): Promise<TResult>;
|
|
52
|
+
declare function raw<TResult = any>(sql: string, bindings?: Knex$1.RawBinding[] | Knex$1.ValueDict): Promise<Knex$1.Raw<TResult>>;
|
|
53
53
|
|
|
54
54
|
export { Knex, type KnexConfig, originKnex, query, raw, transaction, useKnex };
|
package/dist/index.d.ts
CHANGED
|
@@ -29,9 +29,9 @@ declare class Knex implements Plugin {
|
|
|
29
29
|
*
|
|
30
30
|
* - Support 'commit' and 'rollback' event.
|
|
31
31
|
*/
|
|
32
|
-
transaction<TResult = any>(scope: (trx: Knex$1.Transaction<any, any>) => Promise<TResult
|
|
32
|
+
transaction<TResult = any>(scope: (trx: Knex$1.Transaction<any, any>) => Promise<TResult>, config?: Knex$1.TransactionConfig, options?: {
|
|
33
33
|
trx?: Knex$1.Transaction;
|
|
34
|
-
}): Promise<TResult
|
|
34
|
+
}): Promise<TResult>;
|
|
35
35
|
schema(): Knex$1.SchemaBuilder;
|
|
36
36
|
quit(): Promise<void>;
|
|
37
37
|
}
|
|
@@ -46,9 +46,9 @@ declare function query<TName extends Knex$1.TableNames>(table: TName): Knex$1.Qu
|
|
|
46
46
|
_unionProps: never;
|
|
47
47
|
}[]>;
|
|
48
48
|
declare function query<TName extends {} = any, TResult = any[]>(table: string): Knex$1.QueryBuilder<TName, TResult>;
|
|
49
|
-
declare function transaction<TResult = any>(scope: (trx: Knex$1.Transaction<any, any>) => Promise<TResult
|
|
49
|
+
declare function transaction<TResult = any>(scope: (trx: Knex$1.Transaction<any, any>) => Promise<TResult>, config?: Knex$1.TransactionConfig, options?: {
|
|
50
50
|
trx?: Knex$1.Transaction;
|
|
51
|
-
}): Promise<TResult
|
|
52
|
-
declare function raw<TResult = any>(sql: string, bindings?: Knex$1.RawBinding[] | Knex$1.ValueDict): Promise<TResult
|
|
51
|
+
}): Promise<TResult>;
|
|
52
|
+
declare function raw<TResult = any>(sql: string, bindings?: Knex$1.RawBinding[] | Knex$1.ValueDict): Promise<Knex$1.Raw<TResult>>;
|
|
53
53
|
|
|
54
54
|
export { Knex, type KnexConfig, originKnex, query, raw, transaction, useKnex };
|
package/dist/index.js
CHANGED
|
@@ -166,37 +166,40 @@ var Knex = class {
|
|
|
166
166
|
throw Error(`[${this.name}] Client not initialized.`);
|
|
167
167
|
if (options == null ? void 0 : options.trx)
|
|
168
168
|
return scope(options.trx);
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
this.name,
|
|
176
|
-
trxId,
|
|
177
|
-
"COMMIT;"
|
|
178
|
-
);
|
|
179
|
-
await trx.commit();
|
|
169
|
+
const trx = await this.adapter.transaction(config);
|
|
170
|
+
const trxId = crypto.randomUUID();
|
|
171
|
+
this.logger.debug("[%s] [%s] transaction begin", this.name, trxId);
|
|
172
|
+
try {
|
|
173
|
+
const result = await scope(trx);
|
|
174
|
+
if (trx.isCompleted()) {
|
|
180
175
|
this.logger.debug(
|
|
181
|
-
"[%s] [%s]
|
|
176
|
+
"[%s] [%s] transaction has been finished in scope",
|
|
182
177
|
this.name,
|
|
183
|
-
trxId
|
|
184
|
-
"COMMIT;"
|
|
178
|
+
trxId
|
|
185
179
|
);
|
|
186
|
-
trx.emit("commit");
|
|
187
180
|
return result;
|
|
188
|
-
} catch (error) {
|
|
189
|
-
await trx.rollback(error);
|
|
190
|
-
this.logger.debug(
|
|
191
|
-
"[%s] [%s] query failed: %s",
|
|
192
|
-
this.name,
|
|
193
|
-
trxId,
|
|
194
|
-
"ROLLBACK;"
|
|
195
|
-
);
|
|
196
|
-
trx.emit("rollback", error);
|
|
197
|
-
throw error;
|
|
198
181
|
}
|
|
199
|
-
|
|
182
|
+
this.logger.debug("[%s] [%s] transaction begin commit", this.name, trxId);
|
|
183
|
+
await trx.commit();
|
|
184
|
+
this.logger.debug(
|
|
185
|
+
"[%s] [%s] transaction committed: %j",
|
|
186
|
+
this.name,
|
|
187
|
+
trxId,
|
|
188
|
+
result
|
|
189
|
+
);
|
|
190
|
+
trx.emit("commit");
|
|
191
|
+
return result;
|
|
192
|
+
} catch (error) {
|
|
193
|
+
await trx.rollback(error);
|
|
194
|
+
this.logger.error(
|
|
195
|
+
"[%s] [%s] transaction rollback: %s",
|
|
196
|
+
this.name,
|
|
197
|
+
trxId,
|
|
198
|
+
error
|
|
199
|
+
);
|
|
200
|
+
trx.emit("rollback", error);
|
|
201
|
+
throw error;
|
|
202
|
+
}
|
|
200
203
|
}
|
|
201
204
|
schema() {
|
|
202
205
|
if (!this.adapter)
|
package/dist/index.mjs
CHANGED
|
@@ -160,37 +160,40 @@ var Knex = class {
|
|
|
160
160
|
throw Error(`[${this.name}] Client not initialized.`);
|
|
161
161
|
if (options == null ? void 0 : options.trx)
|
|
162
162
|
return scope(options.trx);
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
this.name,
|
|
170
|
-
trxId,
|
|
171
|
-
"COMMIT;"
|
|
172
|
-
);
|
|
173
|
-
await trx.commit();
|
|
163
|
+
const trx = await this.adapter.transaction(config);
|
|
164
|
+
const trxId = randomUUID();
|
|
165
|
+
this.logger.debug("[%s] [%s] transaction begin", this.name, trxId);
|
|
166
|
+
try {
|
|
167
|
+
const result = await scope(trx);
|
|
168
|
+
if (trx.isCompleted()) {
|
|
174
169
|
this.logger.debug(
|
|
175
|
-
"[%s] [%s]
|
|
170
|
+
"[%s] [%s] transaction has been finished in scope",
|
|
176
171
|
this.name,
|
|
177
|
-
trxId
|
|
178
|
-
"COMMIT;"
|
|
172
|
+
trxId
|
|
179
173
|
);
|
|
180
|
-
trx.emit("commit");
|
|
181
174
|
return result;
|
|
182
|
-
} catch (error) {
|
|
183
|
-
await trx.rollback(error);
|
|
184
|
-
this.logger.debug(
|
|
185
|
-
"[%s] [%s] query failed: %s",
|
|
186
|
-
this.name,
|
|
187
|
-
trxId,
|
|
188
|
-
"ROLLBACK;"
|
|
189
|
-
);
|
|
190
|
-
trx.emit("rollback", error);
|
|
191
|
-
throw error;
|
|
192
175
|
}
|
|
193
|
-
|
|
176
|
+
this.logger.debug("[%s] [%s] transaction begin commit", this.name, trxId);
|
|
177
|
+
await trx.commit();
|
|
178
|
+
this.logger.debug(
|
|
179
|
+
"[%s] [%s] transaction committed: %j",
|
|
180
|
+
this.name,
|
|
181
|
+
trxId,
|
|
182
|
+
result
|
|
183
|
+
);
|
|
184
|
+
trx.emit("commit");
|
|
185
|
+
return result;
|
|
186
|
+
} catch (error) {
|
|
187
|
+
await trx.rollback(error);
|
|
188
|
+
this.logger.error(
|
|
189
|
+
"[%s] [%s] transaction rollback: %s",
|
|
190
|
+
this.name,
|
|
191
|
+
trxId,
|
|
192
|
+
error
|
|
193
|
+
);
|
|
194
|
+
trx.emit("rollback", error);
|
|
195
|
+
throw error;
|
|
196
|
+
}
|
|
194
197
|
}
|
|
195
198
|
schema() {
|
|
196
199
|
if (!this.adapter)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/knex",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"dist"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@faasjs/deep_merge": "1.4.
|
|
25
|
-
"@faasjs/func": "1.4.
|
|
26
|
-
"@faasjs/logger": "1.4.
|
|
24
|
+
"@faasjs/deep_merge": "1.4.2",
|
|
25
|
+
"@faasjs/func": "1.4.2",
|
|
26
|
+
"@faasjs/logger": "1.4.2"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"knex": "*"
|