@schemavaults/dbh 0.7.1 → 0.7.3

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.
@@ -0,0 +1,14 @@
1
+ import type { Kysely } from "kysely";
2
+ export interface IMigrateOptions {
3
+ db: Kysely<any>;
4
+ migrationFolder: string;
5
+ version?: string;
6
+ }
7
+ export interface IReverseOptions {
8
+ db: Kysely<any>;
9
+ migrationFolder: string;
10
+ version: string;
11
+ }
12
+ export declare function migrate({ db, migrationFolder, ...opts }: IMigrateOptions): Promise<void>;
13
+ export declare function reverse({ db, migrationFolder, version, }: IReverseOptions): Promise<void>;
14
+ export default migrate;
@@ -0,0 +1,51 @@
1
+ import { Migrator, FileMigrationProvider } from "kysely";
2
+ import fs from "fs/promises";
3
+ import path from "path";
4
+ import { existsSync } from "fs";
5
+ function createMigrator({ db, migrationFolder }) {
6
+ return new Migrator({
7
+ db: db,
8
+ provider: new FileMigrationProvider({
9
+ fs,
10
+ path,
11
+ migrationFolder,
12
+ }),
13
+ });
14
+ }
15
+ export async function migrate({ db, migrationFolder, ...opts }) {
16
+ if (typeof migrationFolder !== "string") {
17
+ throw new Error("migrationFolder must be a string");
18
+ }
19
+ if (!existsSync(migrationFolder)) {
20
+ throw new Error(`migrationFolder '${migrationFolder}' does not exist`);
21
+ }
22
+ const migrator = createMigrator({ db, migrationFolder });
23
+ let result;
24
+ if (typeof opts.version === "string") {
25
+ result = await migrator.migrateTo(opts.version);
26
+ }
27
+ else {
28
+ result = await migrator.migrateToLatest();
29
+ }
30
+ const { error } = result;
31
+ if (error) {
32
+ console.error(error);
33
+ process.exit(1);
34
+ }
35
+ }
36
+ export async function reverse({ db, migrationFolder, version, }) {
37
+ if (typeof migrationFolder !== "string") {
38
+ throw new Error("migrationFolder must be a string");
39
+ }
40
+ if (!existsSync(migrationFolder)) {
41
+ throw new Error(`migrationFolder '${migrationFolder}' does not exist`);
42
+ }
43
+ const migrator = createMigrator({ db, migrationFolder });
44
+ const { error } = await migrator.migrateTo(version);
45
+ if (error) {
46
+ console.error(error);
47
+ process.exit(1);
48
+ }
49
+ }
50
+ export default migrate;
51
+ //# sourceMappingURL=migrate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate.js","sourceRoot":"","sources":["../src/migrate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,QAAQ,CAAC;AACzD,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAehC,SAAS,cAAc,CAAC,EAAE,EAAE,EAAE,eAAe,EAAmB;IAC9D,OAAO,IAAI,QAAQ,CAAC;QAClB,EAAE,EAAE,EAAE;QACN,QAAQ,EAAE,IAAI,qBAAqB,CAAC;YAClC,EAAE;YACF,IAAI;YACJ,eAAe;SAChB,CAAC;KACH,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,EAC5B,EAAE,EACF,eAAe,EACf,GAAG,IAAI,EACS;IAChB,IAAI,OAAO,eAAe,KAAK,QAAQ,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IACtD,CAAC;IAED,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CAAC,oBAAoB,eAAe,kBAAkB,CAAC,CAAC;IACzE,CAAC;IAED,MAAM,QAAQ,GAAG,cAAc,CAAC,EAAE,EAAE,EAAE,eAAe,EAAE,CAAC,CAAC;IAEzD,IAAI,MAA0B,CAAC;IAC/B,IAAI,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;QACrC,MAAM,GAAG,MAAM,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAClD,CAAC;SAAM,CAAC;QACN,MAAM,GAAG,MAAM,QAAQ,CAAC,eAAe,EAAE,CAAC;IAC5C,CAAC;IACD,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;IACzB,IAAI,KAAK,EAAE,CAAC;QACV,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,EAC5B,EAAE,EACF,eAAe,EACf,OAAO,GACS;IAChB,IAAI,OAAO,eAAe,KAAK,QAAQ,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IACtD,CAAC;IAED,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CAAC,oBAAoB,eAAe,kBAAkB,CAAC,CAAC;IACzE,CAAC;IAED,MAAM,QAAQ,GAAG,cAAc,CAAC,EAAE,EAAE,EAAE,eAAe,EAAE,CAAC,CAAC;IAEzD,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACpD,IAAI,KAAK,EAAE,CAAC;QACV,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,eAAe,OAAO,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schemavaults/dbh",
3
- "version": "0.7.1",
3
+ "version": "0.7.3",
4
4
  "description": "Easily connect to PostgresDB from serverless environment",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
@@ -9,13 +9,13 @@
9
9
  "url": "https://github.com/schemavaults/dbh.git"
10
10
  },
11
11
  "dependencies": {
12
- "kysely": "0.28.2",
12
+ "kysely": "0.28.10",
13
13
  "kysely-neon": "1.3.0",
14
14
  "@neondatabase/serverless": "1.0.1"
15
15
  },
16
16
  "devDependencies": {
17
17
  "typescript": "5.9.3",
18
- "bun-types": "1.3.3",
18
+ "bun-types": "1.3.6",
19
19
  "tsc-alias": "1.8.16",
20
20
  "eslint": "9.39.1",
21
21
  "@eslint/js": "9.39.1",
@@ -42,5 +42,27 @@
42
42
  "publishConfig": {
43
43
  "access": "public"
44
44
  },
45
- "packageManager": "bun@1.3.3"
45
+ "packageManager": "bun@1.3.6",
46
+ "exports": {
47
+ ".": {
48
+ "types": "./dist/index.d.ts",
49
+ "import": "./dist/index.js",
50
+ "require": "./dist/index.js"
51
+ },
52
+ "./dist/*": {
53
+ "types": "./dist/*",
54
+ "import": "./dist/*",
55
+ "require": "./dist/*"
56
+ },
57
+ "./*": {
58
+ "types": "./dist/*",
59
+ "import": "./dist/*",
60
+ "require": "./dist/*"
61
+ },
62
+ "./migrate": {
63
+ "types": "./dist/migrate.d.ts",
64
+ "import": "./dist/migrate.js",
65
+ "require": "./dist/migrate.js"
66
+ }
67
+ }
46
68
  }