@guren/orm 1.0.0-rc.17 → 1.0.0-rc.18

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.
Files changed (2) hide show
  1. package/dist/index.js +46 -16
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2566,11 +2566,8 @@ function SoftDeletes(Base) {
2566
2566
  }
2567
2567
 
2568
2568
  // src/postgres.ts
2569
- import { drizzle } from "drizzle-orm/postgres-js";
2570
- import { migrate } from "drizzle-orm/postgres-js/migrator";
2571
2569
  import { resolve as resolve3 } from "path";
2572
2570
  import { fileURLToPath as fileURLToPath2 } from "url";
2573
- import postgres from "postgres";
2574
2571
 
2575
2572
  // src/migration-utils.ts
2576
2573
  import { existsSync, readdirSync } from "fs";
@@ -2694,6 +2691,21 @@ function defineSeeder(handler) {
2694
2691
  }
2695
2692
 
2696
2693
  // src/postgres.ts
2694
+ async function loadPostgresModules() {
2695
+ try {
2696
+ const [{ drizzle }, { migrate }, postgresModule] = await Promise.all([
2697
+ import("drizzle-orm/postgres-js"),
2698
+ import("drizzle-orm/postgres-js/migrator"),
2699
+ import("postgres")
2700
+ ]);
2701
+ return { drizzle, migrate, postgres: postgresModule.default };
2702
+ } catch (error) {
2703
+ const reason = error instanceof Error ? error.message : String(error);
2704
+ throw new Error(
2705
+ `createPostgresDatabase() requires the "postgres" package. Install it with \`bun add postgres\`. (${reason})`
2706
+ );
2707
+ }
2708
+ }
2697
2709
  function createPostgresDatabase(options) {
2698
2710
  const { migrationsFolder, connectionString, clientOptions, seedersFolder, relations } = options;
2699
2711
  const resolvedMigrationsFolder = migrationsFolder instanceof URL ? fileURLToPath2(migrationsFolder) : resolve3(String(migrationsFolder));
@@ -2718,8 +2730,9 @@ function createPostgresDatabase(options) {
2718
2730
  warnIgnoredFlatSqlMigrations(resolvedMigrationsFolder);
2719
2731
  return;
2720
2732
  }
2733
+ const { drizzle, migrate, postgres: postgresFactory } = await loadPostgresModules();
2721
2734
  const url = resolveConnectionString();
2722
- const migrationClient = postgres(url, {
2735
+ const migrationClient = postgresFactory(url, {
2723
2736
  max: 1,
2724
2737
  ...clientOptions
2725
2738
  });
@@ -2743,8 +2756,9 @@ function createPostgresDatabase(options) {
2743
2756
  }
2744
2757
  const promise = (async () => {
2745
2758
  await migrateOnce();
2759
+ const { drizzle, postgres: postgresFactory } = await loadPostgresModules();
2746
2760
  const url = resolveConnectionString();
2747
- client = postgres(url, {
2761
+ client = postgresFactory(url, {
2748
2762
  max: 1,
2749
2763
  ...clientOptions
2750
2764
  });
@@ -2776,7 +2790,8 @@ function createPostgresDatabase(options) {
2776
2790
  await runSeeders(db, resolvedSeedersFolder);
2777
2791
  }
2778
2792
  async function withAdminClient(callback) {
2779
- const adminClient = postgres(resolveConnectionString(), {
2793
+ const { postgres: postgresFactory } = await loadPostgresModules();
2794
+ const adminClient = postgresFactory(resolveConnectionString(), {
2780
2795
  max: 1,
2781
2796
  ...clientOptions
2782
2797
  });
@@ -2822,10 +2837,22 @@ function createPostgresDatabase(options) {
2822
2837
  }
2823
2838
 
2824
2839
  // src/mysql.ts
2825
- import { drizzle as drizzle2 } from "drizzle-orm/mysql2";
2826
- import { migrate as migrate2 } from "drizzle-orm/mysql2/migrator";
2827
2840
  import { resolve as resolve4 } from "path";
2828
2841
  import { fileURLToPath as fileURLToPath3 } from "url";
2842
+ async function loadMySqlModules() {
2843
+ try {
2844
+ const [{ drizzle }, { migrate }] = await Promise.all([
2845
+ import("drizzle-orm/mysql2"),
2846
+ import("drizzle-orm/mysql2/migrator")
2847
+ ]);
2848
+ return { drizzle, migrate };
2849
+ } catch (error) {
2850
+ const reason = error instanceof Error ? error.message : String(error);
2851
+ throw new Error(
2852
+ `createMySqlDatabase() requires the "mysql2" package. Install it with \`bun add mysql2\`. (${reason})`
2853
+ );
2854
+ }
2855
+ }
2829
2856
  function createMySqlDatabase(options) {
2830
2857
  const { migrationsFolder, connectionString, clientOptions, seedersFolder, relations } = options;
2831
2858
  const resolvedMigrationsFolder = migrationsFolder instanceof URL ? fileURLToPath3(migrationsFolder) : resolve4(String(migrationsFolder));
@@ -2850,8 +2877,9 @@ function createMySqlDatabase(options) {
2850
2877
  warnIgnoredFlatSqlMigrations(resolvedMigrationsFolder);
2851
2878
  return;
2852
2879
  }
2880
+ const { drizzle, migrate } = await loadMySqlModules();
2853
2881
  const url = resolveConnectionString();
2854
- const migrationDb = drizzle2({
2882
+ const migrationDb = drizzle({
2855
2883
  connection: {
2856
2884
  uri: url,
2857
2885
  ...clientOptions
@@ -2860,7 +2888,7 @@ function createMySqlDatabase(options) {
2860
2888
  ...relations ? { relations } : {}
2861
2889
  });
2862
2890
  try {
2863
- await migrate2(migrationDb, { migrationsFolder: resolvedMigrationsFolder });
2891
+ await migrate(migrationDb, { migrationsFolder: resolvedMigrationsFolder });
2864
2892
  } finally {
2865
2893
  await closeClient(migrationDb);
2866
2894
  }
@@ -2878,8 +2906,9 @@ function createMySqlDatabase(options) {
2878
2906
  }
2879
2907
  const promise = (async () => {
2880
2908
  await migrateOnce();
2909
+ const { drizzle } = await loadMySqlModules();
2881
2910
  const url = resolveConnectionString();
2882
- const db = drizzle2({
2911
+ const db = drizzle({
2883
2912
  connection: {
2884
2913
  uri: url,
2885
2914
  ...clientOptions
@@ -2916,7 +2945,8 @@ function createMySqlDatabase(options) {
2916
2945
  await runSeeders(db, resolvedSeedersFolder);
2917
2946
  }
2918
2947
  async function withAdminDb(callback) {
2919
- const adminDb = drizzle2({
2948
+ const { drizzle } = await loadMySqlModules();
2949
+ const adminDb = drizzle({
2920
2950
  connection: {
2921
2951
  uri: resolveConnectionString(),
2922
2952
  ...clientOptions
@@ -3028,8 +3058,8 @@ function createSqliteDatabase(options) {
3028
3058
  const sqlite = new Database(dbPath);
3029
3059
  sqlite.exec("PRAGMA journal_mode = WAL;");
3030
3060
  sqliteClient = sqlite;
3031
- const { drizzle: drizzle3 } = await import("drizzle-orm/bun-sqlite");
3032
- db = drizzle3({ client: sqlite, ...relations ? { relations } : {} });
3061
+ const { drizzle } = await import("drizzle-orm/bun-sqlite");
3062
+ db = drizzle({ client: sqlite, ...relations ? { relations } : {} });
3033
3063
  return db;
3034
3064
  }
3035
3065
  async function migrateOnce() {
@@ -3040,8 +3070,8 @@ function createSqliteDatabase(options) {
3040
3070
  return;
3041
3071
  }
3042
3072
  const database2 = await ensureDatabase2();
3043
- const { migrate: migrate3 } = await import("drizzle-orm/bun-sqlite/migrator");
3044
- await migrate3(database2, { migrationsFolder: resolvedMigrationsFolder });
3073
+ const { migrate } = await import("drizzle-orm/bun-sqlite/migrator");
3074
+ await migrate(database2, { migrationsFolder: resolvedMigrationsFolder });
3045
3075
  })();
3046
3076
  migrationsPromise = migrationsPromise.catch((error) => {
3047
3077
  migrationsPromise = void 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guren/orm",
3
- "version": "1.0.0-rc.17",
3
+ "version": "1.0.0-rc.18",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {