drizzle-kit 0.20.8 → 0.20.9

Sign up to get free protection for your applications and to get access to all the features.
package/utils.js CHANGED
@@ -11898,10 +11898,9 @@ var pgSerializer_exports = {};
11898
11898
  __export(pgSerializer_exports, {
11899
11899
  fromDatabase: () => fromDatabase2,
11900
11900
  generatePgSnapshot: () => generatePgSnapshot,
11901
- indexName: () => indexName2,
11902
- toDrizzle: () => toDrizzle
11901
+ indexName: () => indexName2
11903
11902
  });
11904
- var import_pg_core2, import_pg_core3, import_drizzle_orm5, dialect4, indexName2, generatePgSnapshot, trimChar, fromDatabase2, columnToDefault, defaultForColumn, toDrizzle;
11903
+ var import_pg_core2, import_pg_core3, import_drizzle_orm5, dialect4, indexName2, generatePgSnapshot, trimChar, fromDatabase2, columnToDefault, defaultForColumn;
11905
11904
  var init_pgSerializer = __esm({
11906
11905
  "src/serializer/pgSerializer.ts"() {
11907
11906
  import_pg_core2 = require("drizzle-orm/pg-core");
@@ -12531,108 +12530,6 @@ ${withStyle.errorWarning(
12531
12530
  }
12532
12531
  }
12533
12532
  };
12534
- toDrizzle = (schema4, schemaName) => {
12535
- const tables = {};
12536
- Object.values(schema4.tables).forEach((t) => {
12537
- const columns = {};
12538
- Object.values(t.columns).forEach((c) => {
12539
- const columnName = c.name;
12540
- const type = c.type;
12541
- let columnBuilder;
12542
- if (type === "bigint") {
12543
- columnBuilder = new import_pg_core2.PgBigInt53Builder(columnName);
12544
- } else if (type === "bigserial") {
12545
- columnBuilder = new import_pg_core2.PgBigSerial53Builder(columnName);
12546
- } else if (type === "boolean") {
12547
- columnBuilder = new import_pg_core2.PgBooleanBuilder(columnName);
12548
- } else if (type === "cidr") {
12549
- columnBuilder = new import_pg_core2.PgCidrBuilder(columnName);
12550
- } else if (type === "date") {
12551
- columnBuilder = new import_pg_core2.PgDateBuilder(columnName);
12552
- } else if (type === "double precision") {
12553
- columnBuilder = new import_pg_core2.PgDoublePrecisionBuilder(columnName);
12554
- } else if (type === "inet") {
12555
- columnBuilder = new import_pg_core2.PgInetBuilder(columnName);
12556
- } else if (type === "integer") {
12557
- columnBuilder = new import_pg_core2.PgIntegerBuilder(columnName);
12558
- } else if (type === "interval" || type.startsWith("interval ")) {
12559
- columnBuilder = new import_pg_core2.PgIntervalBuilder(columnName, {});
12560
- } else if (type === "json") {
12561
- columnBuilder = new import_pg_core2.PgJsonBuilder(columnName);
12562
- } else if (type === "jsonb") {
12563
- columnBuilder = new import_pg_core2.PgJsonbBuilder(columnName);
12564
- } else if (type === "macaddr") {
12565
- columnBuilder = new import_pg_core2.PgMacaddrBuilder(columnName);
12566
- } else if (type === "macaddr8") {
12567
- columnBuilder = new import_pg_core2.PgMacaddr8Builder(columnName);
12568
- } else if (type === "numeric" || type.startsWith("numeric(")) {
12569
- columnBuilder = new import_pg_core2.PgNumericBuilder(columnName);
12570
- } else if (type === "real") {
12571
- columnBuilder = new import_pg_core2.PgRealBuilder(columnName);
12572
- } else if (type === "serial") {
12573
- columnBuilder = new import_pg_core2.PgSerialBuilder(columnName);
12574
- } else if (type === "smallint") {
12575
- columnBuilder = new import_pg_core2.PgSmallIntBuilder(columnName);
12576
- } else if (type === "smallserial") {
12577
- columnBuilder = new import_pg_core2.PgSmallSerialBuilder(columnName);
12578
- } else if (type === "text") {
12579
- columnBuilder = new import_pg_core2.PgTextBuilder(columnName, {});
12580
- } else if (type === "time" || type.startsWith("time(") || type === "time with time zone") {
12581
- columnBuilder = new import_pg_core2.PgTimeBuilder(columnName, false, void 0);
12582
- } else if (type === "timestamp" || type.startsWith("timestamp(") || type === "timestamp with time zone") {
12583
- columnBuilder = new import_pg_core2.PgTimestampBuilder(columnName, false, void 0);
12584
- } else if (type === "uuid") {
12585
- columnBuilder = new import_pg_core2.PgUUIDBuilder(columnName);
12586
- } else if (type === "varchar" || type.startsWith("varchar(")) {
12587
- columnBuilder = new import_pg_core2.PgVarcharBuilder(columnName, {});
12588
- } else if (type === "char" || type.startsWith("char(")) {
12589
- columnBuilder = new import_pg_core2.PgCharBuilder(columnName, {});
12590
- } else {
12591
- columnBuilder = (0, import_pg_core2.customType)({
12592
- dataType() {
12593
- return type;
12594
- }
12595
- })(columnName);
12596
- }
12597
- if (c.notNull) {
12598
- columnBuilder = columnBuilder.notNull();
12599
- }
12600
- if (c.default) {
12601
- columnBuilder = columnBuilder.default(c.default);
12602
- }
12603
- if (c.primaryKey) {
12604
- columnBuilder = columnBuilder.primaryKey();
12605
- }
12606
- columns[columnName] = columnBuilder;
12607
- });
12608
- if (schemaName === "public") {
12609
- tables[t.name] = (0, import_pg_core2.pgTable)(t.name, columns, (cb) => {
12610
- const res = {};
12611
- Object.values(t.compositePrimaryKeys).forEach((cpk) => {
12612
- const gh = cpk.columns.map((c) => cb[c]);
12613
- res[cpk.name] = new import_pg_core2.PrimaryKeyBuilder(
12614
- gh,
12615
- cpk.name
12616
- );
12617
- });
12618
- return res;
12619
- });
12620
- } else {
12621
- tables[t.name] = (0, import_pg_core2.pgSchema)(schemaName).table(t.name, columns, (cb) => {
12622
- const res = {};
12623
- Object.values(t.compositePrimaryKeys).forEach((cpk) => {
12624
- const gh = cpk.columns.map((c) => cb[c]);
12625
- res[cpk.name] = new import_pg_core2.PrimaryKeyBuilder(
12626
- gh,
12627
- cpk.name
12628
- );
12629
- });
12630
- return res;
12631
- });
12632
- }
12633
- });
12634
- return tables;
12635
- };
12636
12533
  }
12637
12534
  });
