@geekmidas/db 0.0.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/dist/kysely.cjs +9 -0
- package/dist/kysely.d.cts +7 -0
- package/dist/kysely.d.mts +7 -0
- package/dist/kysely.mjs +8 -0
- package/package.json +31 -0
- package/src/kysely.ts +17 -0
package/dist/kysely.cjs
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ControlledTransaction, Kysely, Transaction } from "kysely";
|
|
2
|
+
|
|
3
|
+
//#region src/kysely.d.ts
|
|
4
|
+
declare function withTransaction<T>(db: DatabaseConnection<any>, cb: (trx: DatabaseConnection<any>) => Promise<T>): Promise<T>;
|
|
5
|
+
type DatabaseConnection<T> = ControlledTransaction<T> | Kysely<T> | Transaction<T>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { DatabaseConnection, withTransaction };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ControlledTransaction, Kysely, Transaction } from "kysely";
|
|
2
|
+
|
|
3
|
+
//#region src/kysely.d.ts
|
|
4
|
+
declare function withTransaction<T>(db: DatabaseConnection<any>, cb: (trx: DatabaseConnection<any>) => Promise<T>): Promise<T>;
|
|
5
|
+
type DatabaseConnection<T> = ControlledTransaction<T> | Kysely<T> | Transaction<T>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { DatabaseConnection, withTransaction };
|
package/dist/kysely.mjs
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@geekmidas/db",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
"./kysely": {
|
|
8
|
+
"types": "./dist/kysely.d.ts",
|
|
9
|
+
"import": "./dist/kysely.mjs",
|
|
10
|
+
"require": "./dist/kysely.cjs"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@faker-js/faker": "~9.9.0"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@types/pg": "~8.15.4"
|
|
18
|
+
},
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"registry": "https://registry.npmjs.org/",
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"kysely": "~0.28.2",
|
|
25
|
+
"pg": "~8.16.3",
|
|
26
|
+
"knex": "~3.1.0",
|
|
27
|
+
"objection": "~3.1.5",
|
|
28
|
+
"db-errors": "~0.2.3",
|
|
29
|
+
"vitest": "~3.2.4"
|
|
30
|
+
}
|
|
31
|
+
}
|
package/src/kysely.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ControlledTransaction, Kysely, Transaction } from 'kysely';
|
|
2
|
+
|
|
3
|
+
export function withTransaction<T>(
|
|
4
|
+
db: DatabaseConnection<any>,
|
|
5
|
+
cb: (trx: DatabaseConnection<any>) => Promise<T>,
|
|
6
|
+
): Promise<T> {
|
|
7
|
+
if (db.isTransaction) {
|
|
8
|
+
return cb(db);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return db.transaction().execute(cb);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type DatabaseConnection<T> =
|
|
15
|
+
| ControlledTransaction<T>
|
|
16
|
+
| Kysely<T>
|
|
17
|
+
| Transaction<T>;
|