12638
12535
 
@@ -12671,8 +12568,7 @@ var init_sqliteImports = __esm({
12671
12568
  var sqliteSerializer_exports = {};
12672
12569
  __export(sqliteSerializer_exports, {
12673
12570
  fromDatabase: () => fromDatabase3,
12674
- generateSqliteSnapshot: () => generateSqliteSnapshot,
12675
- toDrizzle: () => toDrizzle2
12571
+ generateSqliteSnapshot: () => generateSqliteSnapshot
12676
12572
  });
12677
12573
  function mapSqlToSqliteType(sqlType) {
12678
12574
  if ([
@@ -12709,7 +12605,7 @@ function mapSqlToSqliteType(sqlType) {
12709
12605
  return "numeric";
12710
12606
  }
12711
12607
  }
12712
- var import_drizzle_orm7, import_sqlite_core2, dialect5, generateSqliteSnapshot, fromDatabase3, toDrizzle2;
12608
+ var import_drizzle_orm7, import_sqlite_core2, dialect5, generateSqliteSnapshot, fromDatabase3;
12713
12609
  var init_sqliteSerializer = __esm({
12714
12610
  "src/serializer/sqliteSerializer.ts"() {
12715
12611
  import_drizzle_orm7 = require("drizzle-orm");
@@ -13077,50 +12973,6 @@ WHERE
13077
12973
  }
13078
12974
  };
13079
12975
  };
13080
- toDrizzle2 = (schema4) => {
13081
- const tables = {};
13082
- Object.values(schema4.tables).forEach((t) => {
13083
- const columns = {};
13084
- Object.values(t.columns).forEach((c) => {
13085
- const columnName = c.name;
13086
- const type = c.type;
13087
- let columnBuilder;
13088
- if (type === "integer") {
13089
- columnBuilder = new import_sqlite_core2.SQLiteIntegerBuilder(columnName);
13090
- } else if (type === "text") {
13091
- columnBuilder = new import_sqlite_core2.SQLiteTextBuilder(columnName, {});
13092
- } else if (type === "blob") {
13093
- columnBuilder = new import_sqlite_core2.SQLiteBlobBufferBuilder(columnName);
13094
- } else if (type === "real") {
13095
- columnBuilder = new import_sqlite_core2.SQLiteRealBuilder(columnName);
13096
- } else {
13097
- columnBuilder = new import_sqlite_core2.SQLiteNumericBuilder(columnName);
13098
- }
13099
- if (c.notNull) {
13100
- columnBuilder = columnBuilder.notNull();
13101
- }
13102
- if (c.default) {
13103
- columnBuilder = columnBuilder.default(c.default);
13104
- }
13105
- if (c.primaryKey) {
13106
- columnBuilder = columnBuilder.primaryKey();
13107
- }
13108
- columns[columnName] = columnBuilder;
13109
- });
13110
- tables[t.name] = (0, import_sqlite_core2.sqliteTable)(t.name, columns, (cb) => {
13111
- const res = {};
13112
- Object.values(t.compositePrimaryKeys).forEach((cpk) => {
13113
- const gh = cpk.columns.map((c) => cb[c]);
13114
- res[cpk.name] = new import_sqlite_core2.PrimaryKeyBuilder(
13115
- gh,
13116
- cpk.name
13117
- );
13118
- });
13119
- return res;
13120
- });
13121
- });
13122
- return tables;
13123
- };
13124
12976
  }
13125
12977
  });
13126
12978
 
@@ -24908,6 +24760,161 @@ var init_sqliteIntrospect = __esm({
24908
24760
  }
24909
24761
  });
24910
24762
 
24763
+ // src/serializer/schemaToDrizzle.ts
24764
+ var import_pg_core4, import_sqlite_core3, pgSchemaToDrizzle, sqliteSchemaToDrizzle;
24765
+ var init_schemaToDrizzle = __esm({
24766
+ "src/serializer/schemaToDrizzle.ts"() {
24767
+ import_pg_core4 = require("drizzle-orm/pg-core");
24768
+ import_sqlite_core3 = require("drizzle-orm/sqlite-core");
24769
+ pgSchemaToDrizzle = (schema4, schemaName) => {
24770
+ const tables = {};
24771
+ Object.values(schema4.tables).forEach((t) => {
24772
+ const columns = {};
24773
+ Object.values(t.columns).forEach((c) => {
24774
+ const columnName = c.name;
24775
+ const type = c.type;
24776
+ let columnBuilder;
24777
+ if (type === "bigint") {
24778
+ columnBuilder = new import_pg_core4.PgBigInt53Builder(columnName);
24779
+ } else if (type === "bigserial") {
24780
+ columnBuilder = new import_pg_core4.PgBigSerial53Builder(columnName);
24781
+ } else if (type === "boolean") {
24782
+ columnBuilder = new import_pg_core4.PgBooleanBuilder(columnName);
24783
+ } else if (type === "cidr") {
24784
+ columnBuilder = new import_pg_core4.PgCidrBuilder(columnName);
24785
+ } else if (type === "date") {
24786
+ columnBuilder = new import_pg_core4.PgDateBuilder(columnName);
24787
+ } else if (type === "double precision") {
24788
+ columnBuilder = new import_pg_core4.PgDoublePrecisionBuilder(columnName);
24789
+ } else if (type === "inet") {
24790
+ columnBuilder = new import_pg_core4.PgInetBuilder(columnName);
24791
+ } else if (type === "integer") {
24792
+ columnBuilder = new import_pg_core4.PgIntegerBuilder(columnName);
24793
+ } else if (type === "interval" || type.startsWith("interval ")) {
24794
+ columnBuilder = new import_pg_core4.PgIntervalBuilder(columnName, {});
24795
+ } else if (type === "json") {
24796
+ columnBuilder = new import_pg_core4.PgJsonBuilder(columnName);
24797
+ } else if (type === "jsonb") {
24798
+ columnBuilder = new import_pg_core4.PgJsonbBuilder(columnName);
24799
+ } else if (type === "macaddr") {
24800
+ columnBuilder = new import_pg_core4.PgMacaddrBuilder(columnName);
24801
+ } else if (type === "macaddr8") {
24802
+ columnBuilder = new import_pg_core4.PgMacaddr8Builder(columnName);
24803
+ } else if (type === "numeric" || type.startsWith("numeric(")) {
24804
+ columnBuilder = new import_pg_core4.PgNumericBuilder(columnName);
24805
+ } else if (type === "real") {
24806
+ columnBuilder = new import_pg_core4.PgRealBuilder(columnName);
24807
+ } else if (type === "serial") {
24808
+ columnBuilder = new import_pg_core4.PgSerialBuilder(columnName);
24809
+ } else if (type === "smallint") {
24810
+ columnBuilder = new import_pg_core4.PgSmallIntBuilder(columnName);
24811
+ } else if (type === "smallserial") {
24812
+ columnBuilder = new import_pg_core4.PgSmallSerialBuilder(columnName);
24813
+ } else if (type === "text") {
24814
+ columnBuilder = new import_pg_core4.PgTextBuilder(columnName, {});
24815
+ } else if (type === "time" || type.startsWith("time(") || type === "time with time zone") {
24816
+ columnBuilder = new import_pg_core4.PgTimeBuilder(columnName, false, void 0);
24817
+ } else if (type === "timestamp" || type.startsWith("timestamp(") || type === "timestamp with time zone") {
24818
+ columnBuilder = new import_pg_core4.PgTimestampBuilder(columnName, false, void 0);
24819
+ } else if (type === "uuid") {
24820
+ columnBuilder = new import_pg_core4.PgUUIDBuilder(columnName);
24821
+ } else if (type === "varchar" || type.startsWith("varchar(")) {
24822
+ columnBuilder = new import_pg_core4.PgVarcharBuilder(columnName, {});
24823
+ } else if (type === "char" || type.startsWith("char(")) {
24824
+ columnBuilder = new import_pg_core4.PgCharBuilder(columnName, {});
24825
+ } else {
24826
+ columnBuilder = (0, import_pg_core4.customType)({
24827
+ dataType() {
24828
+ return type;
24829
+ }
24830
+ })(columnName);
24831
+ }
24832
+ if (c.notNull) {
24833
+ columnBuilder = columnBuilder.notNull();
24834
+ }
24835
+ if (c.default) {
24836
+ columnBuilder = columnBuilder.default(c.default);
24837
+ }
24838
+ if (c.primaryKey) {
24839
+ columnBuilder = columnBuilder.primaryKey();
24840
+ }
24841
+ columns[columnName] = columnBuilder;
24842
+ });
24843
+ if (schemaName === "public") {
24844
+ tables[t.name] = (0, import_pg_core4.pgTable)(t.name, columns, (cb) => {
24845
+ const res = {};
24846
+ Object.values(t.compositePrimaryKeys).forEach((cpk) => {
24847
+ const gh = cpk.columns.map((c) => cb[c]);
24848
+ res[cpk.name] = new import_pg_core4.PrimaryKeyBuilder(
24849
+ gh,
24850
+ cpk.name
24851
+ );
24852
+ });
24853
+ return res;
24854
+ });
24855
+ } else {
24856
+ tables[t.name] = (0, import_pg_core4.pgSchema)(schemaName).table(t.name, columns, (cb) => {
24857
+ const res = {};
24858
+ Object.values(t.compositePrimaryKeys).forEach((cpk) => {
24859
+ const gh = cpk.columns.map((c) => cb[c]);
24860
+ res[cpk.name] = new import_pg_core4.PrimaryKeyBuilder(
24861
+ gh,
24862
+ cpk.name
24863
+ );
24864
+ });
24865
+ return res;
24866
+ });
24867
+ }
24868
+ });
24869
+ return tables;
24870
+ };
24871
+ sqliteSchemaToDrizzle = (schema4) => {
24872
+ const tables = {};
24873
+ Object.values(schema4.tables).forEach((t) => {
24874
+ const columns = {};
24875
+ Object.values(t.columns).forEach((c) => {
24876
+ const columnName = c.name;
24877
+ const type = c.type;
24878
+ let columnBuilder;
24879
+ if (type === "integer") {
24880
+ columnBuilder = new import_sqlite_core3.SQLiteIntegerBuilder(columnName);
24881
+ } else if (type === "text") {
24882
+ columnBuilder = new import_sqlite_core3.SQLiteTextBuilder(columnName, {});
24883
+ } else if (type === "blob") {
24884
+ columnBuilder = new import_sqlite_core3.SQLiteBlobBufferBuilder(columnName);
24885
+ } else if (type === "real") {
24886
+ columnBuilder = new import_sqlite_core3.SQLiteRealBuilder(columnName);
24887
+ } else {
24888
+ columnBuilder = new import_sqlite_core3.SQLiteNumericBuilder(columnName);
24889
+ }
24890
+ if (c.notNull) {
24891
+ columnBuilder = columnBuilder.notNull();
24892
+ }
24893
+ if (c.default) {
24894
+ columnBuilder = columnBuilder.default(c.default);
24895
+ }
24896
+ if (c.primaryKey) {
24897
+ columnBuilder = columnBuilder.primaryKey();
24898
+ }
24899
+ columns[columnName] = columnBuilder;
24900
+ });
24901
+ tables[t.name] = (0, import_sqlite_core3.sqliteTable)(t.name, columns, (cb) => {
24902
+ const res = {};
24903
+ Object.values(t.compositePrimaryKeys).forEach((cpk) => {
24904
+ const gh = cpk.columns.map((c) => cb[c]);
24905
+ res[cpk.name] = new import_sqlite_core3.PrimaryKeyBuilder(
24906
+ gh,
24907
+ cpk.name
24908
+ );
24909
+ });
24910
+ return res;
24911
+ });
24912
+ });
24913
+ return tables;
24914
+ };
24915
+ }
24916
+ });
24917
+
24911
24918
  // node_modules/.pnpm/semver@7.5.4/node_modules/semver/internal/constants.js
24912
24919
  var require_constants = __commonJS({
24913
24920
  "node_modules/.pnpm/semver@7.5.4/node_modules/semver/internal/constants.js"(exports, module2) {
@@ -43251,15 +43258,15 @@ var require_promise = __commonJS({
43251
43258
  });
43252
43259
 
43253
43260
  // src/orm-extenstions/d1-driver/session.ts
43254
- var import_drizzle_orm10, import_drizzle_orm11, import_drizzle_orm12, import_sqlite_core3, import_drizzle_orm13, _a, SQLiteWranglerD1Session, _a2, PreparedQuery;
43261
+ var import_drizzle_orm10, import_drizzle_orm11, import_drizzle_orm12, import_sqlite_core4, import_drizzle_orm13, _a, SQLiteWranglerD1Session, _a2, PreparedQuery;
43255
43262
  var init_session = __esm({
43256
43263
  "src/orm-extenstions/d1-driver/session.ts"() {
43257
43264
  import_drizzle_orm10 = require("drizzle-orm");
43258
43265
  import_drizzle_orm11 = require("drizzle-orm");
43259
43266
  import_drizzle_orm12 = require("drizzle-orm");
43260
- import_sqlite_core3 = require("drizzle-orm/sqlite-core");
43267
+ import_sqlite_core4 = require("drizzle-orm/sqlite-core");
43261
43268
  import_drizzle_orm13 = require("drizzle-orm");
43262
- SQLiteWranglerD1Session = class extends import_sqlite_core3.SQLiteSession {
43269
+ SQLiteWranglerD1Session = class extends import_sqlite_core4.SQLiteSession {
43263
43270
  constructor(client, configPath, dbName, dialect6, schema4, options = {}) {
43264
43271
  super(dialect6);
43265
43272
  this.client = client;
@@ -43288,7 +43295,7 @@ var init_session = __esm({
43288
43295
  };
43289
43296
  _a = import_drizzle_orm10.entityKind;
43290
43297
  SQLiteWranglerD1Session[_a] = "SQLiteD1Session";
43291
- PreparedQuery = class extends import_sqlite_core3.SQLitePreparedQuery {
43298
+ PreparedQuery = class extends import_sqlite_core4.SQLitePreparedQuery {
43292
43299
  constructor(stmt, configPath, dbName, queryString, params, logger, fields, executeMethod, customResultMapper) {
43293
43300
  super("async", executeMethod, {
43294
43301
  sql: queryString,
@@ -43413,20 +43420,20 @@ function drizzle(client, configPath, dbName, config = {}) {
43413
43420
  const session = new SQLiteWranglerD1Session(client, configPath, dbName, dialect6, schema4, {
43414
43421
  logger
43415
43422
  });
43416
- return new import_sqlite_core4.BaseSQLiteDatabase(
43423
+ return new import_sqlite_core5.BaseSQLiteDatabase(
43417
43424
  "async",
43418
43425
  dialect6,
43419
43426
  session,
43420
43427
  schema4
43421
43428
  );
43422
43429
  }
43423
- var import_drizzle_orm14, import_sqlite_core4, WranglerDialect;
43430
+ var import_drizzle_orm14, import_sqlite_core5, WranglerDialect;
43424
43431
  var init_driver = __esm({
43425
43432
  "src/orm-extenstions/d1-driver/driver.ts"() {
43426
43433
  import_drizzle_orm14 = require("drizzle-orm");
43427
- import_sqlite_core4 = require("drizzle-orm/sqlite-core");
43434
+ import_sqlite_core5 = require("drizzle-orm/sqlite-core");
43428
43435
  init_session();
43429
- WranglerDialect = class extends import_sqlite_core4.SQLiteAsyncDialect {
43436
+ WranglerDialect = class extends import_sqlite_core5.SQLiteAsyncDialect {
43430
43437
  sqlToQuery(sql2) {
43431
43438
  return sql2.toQuery({
43432
43439
  escapeName: this.escapeName,
@@ -58742,13 +58749,13 @@ var init_wrangler_client = __esm({
58742
58749
  });
58743
58750
 
58744
58751
  // src/serializer/studioUtils.ts
58745
- var import_drizzle_orm15, import_mysql_core4, import_pg_core4, import_sqlite_core5, drizzleDb;
58752
+ var import_drizzle_orm15, import_mysql_core4, import_pg_core5, import_sqlite_core6, drizzleDb;
58746
58753
  var init_studioUtils = __esm({
58747
58754
  "src/serializer/studioUtils.ts"() {
58748
58755
  import_drizzle_orm15 = require("drizzle-orm");
58749
58756
  import_mysql_core4 = require("drizzle-orm/mysql-core");
58750
- import_pg_core4 = require("drizzle-orm/pg-core");
58751
- import_sqlite_core5 = require("drizzle-orm/sqlite-core");
58757
+ import_pg_core5 = require("drizzle-orm/pg-core");
58758
+ import_sqlite_core6 = require("drizzle-orm/sqlite-core");
58752
58759
  init_utils();
58753
58760
  init_utils3();
58754
58761
  init_global();
@@ -58857,8 +58864,7 @@ var init_utils5 = __esm({
58857
58864
  init_pgIntrospect();
58858
58865
  init_pgPushUtils();
58859
58866
  init_sqliteIntrospect();
58860
- init_sqliteSerializer();
58861
- init_pgSerializer();
58867
+ init_schemaToDrizzle();
58862
58868
  init_studioUtils();
58863
58869
  init_pgConnect();
58864
58870
  assertV1OutFolder = (out, dialect6) => {
@@ -59177,7 +59183,7 @@ var init_utils5 = __esm({
59177
59183
  preparedConnection.client,
59178
59184
  []
59179
59185
  );
59180
- const models = toDrizzle2(schema4);
59186
+ const models = sqliteSchemaToDrizzle(schema4);
59181
59187
  const drizzleDbInstance = await drizzleDb(
59182
59188
  connection,
59183
59189
  { sqliteSchema: models },
@@ -59202,7 +59208,7 @@ var init_utils5 = __esm({
59202
59208
  [],
59203
59209
  [schemaName]
59204
59210
  );
59205
- const models = toDrizzle(schema4, schemaName);
59211
+ const models = pgSchemaToDrizzle(schema4, schemaName);
59206
59212
  response[schemaName] = await drizzleDb(
59207
59213
  // @ts-ignore I don't know how to fix it yet. But will find a way
59208
59214
  connection,