drizzle-kit 1.0.0-beta.2-278d7e6 → 1.0.0-beta.2-9848003

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/api-postgres.js CHANGED
@@ -15199,7 +15199,8 @@ var init_schemaValidator = __esm({
15199
15199
  "singlestore",
15200
15200
  "gel",
15201
15201
  "mssql",
15202
- "cockroach"
15202
+ "cockroach",
15203
+ "duckdb"
15203
15204
  ];
15204
15205
  dialect = enumType(dialects);
15205
15206
  }
@@ -24989,7 +24990,7 @@ var init_introspect = __esm({
24989
24990
  let checksCount = 0;
24990
24991
  let viewsCount = 0;
24991
24992
  for (const seq of sequencesList) {
24992
- const depend = dependList.find((it) => it.oid === seq.oid);
24993
+ const depend = dependList.find((it) => Number(it.oid) === Number(seq.oid));
24993
24994
  if (depend && (depend.deptype === "a" || depend.deptype === "i")) {
24994
24995
  continue;
24995
24996
  }
@@ -25055,22 +25056,22 @@ var init_introspect = __esm({
25055
25056
  continue;
25056
25057
  }
25057
25058
  const expr = serialsList.find(
25058
- (it) => it.tableId === column8.tableId && it.ordinality === column8.ordinality
25059
+ (it) => Number(it.tableId) === Number(column8.tableId) && it.ordinality === column8.ordinality
25059
25060
  );
25060
25061
  if (expr) {
25061
- const table7 = tablesList.find((it) => it.oid === column8.tableId);
25062
+ const table7 = tablesList.find((it) => Number(it.oid) === Number(column8.tableId));
25062
25063
  const isSerial = isSerialExpression(expr.expression, table7.schema);
25063
25064
  column8.type = isSerial ? type === "bigint" ? "bigserial" : type === "integer" ? "serial" : "smallserial" : type;
25064
25065
  }
25065
25066
  }
25066
25067
  for (const column8 of columnsList.filter((x6) => x6.kind === "r" || x6.kind === "p")) {
25067
- const table7 = tablesList.find((it) => it.oid === column8.tableId);
25068
+ const table7 = tablesList.find((it) => Number(it.oid) === Number(column8.tableId));
25068
25069
  const enumType2 = column8.typeId in groupedEnums ? groupedEnums[column8.typeId] : column8.typeId in groupedArrEnums ? groupedArrEnums[column8.typeId] : null;
25069
25070
  let columnTypeMapped = enumType2 ? enumType2.name : column8.type.replaceAll("[]", "");
25070
25071
  columnTypeMapped = columnTypeMapped.replace("character varying", "varchar").replace(" without time zone", "").replace("character", "char").replace("geometry(Point", "geometry(point");
25071
25072
  columnTypeMapped = trimChar(columnTypeMapped, '"');
25072
25073
  const columnDefault = defaultsList.find(
25073
- (it) => it.tableId === column8.tableId && it.ordinality === column8.ordinality
25074
+ (it) => Number(it.tableId) === Number(column8.tableId) && it.ordinality === column8.ordinality
25074
25075
  );
25075
25076
  const defaultValue = defaultForColumn(
25076
25077
  columnTypeMapped,
@@ -25079,10 +25080,10 @@ var init_introspect = __esm({
25079
25080
  Boolean(enumType2)
25080
25081
  );
25081
25082
  const unique = constraintsList.find((it) => {
25082
- return it.type === "u" && it.tableId === column8.tableId && it.columnsOrdinals.length === 1 && it.columnsOrdinals.includes(column8.ordinality);
25083
+ return it.type === "u" && Number(it.tableId) === Number(column8.tableId) && it.columnsOrdinals.length === 1 && it.columnsOrdinals.includes(column8.ordinality);
25083
25084
  }) ?? null;
25084
25085
  const pk = constraintsList.find((it) => {
25085
- return it.type === "p" && it.tableId === column8.tableId && it.columnsOrdinals.length === 1 && it.columnsOrdinals.includes(column8.ordinality);
25086
+ return it.type === "p" && Number(it.tableId) === Number(column8.tableId) && it.columnsOrdinals.length === 1 && it.columnsOrdinals.includes(column8.ordinality);
25086
25087
  }) ?? null;
25087
25088
  const metadata = column8.metadata;
25088
25089
  if (column8.generatedType === "s" && (!metadata || !metadata.expression)) {
@@ -25097,7 +25098,7 @@ ${JSON.stringify(column8.metadata)}`
25097
25098
  ${JSON.stringify(column8.metadata)}`
25098
25099
  );
25099
25100
  }
25100
- const sequence = metadata?.seqId ? sequencesList.find((it) => it.oid === Number(metadata.seqId)) ?? null : null;
25101
+ const sequence = metadata?.seqId ? sequencesList.find((it) => Number(it.oid) === Number(metadata.seqId)) ?? null : null;
25101
25102
  columns.push({
25102
25103
  entityType: "columns",
25103
25104
  schema: table7.schema,
@@ -25127,10 +25128,12 @@ ${JSON.stringify(column8.metadata)}`
25127
25128
  });
25128
25129
  }
25129
25130
  for (const unique of constraintsList.filter((it) => it.type === "u")) {
25130
- const table7 = tablesList.find((it) => it.oid === unique.tableId);
25131
- const schema6 = namespaces.find((it) => it.oid === unique.schemaId);
25131
+ const table7 = tablesList.find((it) => Number(it.oid) === Number(unique.tableId));
25132
+ const schema6 = namespaces.find((it) => Number(it.oid) === Number(unique.schemaId));
25132
25133
  const columns2 = unique.columnsOrdinals.map((it) => {
25133
- const column8 = columnsList.find((column9) => column9.tableId === unique.tableId && column9.ordinality === it);
25134
+ const column8 = columnsList.find(
25135
+ (column9) => Number(column9.tableId) === Number(unique.tableId) && column9.ordinality === it
25136
+ );
25134
25137
  return column8.name;
25135
25138
  });
25136
25139
  uniques.push({
@@ -25144,10 +25147,12 @@ ${JSON.stringify(column8.metadata)}`
25144
25147
  });
25145
25148
  }
25146
25149
  for (const pk of constraintsList.filter((it) => it.type === "p")) {
25147
- const table7 = tablesList.find((it) => it.oid === pk.tableId);
25148
- const schema6 = namespaces.find((it) => it.oid === pk.schemaId);
25150
+ const table7 = tablesList.find((it) => Number(it.oid) === Number(pk.tableId));
25151
+ const schema6 = namespaces.find((it) => Number(it.oid) === Number(pk.schemaId));
25149
25152
  const columns2 = pk.columnsOrdinals.map((it) => {
25150
- const column8 = columnsList.find((column9) => column9.tableId === pk.tableId && column9.ordinality === it);
25153
+ const column8 = columnsList.find(
25154
+ (column9) => Number(column9.tableId) === Number(pk.tableId) && column9.ordinality === it
25155
+ );
25151
25156
  return column8.name;
25152
25157
  });
25153
25158
  pks.push({
@@ -25160,15 +25165,19 @@ ${JSON.stringify(column8.metadata)}`
25160
25165
  });
25161
25166
  }
25162
25167
  for (const fk6 of constraintsList.filter((it) => it.type === "f")) {
25163
- const table7 = tablesList.find((it) => it.oid === fk6.tableId);
25164
- const schema6 = namespaces.find((it) => it.oid === fk6.schemaId);
25165
- const tableTo = tablesList.find((it) => it.oid === fk6.tableToId);
25168
+ const table7 = tablesList.find((it) => Number(it.oid) === Number(fk6.tableId));
25169
+ const schema6 = namespaces.find((it) => Number(it.oid) === Number(fk6.schemaId));
25170
+ const tableTo = tablesList.find((it) => Number(it.oid) === Number(fk6.tableToId));
25166
25171
  const columns2 = fk6.columnsOrdinals.map((it) => {
25167
- const column8 = columnsList.find((column9) => column9.tableId === fk6.tableId && column9.ordinality === it);
25172
+ const column8 = columnsList.find(
25173
+ (column9) => Number(column9.tableId) === Number(fk6.tableId) && column9.ordinality === it
25174
+ );
25168
25175
  return column8.name;
25169
25176
  });
25170
25177
  const columnsTo = fk6.columnsToOrdinals.map((it) => {
25171
- const column8 = columnsList.find((column9) => column9.tableId === fk6.tableToId && column9.ordinality === it);
25178
+ const column8 = columnsList.find(
25179
+ (column9) => Number(column9.tableId) === Number(fk6.tableToId) && column9.ordinality === it
25180
+ );
25172
25181
  return column8.name;
25173
25182
  });
25174
25183
  fks.push({
@@ -25186,8 +25195,8 @@ ${JSON.stringify(column8.metadata)}`
25186
25195
  });
25187
25196
  }
25188
25197
  for (const check of constraintsList.filter((it) => it.type === "c")) {
25189
- const table7 = tablesList.find((it) => it.oid === check.tableId);
25190
- const schema6 = namespaces.find((it) => it.oid === check.schemaId);
25198
+ const table7 = tablesList.find((it) => Number(it.oid) === Number(check.tableId));
25199
+ const schema6 = namespaces.find((it) => Number(it.oid) === Number(check.schemaId));
25191
25200
  checks.push({
25192
25201
  entityType: "checks",
25193
25202
  schema: schema6.name,
@@ -25248,10 +25257,10 @@ ${JSON.stringify(column8.metadata)}`
25248
25257
  });
25249
25258
  for (const idx of idxs) {
25250
25259
  const { metadata } = idx;
25251
- const forUnique = metadata.isUnique && constraintsList.some((x6) => x6.type === "u" && x6.indexId === idx.oid);
25252
- const forPK = metadata.isPrimary && constraintsList.some((x6) => x6.type === "p" && x6.indexId === idx.oid);
25260
+ const forUnique = metadata.isUnique && constraintsList.some((x6) => x6.type === "u" && Number(x6.indexId) === Number(idx.oid));
25261
+ const forPK = metadata.isPrimary && constraintsList.some((x6) => x6.type === "p" && Number(x6.indexId) === Number(idx.oid));
25253
25262
  const expr = splitExpressions(metadata.expression);
25254
- const table7 = tablesList.find((it) => it.oid === idx.metadata.tableId);
25263
+ const table7 = tablesList.find((it) => Number(it.oid) === Number(idx.metadata.tableId));
25255
25264
  const nonColumnsCount = metadata.columnOrdinals.reduce((acc, it) => {
25256
25265
  if (it === 0) acc += 1;
25257
25266
  return acc;
@@ -25283,7 +25292,7 @@ ${JSON.stringify(column8.metadata)}`
25283
25292
  k6 += 1;
25284
25293
  } else {
25285
25294
  const column8 = columnsList.find((column9) => {
25286
- return column9.tableId === metadata.tableId && column9.ordinality === ordinal;
25295
+ return Number(column9.tableId) === Number(metadata.tableId) && column9.ordinality === ordinal;
25287
25296
  });
25288
25297
  if (!column8) throw new Error(`missing column: ${metadata.tableId}:${ordinal}`);
25289
25298
  const options = opts[i7];
@@ -25332,7 +25341,7 @@ ${JSON.stringify(column8.metadata)}`
25332
25341
  progressCallback("indexes", indexesCount, "fetching");
25333
25342
  progressCallback("tables", tableCount, "done");
25334
25343
  for (const it of columnsList.filter((x6) => x6.kind === "m" || x6.kind === "v")) {
25335
- const view6 = viewsList.find((x6) => x6.oid === it.tableId);
25344
+ const view6 = viewsList.find((x6) => Number(x6.oid) === Number(it.tableId));
25336
25345
  const typeDimensions = it.type.split("[]").length - 1;
25337
25346
  const enumType2 = it.typeId in groupedEnums ? groupedEnums[it.typeId] : it.typeId in groupedArrEnums ? groupedArrEnums[it.typeId] : null;
25338
25347
  let columnTypeMapped = enumType2 ? enumType2.name : it.type.replace("[]", "");
@@ -25355,8 +25364,8 @@ ${JSON.stringify(column8.metadata)}`
25355
25364
  }
25356
25365
  for (const view6 of viewsList) {
25357
25366
  tableCount += 1;
25358
- const accessMethod = view6.accessMethod === 0 ? null : ams.find((it) => it.oid === view6.accessMethod);
25359
- const tablespace = view6.tablespaceid === 0 ? null : tablespaces.find((it) => it.oid === view6.tablespaceid).name;
25367
+ const accessMethod = Number(view6.accessMethod) === 0 ? null : ams.find((it) => Number(it.oid) === Number(view6.accessMethod));
25368
+ const tablespace = Number(view6.tablespaceid) === 0 ? null : tablespaces.find((it) => Number(it.oid) === Number(view6.tablespaceid)).name;
25360
25369
  const definition = parseViewDefinition(view6.definition);
25361
25370
  const withOpts = wrapRecord(
25362
25371
  view6.options?.reduce((acc, it) => {
@@ -34395,7 +34404,7 @@ var require_websocket = __commonJS({
34395
34404
  var EventEmitter = require("events");
34396
34405
  var https2 = require("https");
34397
34406
  var http3 = require("http");
34398
- var net2 = require("net");
34407
+ var net = require("net");
34399
34408
  var tls = require("tls");
34400
34409
  var { randomBytes, createHash: createHash5 } = require("crypto");
34401
34410
  var { Duplex, Readable: Readable6 } = require("stream");
@@ -35126,12 +35135,12 @@ var require_websocket = __commonJS({
35126
35135
  }
35127
35136
  function netConnect(options) {
35128
35137
  options.path = options.socketPath;
35129
- return net2.connect(options);
35138
+ return net.connect(options);
35130
35139
  }
35131
35140
  function tlsConnect(options) {
35132
35141
  options.path = void 0;
35133
35142
  if (!options.servername && options.servername !== "") {
35134
- options.servername = net2.isIP(options.host) ? "" : options.host;
35143
+ options.servername = net.isIP(options.host) ? "" : options.host;
35135
35144
  }
35136
35145
  return tls.connect(options);
35137
35146
  }
@@ -39450,7 +39459,7 @@ var init_timing = __esm({
39450
39459
  "../node_modules/.pnpm/@smithy+node-http-handler@4.4.5/node_modules/@smithy/node-http-handler/dist-es/timing.js"() {
39451
39460
  "use strict";
39452
39461
  timing = {
39453
- setTimeout: (cb, ms2) => setTimeout(cb, ms2),
39462
+ setTimeout: (cb, ms) => setTimeout(cb, ms),
39454
39463
  clearTimeout: (timeoutId) => clearTimeout(timeoutId)
39455
39464
  };
39456
39465
  }
@@ -41338,13 +41347,13 @@ var init_schema_date_utils = __esm({
41338
41347
  if (!matches) {
41339
41348
  throw new TypeError(`Invalid RFC3339 timestamp format ${value}`);
41340
41349
  }
41341
- const [, yearStr, monthStr, dayStr, hours, minutes, seconds, , ms2, offsetStr] = matches;
41350
+ const [, yearStr, monthStr, dayStr, hours, minutes, seconds, , ms, offsetStr] = matches;
41342
41351
  range(monthStr, 1, 12);
41343
41352
  range(dayStr, 1, 31);
41344
41353
  range(hours, 0, 23);
41345
41354
  range(minutes, 0, 59);
41346
41355
  range(seconds, 0, 60);
41347
- const date2 = new Date(Date.UTC(Number(yearStr), Number(monthStr) - 1, Number(dayStr), Number(hours), Number(minutes), Number(seconds), Number(ms2) ? Math.round(parseFloat(`0.${ms2}`) * 1e3) : 0));
41356
+ const date2 = new Date(Date.UTC(Number(yearStr), Number(monthStr) - 1, Number(dayStr), Number(hours), Number(minutes), Number(seconds), Number(ms) ? Math.round(parseFloat(`0.${ms}`) * 1e3) : 0));
41348
41357
  date2.setUTCFullYear(Number(yearStr));
41349
41358
  if (offsetStr.toUpperCase() != "Z") {
41350
41359
  const [, sign2, offsetH, offsetM] = /([+-])(\d\d):(\d\d)/.exec(offsetStr) || [void 0, "+", 0, 0];
@@ -61358,8 +61367,8 @@ var require_datetime2 = __commonJS({
61358
61367
  if (!(object instanceof Date)) {
61359
61368
  throw new errors_1.InvalidArgumentError(`a Date instance was expected, got "${object}"`);
61360
61369
  }
61361
- const ms2 = object.getTime() - TIMESHIFT;
61362
- const us = ms2 * 1e3;
61370
+ const ms = object.getTime() - TIMESHIFT;
61371
+ const us = ms * 1e3;
61363
61372
  buf.writeInt32(8);
61364
61373
  buf.writeInt64(us);
61365
61374
  }
@@ -61369,12 +61378,12 @@ var require_datetime2 = __commonJS({
61369
61378
  return ctx.postDecode(this, us2 + BI_TIMESHIFT_US);
61370
61379
  }
61371
61380
  const us = Number(buf.readBigInt64());
61372
- let ms2 = Math.round(us / 1e3);
61373
- if (Math.abs(us % 1e3) === 500 && Math.abs(ms2) % 2 === 1) {
61374
- ms2 -= 1;
61381
+ let ms = Math.round(us / 1e3);
61382
+ if (Math.abs(us % 1e3) === 500 && Math.abs(ms) % 2 === 1) {
61383
+ ms -= 1;
61375
61384
  }
61376
- ms2 += TIMESHIFT;
61377
- return new Date(ms2);
61385
+ ms += TIMESHIFT;
61386
+ return new Date(ms);
61378
61387
  }
61379
61388
  };
61380
61389
  exports2.DateTimeCodec = DateTimeCodec;
@@ -61395,8 +61404,8 @@ var require_datetime2 = __commonJS({
61395
61404
  if (!(object instanceof datetime_1.LocalDateTime)) {
61396
61405
  throw new errors_1.InvalidArgumentError(`a LocalDateTime instance was expected, got "${object}"`);
61397
61406
  }
61398
- const ms2 = BigInt(datetime_1.localDateInstances.get(object).getTime() - TIMESHIFT);
61399
- let us = ms2 * 1000n + BigInt(object.hour * 36e8 + object.minute * 6e7 + object.second * 1e6 + object.millisecond * 1e3 + object.microsecond);
61407
+ const ms = BigInt(datetime_1.localDateInstances.get(object).getTime() - TIMESHIFT);
61408
+ let us = ms * 1000n + BigInt(object.hour * 36e8 + object.minute * 6e7 + object.second * 1e6 + object.millisecond * 1e3 + object.microsecond);
61400
61409
  if (object.nanosecond === 500 && Math.abs(object.microsecond) % 2 === 1 || object.nanosecond > 500) {
61401
61410
  us += 1n;
61402
61411
  }
@@ -61410,13 +61419,13 @@ var require_datetime2 = __commonJS({
61410
61419
  }
61411
61420
  const bi_ms = bi_us / 1000n;
61412
61421
  let us = Number(bi_us - bi_ms * 1000n);
61413
- let ms2 = Number(bi_ms);
61422
+ let ms = Number(bi_ms);
61414
61423
  if (us < 0) {
61415
61424
  us += 1e3;
61416
- ms2 -= 1;
61425
+ ms -= 1;
61417
61426
  }
61418
- ms2 += TIMESHIFT;
61419
- const date2 = new Date(ms2);
61427
+ ms += TIMESHIFT;
61428
+ const date2 = new Date(ms);
61420
61429
  return new datetime_1.LocalDateTime(date2.getUTCFullYear(), date2.getUTCMonth() + 1, date2.getUTCDate(), date2.getUTCHours(), date2.getUTCMinutes(), date2.getUTCSeconds(), date2.getUTCMilliseconds(), us);
61421
61430
  }
61422
61431
  };
@@ -61478,13 +61487,13 @@ var require_datetime2 = __commonJS({
61478
61487
  }
61479
61488
  let us = Number(bius);
61480
61489
  let seconds = Math.floor(us / 1e6);
61481
- const ms2 = Math.floor(us % 1e6 / 1e3);
61482
- us = us % 1e6 - ms2 * 1e3;
61490
+ const ms = Math.floor(us % 1e6 / 1e3);
61491
+ us = us % 1e6 - ms * 1e3;
61483
61492
  let minutes = Math.floor(seconds / 60);
61484
61493
  seconds = Math.floor(seconds % 60);
61485
61494
  const hours = Math.floor(minutes / 60);
61486
61495
  minutes = Math.floor(minutes % 60);
61487
- return new datetime_1.LocalTime(hours, minutes, seconds, ms2, us);
61496
+ return new datetime_1.LocalTime(hours, minutes, seconds, ms, us);
61488
61497
  }
61489
61498
  };
61490
61499
  exports2.LocalTimeCodec = LocalTimeCodec;
@@ -61561,14 +61570,14 @@ var require_datetime2 = __commonJS({
61561
61570
  const biMillion = 1000000n;
61562
61571
  const biSeconds = bius / biMillion;
61563
61572
  let us = Number(bius - biSeconds * biMillion);
61564
- const ms2 = Math.floor(us / 1e3);
61573
+ const ms = Math.floor(us / 1e3);
61565
61574
  us = us % 1e3;
61566
61575
  let seconds = Number(biSeconds);
61567
61576
  let minutes = Math.floor(seconds / 60);
61568
61577
  seconds = Math.floor(seconds % 60);
61569
61578
  const hours = Math.floor(minutes / 60);
61570
61579
  minutes = Math.floor(minutes % 60);
61571
- return new datetime_1.Duration(0, 0, 0, 0, hours * sign2, minutes * sign2, seconds * sign2, ms2 * sign2, us * sign2);
61580
+ return new datetime_1.Duration(0, 0, 0, 0, hours * sign2, minutes * sign2, seconds * sign2, ms * sign2, us * sign2);
61572
61581
  }
61573
61582
  };
61574
61583
  exports2.DurationCodec = DurationCodec;
@@ -61614,7 +61623,7 @@ var require_datetime2 = __commonJS({
61614
61623
  const million = BigInt(1e6);
61615
61624
  const biSeconds = bius / million;
61616
61625
  let us = Number(bius - biSeconds * million);
61617
- const ms2 = Math.trunc(us / 1e3);
61626
+ const ms = Math.trunc(us / 1e3);
61618
61627
  us = us % 1e3;
61619
61628
  let seconds = Number(biSeconds);
61620
61629
  let minutes = Math.trunc(seconds / 60);
@@ -61625,7 +61634,7 @@ var require_datetime2 = __commonJS({
61625
61634
  days = Math.trunc(days % 7);
61626
61635
  const years = Math.trunc(months2 / 12);
61627
61636
  months2 = Math.trunc(months2 % 12);
61628
- return new datetime_1.RelativeDuration(years, months2, weeks, days, hours * sign2, minutes * sign2, seconds * sign2, ms2 * sign2, us * sign2);
61637
+ return new datetime_1.RelativeDuration(years, months2, weeks, days, hours * sign2, minutes * sign2, seconds * sign2, ms * sign2, us * sign2);
61629
61638
  }
61630
61639
  };
61631
61640
  exports2.RelativeDurationCodec = RelativeDurationCodec;
@@ -71789,41 +71798,41 @@ var require_ms = __commonJS({
71789
71798
  return void 0;
71790
71799
  }
71791
71800
  }
71792
- function fmtShort(ms2) {
71793
- var msAbs = Math.abs(ms2);
71801
+ function fmtShort(ms) {
71802
+ var msAbs = Math.abs(ms);
71794
71803
  if (msAbs >= d6) {
71795
- return Math.round(ms2 / d6) + "d";
71804
+ return Math.round(ms / d6) + "d";
71796
71805
  }
71797
71806
  if (msAbs >= h7) {
71798
- return Math.round(ms2 / h7) + "h";
71807
+ return Math.round(ms / h7) + "h";
71799
71808
  }
71800
71809
  if (msAbs >= m7) {
71801
- return Math.round(ms2 / m7) + "m";
71810
+ return Math.round(ms / m7) + "m";
71802
71811
  }
71803
71812
  if (msAbs >= s7) {
71804
- return Math.round(ms2 / s7) + "s";
71813
+ return Math.round(ms / s7) + "s";
71805
71814
  }
71806
- return ms2 + "ms";
71815
+ return ms + "ms";
71807
71816
  }
71808
- function fmtLong(ms2) {
71809
- var msAbs = Math.abs(ms2);
71817
+ function fmtLong(ms) {
71818
+ var msAbs = Math.abs(ms);
71810
71819
  if (msAbs >= d6) {
71811
- return plural2(ms2, msAbs, d6, "day");
71820
+ return plural2(ms, msAbs, d6, "day");
71812
71821
  }
71813
71822
  if (msAbs >= h7) {
71814
- return plural2(ms2, msAbs, h7, "hour");
71823
+ return plural2(ms, msAbs, h7, "hour");
71815
71824
  }
71816
71825
  if (msAbs >= m7) {
71817
- return plural2(ms2, msAbs, m7, "minute");
71826
+ return plural2(ms, msAbs, m7, "minute");
71818
71827
  }
71819
71828
  if (msAbs >= s7) {
71820
- return plural2(ms2, msAbs, s7, "second");
71829
+ return plural2(ms, msAbs, s7, "second");
71821
71830
  }
71822
- return ms2 + " ms";
71831
+ return ms + " ms";
71823
71832
  }
71824
- function plural2(ms2, msAbs, n6, name) {
71833
+ function plural2(ms, msAbs, n6, name) {
71825
71834
  var isPlural = msAbs >= n6 * 1.5;
71826
- return Math.round(ms2 / n6) + " " + name + (isPlural ? "s" : "");
71835
+ return Math.round(ms / n6) + " " + name + (isPlural ? "s" : "");
71827
71836
  }
71828
71837
  }
71829
71838
  });
@@ -71867,8 +71876,8 @@ var require_common2 = __commonJS({
71867
71876
  }
71868
71877
  const self2 = debug;
71869
71878
  const curr = Number(/* @__PURE__ */ new Date());
71870
- const ms2 = curr - (prevTime || curr);
71871
- self2.diff = ms2;
71879
+ const ms = curr - (prevTime || curr);
71880
+ self2.diff = ms;
71872
71881
  self2.prev = prevTime;
71873
71882
  self2.curr = curr;
71874
71883
  prevTime = curr;
@@ -87371,11 +87380,11 @@ var require_TokenExpiredError = __commonJS({
87371
87380
  var require_timespan = __commonJS({
87372
87381
  "../node_modules/.pnpm/jsonwebtoken@9.0.2/node_modules/jsonwebtoken/lib/timespan.js"(exports2, module2) {
87373
87382
  "use strict";
87374
- var ms2 = require_ms();
87383
+ var ms = require_ms();
87375
87384
  module2.exports = function(time2, iat) {
87376
87385
  var timestamp = iat || Math.floor(Date.now() / 1e3);
87377
87386
  if (typeof time2 === "string") {
87378
- var milliseconds = ms2(time2);
87387
+ var milliseconds = ms(time2);
87379
87388
  if (typeof milliseconds === "undefined") {
87380
87389
  return;
87381
87390
  }
@@ -101913,7 +101922,7 @@ var require_dist = __commonJS({
101913
101922
  };
101914
101923
  Object.defineProperty(exports2, "__esModule", { value: true });
101915
101924
  exports2.Agent = void 0;
101916
- var net2 = __importStar2(require("net"));
101925
+ var net = __importStar2(require("net"));
101917
101926
  var http3 = __importStar2(require("http"));
101918
101927
  var https_1 = require("https");
101919
101928
  __exportStar2(require_helpers2(), exports2);
@@ -101953,7 +101962,7 @@ var require_dist = __commonJS({
101953
101962
  if (!this.sockets[name]) {
101954
101963
  this.sockets[name] = [];
101955
101964
  }
101956
- const fakeSocket = new net2.Socket({ writable: false });
101965
+ const fakeSocket = new net.Socket({ writable: false });
101957
101966
  this.sockets[name].push(fakeSocket);
101958
101967
  this.totalSocketCount++;
101959
101968
  return fakeSocket;
@@ -102165,7 +102174,7 @@ var require_dist2 = __commonJS({
102165
102174
  };
102166
102175
  Object.defineProperty(exports2, "__esModule", { value: true });
102167
102176
  exports2.HttpsProxyAgent = void 0;
102168
- var net2 = __importStar2(require("net"));
102177
+ var net = __importStar2(require("net"));
102169
102178
  var tls = __importStar2(require("tls"));
102170
102179
  var assert_1 = __importDefault2(require("assert"));
102171
102180
  var debug_1 = __importDefault2(require_src2());
@@ -102174,7 +102183,7 @@ var require_dist2 = __commonJS({
102174
102183
  var parse_proxy_response_1 = require_parse_proxy_response();
102175
102184
  var debug = (0, debug_1.default)("https-proxy-agent");
102176
102185
  var setServernameFromNonIpHost = (options) => {
102177
- if (options.servername === void 0 && options.host && !net2.isIP(options.host)) {
102186
+ if (options.servername === void 0 && options.host && !net.isIP(options.host)) {
102178
102187
  return {
102179
102188
  ...options,
102180
102189
  servername: options.host
@@ -102214,10 +102223,10 @@ var require_dist2 = __commonJS({
102214
102223
  socket = tls.connect(setServernameFromNonIpHost(this.connectOpts));
102215
102224
  } else {
102216
102225
  debug("Creating `net.Socket`: %o", this.connectOpts);
102217
- socket = net2.connect(this.connectOpts);
102226
+ socket = net.connect(this.connectOpts);
102218
102227
  }
102219
102228
  const headers = typeof this.proxyHeaders === "function" ? this.proxyHeaders() : { ...this.proxyHeaders };
102220
- const host = net2.isIPv6(opts.host) ? `[${opts.host}]` : opts.host;
102229
+ const host = net.isIPv6(opts.host) ? `[${opts.host}]` : opts.host;
102221
102230
  let payload = `CONNECT ${host}:${opts.port} HTTP/1.1\r
102222
102231
  `;
102223
102232
  if (proxy.username || proxy.password) {
@@ -102250,7 +102259,7 @@ var require_dist2 = __commonJS({
102250
102259
  return socket;
102251
102260
  }
102252
102261
  socket.destroy();
102253
- const fakeSocket = new net2.Socket({ writable: false });
102262
+ const fakeSocket = new net.Socket({ writable: false });
102254
102263
  fakeSocket.readable = true;
102255
102264
  req.once("socket", (s7) => {
102256
102265
  debug("Replaying proxy buffer for failed request");
@@ -102315,7 +102324,7 @@ var require_dist3 = __commonJS({
102315
102324
  };
102316
102325
  Object.defineProperty(exports2, "__esModule", { value: true });
102317
102326
  exports2.HttpProxyAgent = void 0;
102318
- var net2 = __importStar2(require("net"));
102327
+ var net = __importStar2(require("net"));
102319
102328
  var tls = __importStar2(require("tls"));
102320
102329
  var debug_1 = __importDefault2(require_src2());
102321
102330
  var events_1 = require("events");
@@ -102388,7 +102397,7 @@ var require_dist3 = __commonJS({
102388
102397
  socket = tls.connect(this.connectOpts);
102389
102398
  } else {
102390
102399
  debug("Creating `net.Socket`: %o", this.connectOpts);
102391
- socket = net2.connect(this.connectOpts);
102400
+ socket = net.connect(this.connectOpts);
102392
102401
  }
102393
102402
  await (0, events_1.once)(socket, "connect");
102394
102403
  return socket;
@@ -141268,7 +141277,7 @@ var require_connection = __commonJS({
141268
141277
  var _crypto = _interopRequireDefault(require("crypto"));
141269
141278
  var _os = _interopRequireDefault(require("os"));
141270
141279
  var tls = _interopRequireWildcard(require("tls"));
141271
- var net2 = _interopRequireWildcard(require("net"));
141280
+ var net = _interopRequireWildcard(require("net"));
141272
141281
  var _dns = _interopRequireDefault(require("dns"));
141273
141282
  var _constants = _interopRequireDefault(require("constants"));
141274
141283
  var _stream = require("stream");
@@ -142317,7 +142326,7 @@ var require_connection = __commonJS({
142317
142326
  async wrapWithTls(socket, signal) {
142318
142327
  signal.throwIfAborted();
142319
142328
  const secureContext = tls.createSecureContext(this.secureContextOptions);
142320
- const serverName = !net2.isIP(this.config.server) ? this.config.server : "";
142329
+ const serverName = !net.isIP(this.config.server) ? this.config.server : "";
142321
142330
  const encryptOptions = {
142322
142331
  host: this.config.server,
142323
142332
  socket,
@@ -145223,6 +145232,7 @@ __export(connections_exports, {
145223
145232
  connectToSQLite: () => connectToSQLite,
145224
145233
  connectToSingleStore: () => connectToSingleStore,
145225
145234
  prepareCockroach: () => prepareCockroach,
145235
+ prepareDuckDb: () => prepareDuckDb,
145226
145236
  prepareGelDB: () => prepareGelDB,
145227
145237
  preparePostgresDB: () => preparePostgresDB
145228
145238
  });
@@ -145239,11 +145249,10 @@ function parseMssqlUrl(url) {
145239
145249
  }
145240
145250
  };
145241
145251
  }
145242
- var import_net, ms, normalisePGliteUrl, preparePostgresDB, prepareCockroach, prepareGelDB, parseSingleStoreCredentials, connectToSingleStore, parseMysqlCredentials, connectToMySQL, parseMssqlCredentials, connectToMsSQL, prepareSqliteParams, preparePGliteParams, connectToSQLite, connectToLibSQL;
145252
+ var normalisePGliteUrl, preparePostgresDB, prepareDuckDb, prepareCockroach, prepareGelDB, parseSingleStoreCredentials, connectToSingleStore, parseMysqlCredentials, connectToMySQL, parseMssqlCredentials, connectToMsSQL, prepareSqliteParams, preparePGliteParams, connectToSQLite, connectToLibSQL;
145243
145253
  var init_connections = __esm({
145244
145254
  "src/cli/connections.ts"() {
145245
145255
  "use strict";
145246
- import_net = __toESM(require("net"));
145247
145256
  init_src();
145248
145257
  init_wrapper();
145249
145258
  init_utils();
@@ -145251,7 +145260,6 @@ var init_connections = __esm({
145251
145260
  init_when_json_met_bigint();
145252
145261
  init_utils3();
145253
145262
  init_outputs();
145254
- ms = (a6, b6) => Number(b6 - a6) / 1e6;
145255
145263
  normalisePGliteUrl = (it) => {
145256
145264
  if (it.startsWith("file:")) {
145257
145265
  return it.substring(5);
@@ -145375,7 +145383,13 @@ var init_connections = __esm({
145375
145383
  }
145376
145384
  return results;
145377
145385
  };
145378
- return { packageName: "pglite", query, proxy, transactionProxy, migrate: migrateFn };
145386
+ return {
145387
+ packageName: "pglite",
145388
+ query,
145389
+ proxy,
145390
+ transactionProxy,
145391
+ migrate: migrateFn
145392
+ };
145379
145393
  }
145380
145394
  assertUnreachable(driver2);
145381
145395
  }
@@ -145406,13 +145420,13 @@ var init_connections = __esm({
145406
145420
  return pg.types.getTypeParser(typeId, format2);
145407
145421
  }
145408
145422
  };
145409
- const pool = "url" in credentials ? new pg.Pool({ connectionString: credentials.url, max: 1 }) : new pg.Pool({ ...credentials, ssl, max: 1 });
145410
- const db = drizzle({ client: pool });
145423
+ const client = "url" in credentials ? new pg.Pool({ connectionString: credentials.url, max: 1 }) : new pg.Pool({ ...credentials, ssl, max: 1 });
145424
+ const db = drizzle({ client });
145411
145425
  const migrateFn = async (config) => {
145412
145426
  return migrate(db, config);
145413
145427
  };
145414
145428
  const query = async (sql, params) => {
145415
- const result2 = await pool.query({
145429
+ const result2 = await client.query({
145416
145430
  text: sql,
145417
145431
  values: params ?? [],
145418
145432
  types: types3
@@ -145422,7 +145436,7 @@ var init_connections = __esm({
145422
145436
  return result2.rows;
145423
145437
  };
145424
145438
  const proxy = async (params) => {
145425
- const result2 = await pool.query({
145439
+ const result2 = await client.query({
145426
145440
  text: params.sql,
145427
145441
  values: params.params,
145428
145442
  ...params.mode === "array" && { rowMode: "array" },
@@ -145434,7 +145448,7 @@ var init_connections = __esm({
145434
145448
  };
145435
145449
  const transactionProxy = async (queries) => {
145436
145450
  const results = [];
145437
- const tx = await pool.connect();
145451
+ const tx = await client.connect();
145438
145452
  try {
145439
145453
  await tx.query("BEGIN");
145440
145454
  for (const query2 of queries) {
@@ -145453,119 +145467,13 @@ var init_connections = __esm({
145453
145467
  }
145454
145468
  return results;
145455
145469
  };
145456
- const benchmarkQuery = async (client, sql, params) => {
145457
- const explainResult = await pool.query({
145458
- text: `EXPLAIN ANALYZE ${sql}`,
145459
- values: params ?? [],
145460
- types: types3
145461
- });
145462
- const stringifiedResult = JSON.stringify(explainResult.rows);
145463
- const planningMatch = stringifiedResult.match(/Planning Time:\s*([\d.]+)\s*ms/i);
145464
- const executionMatch = stringifiedResult.match(/Execution Time:\s*([\d.]+)\s*ms/i);
145465
- let planningTime = Number(planningMatch[1]);
145466
- let executionTime = Number(executionMatch[1]);
145467
- let querySentAt = 0n;
145468
- let firstDataAt = 0n;
145469
- let lastDataAt = 0n;
145470
- let lastRowParsedAt = 0n;
145471
- let queryCompletedAt = 0n;
145472
- let bytesReceived = 0;
145473
- let rowCount = 0;
145474
- let parseTime = 0;
145475
- let lastParseTime = 0;
145476
- const rowDescriptionListener = (data) => {
145477
- if (firstDataAt === 0n) {
145478
- firstDataAt = process.hrtime.bigint();
145479
- }
145480
- bytesReceived += data.length;
145481
- };
145482
- const originalRowListener = client.connection.listeners("dataRow")[0];
145483
- const wrappedRowListener = (data) => {
145484
- rowCount += 1;
145485
- const start = process.hrtime.bigint();
145486
- lastDataAt = start;
145487
- originalRowListener.apply(client.connection, [data]);
145488
- const end2 = process.hrtime.bigint();
145489
- lastRowParsedAt = end2;
145490
- lastParseTime = ms(start, end2);
145491
- parseTime += lastParseTime;
145492
- bytesReceived += data.length;
145493
- };
145494
- client.connection.removeAllListeners("dataRow");
145495
- client.connection.addListener("dataRow", wrappedRowListener);
145496
- client.connection.prependListener("rowDescription", rowDescriptionListener);
145497
- querySentAt = process.hrtime.bigint();
145498
- await client.query({
145499
- text: sql,
145500
- values: params,
145501
- types: types3
145502
- });
145503
- queryCompletedAt = process.hrtime.bigint();
145504
- client.connection.removeListener("rowDescription", rowDescriptionListener);
145505
- client.connection.removeAllListeners("dataRow");
145506
- client.connection.addListener("dataRow", originalRowListener);
145507
- let querySentTime = ms(querySentAt, firstDataAt) - executionTime - planningTime;
145508
- if (querySentTime < 0) {
145509
- const percent = 0.1;
145510
- const overflow = -querySentTime;
145511
- const keepForSent = overflow * percent;
145512
- const adjustedOverflow = overflow * (1 + percent);
145513
- const total2 = planningTime + executionTime;
145514
- const ratioPlanning = planningTime / total2;
145515
- const ratioExecution = executionTime / total2;
145516
- planningTime -= adjustedOverflow * ratioPlanning;
145517
- executionTime -= adjustedOverflow * ratioExecution;
145518
- querySentTime = keepForSent;
145519
- }
145520
- const networkLatencyBefore = querySentTime / 2;
145521
- const networkLatencyAfter = querySentTime / 2;
145522
- const downloadTime = ms(firstDataAt, lastDataAt) - (rowCount > 1 ? parseTime - lastParseTime : 0);
145523
- const total = ms(querySentAt, queryCompletedAt);
145524
- const calculatedTotal = networkLatencyBefore + planningTime + executionTime + networkLatencyAfter + downloadTime + parseTime + ms(lastRowParsedAt, queryCompletedAt);
145525
- const errorMargin = Math.abs(total - calculatedTotal);
145526
- return {
145527
- networkLatencyBefore,
145528
- planning: planningTime,
145529
- execution: executionTime,
145530
- networkLatencyAfter,
145531
- dataDownload: downloadTime,
145532
- dataParse: parseTime,
145533
- total,
145534
- errorMargin,
145535
- dataSize: bytesReceived
145536
- };
145537
- };
145538
- const benchmarkProxy = async ({ sql, params }, repeats) => {
145539
- let startAt = 0n;
145540
- let tcpConnectedAt = 0n;
145541
- let tlsConnectedAt = null;
145542
- let dbReadyAt = 0n;
145543
- const client = "url" in credentials ? new pg.Client({ connectionString: credentials.url }) : new pg.Client({ ...credentials, ssl });
145544
- client.connection.once("connect", () => {
145545
- tcpConnectedAt = process.hrtime.bigint();
145546
- });
145547
- client.connection.prependOnceListener("sslconnect", () => {
145548
- tlsConnectedAt = process.hrtime.bigint();
145549
- });
145550
- client.connection.prependOnceListener("readyForQuery", () => {
145551
- dbReadyAt = process.hrtime.bigint();
145552
- });
145553
- startAt = process.hrtime.bigint();
145554
- await client.connect();
145555
- const results = [];
145556
- for (let i7 = 0; i7 < repeats; i7++) {
145557
- const r7 = await benchmarkQuery(client, sql, params);
145558
- results.push(r7);
145559
- }
145560
- await client.end();
145561
- return {
145562
- tcpHandshake: ms(startAt, tcpConnectedAt),
145563
- tlsHandshake: tlsConnectedAt ? ms(tcpConnectedAt, tlsConnectedAt) : null,
145564
- dbHandshake: ms(tlsConnectedAt ?? tcpConnectedAt, dbReadyAt),
145565
- queries: results
145566
- };
145470
+ return {
145471
+ packageName: "pg",
145472
+ query,
145473
+ proxy,
145474
+ transactionProxy,
145475
+ migrate: migrateFn
145567
145476
  };
145568
- return { packageName: "pg", query, proxy, transactionProxy, benchmarkProxy, migrate: migrateFn };
145569
145477
  }
145570
145478
  if (await checkPackage("postgres")) {
145571
145479
  console.log(
@@ -145616,7 +145524,13 @@ var init_connections = __esm({
145616
145524
  }
145617
145525
  return results;
145618
145526
  };
145619
- return { packageName: "postgres", query, proxy, transactionProxy, migrate: migrateFn };
145527
+ return {
145528
+ packageName: "postgres",
145529
+ query,
145530
+ proxy,
145531
+ transactionProxy,
145532
+ migrate: migrateFn
145533
+ };
145620
145534
  }
145621
145535
  if (await checkPackage("@vercel/postgres")) {
145622
145536
  console.log(
@@ -145697,7 +145611,13 @@ var init_connections = __esm({
145697
145611
  }
145698
145612
  return results;
145699
145613
  };
145700
- return { packageName: "@vercel/postgres", query, proxy, transactionProxy, migrate: migrateFn };
145614
+ return {
145615
+ packageName: "@vercel/postgres",
145616
+ query,
145617
+ proxy,
145618
+ transactionProxy,
145619
+ migrate: migrateFn
145620
+ };
145701
145621
  }
145702
145622
  if (await checkPackage("@neondatabase/serverless")) {
145703
145623
  console.log(
@@ -145710,7 +145630,11 @@ var init_connections = __esm({
145710
145630
  "'@neondatabase/serverless' can only connect to remote Neon/Vercel Postgres/Supabase instances through a websocket"
145711
145631
  )
145712
145632
  );
145713
- const { Pool, neonConfig, types: pgTypes } = require("@neondatabase/serverless");
145633
+ const {
145634
+ Pool,
145635
+ neonConfig,
145636
+ types: pgTypes
145637
+ } = require("@neondatabase/serverless");
145714
145638
  const { drizzle } = require("drizzle-orm/neon-serverless");
145715
145639
  const { migrate } = require("drizzle-orm/neon-serverless/migrator");
145716
145640
  const ssl = "ssl" in credentials ? credentials.ssl === "prefer" || credentials.ssl === "require" || credentials.ssl === "allow" ? { rejectUnauthorized: false } : credentials.ssl === "verify-full" ? {} : credentials.ssl : {};
@@ -145780,7 +145704,13 @@ var init_connections = __esm({
145780
145704
  }
145781
145705
  return results;
145782
145706
  };
145783
- return { packageName: "@neondatabase/serverless", query, proxy, transactionProxy, migrate: migrateFn };
145707
+ return {
145708
+ packageName: "@neondatabase/serverless",
145709
+ query,
145710
+ proxy,
145711
+ transactionProxy,
145712
+ migrate: migrateFn
145713
+ };
145784
145714
  }
145785
145715
  if (await checkPackage("bun")) {
145786
145716
  console.log(withStyle.info(`Using 'bun' driver for database querying`));
@@ -145831,6 +145761,111 @@ var init_connections = __esm({
145831
145761
  console.warn("For the 'bun' driver, run your script using: bun --bun");
145832
145762
  process.exit(1);
145833
145763
  };
145764
+ prepareDuckDb = async (credentials) => {
145765
+ if (await checkPackage("duckdb")) {
145766
+ console.log(withStyle.info(`Using 'duckdb' driver for database querying`));
145767
+ const duckdb = require("duckdb");
145768
+ const client = await new Promise((resolve2, reject) => {
145769
+ const db = new duckdb.Database(credentials.url, (err2) => {
145770
+ if (err2) {
145771
+ reject(err2);
145772
+ }
145773
+ resolve2(db);
145774
+ });
145775
+ });
145776
+ const query = async (sql, params = []) => new Promise((resolve2, reject) => {
145777
+ client.all(sql, ...params, (err2, rows) => {
145778
+ if (err2) {
145779
+ reject(err2);
145780
+ }
145781
+ resolve2(rows);
145782
+ });
145783
+ });
145784
+ const proxy = async (params) => {
145785
+ const rows = await query(params.sql, params.params);
145786
+ return params.mode === "array" ? rows.map((row) => Object.values(row)) : rows;
145787
+ };
145788
+ const transactionProxy = async (queries) => {
145789
+ const results = [];
145790
+ const tx = client.connect();
145791
+ try {
145792
+ tx.run("BEGIN");
145793
+ for (const query2 of queries) {
145794
+ const rows = await new Promise((resolve2, reject) => {
145795
+ client.all(query2.sql, (err2, rows2) => {
145796
+ if (err2) {
145797
+ reject(err2);
145798
+ }
145799
+ resolve2(rows2);
145800
+ });
145801
+ });
145802
+ results.push(rows);
145803
+ }
145804
+ tx.run("COMMIT");
145805
+ } catch (error3) {
145806
+ tx.run("ROLLBACK");
145807
+ results.push(error3);
145808
+ } finally {
145809
+ tx.close();
145810
+ }
145811
+ return results;
145812
+ };
145813
+ return {
145814
+ packageName: "duckdb",
145815
+ query,
145816
+ proxy,
145817
+ transactionProxy,
145818
+ migrate: () => {
145819
+ throw new Error("DuckDB does not support migrations");
145820
+ }
145821
+ };
145822
+ }
145823
+ if (await checkPackage("@duckdb/node-api")) {
145824
+ console.log(
145825
+ withStyle.info(`Using '@duckdb/node-api' driver for database querying`)
145826
+ );
145827
+ const { DuckDBInstance } = require("@duckdb/node-api");
145828
+ const instance = await DuckDBInstance.create(credentials.url);
145829
+ const client = await instance.connect();
145830
+ const query = async (sql, params = []) => {
145831
+ const result2 = await client.run(sql, params);
145832
+ const rows = await result2.getRowObjectsJson();
145833
+ return rows;
145834
+ };
145835
+ const proxy = async (params) => {
145836
+ const result2 = await client.run(params.sql, params.params);
145837
+ return params.mode === "array" ? await result2.getRowsJson() : await result2.getRowObjectsJson();
145838
+ };
145839
+ const transactionProxy = async (queries) => {
145840
+ const results = [];
145841
+ try {
145842
+ await client.run("BEGIN");
145843
+ for (const query2 of queries) {
145844
+ const result2 = await client.run(query2.sql);
145845
+ results.push(await result2.getRowObjectsJson());
145846
+ }
145847
+ await client.run("COMMIT");
145848
+ } catch (error3) {
145849
+ await client.run("ROLLBACK");
145850
+ results.push(error3);
145851
+ }
145852
+ return results;
145853
+ };
145854
+ return {
145855
+ packageName: "@duckdb/node-api",
145856
+ query,
145857
+ proxy,
145858
+ transactionProxy,
145859
+ migrate: () => {
145860
+ throw new Error("DuckDB does not support migrations");
145861
+ }
145862
+ };
145863
+ }
145864
+ console.error(
145865
+ "To connect to DuckDb database - please install either of 'duckdb', '@duckdb/node-api' drivers"
145866
+ );
145867
+ process.exit(1);
145868
+ };
145834
145869
  prepareCockroach = async (credentials) => {
145835
145870
  if (await checkPackage("pg")) {
145836
145871
  const { default: pg } = require("pg");
@@ -145883,9 +145918,7 @@ var init_connections = __esm({
145883
145918
  };
145884
145919
  return { query, proxy, migrate: migrateFn };
145885
145920
  }
145886
- console.error(
145887
- "To connect to Cockroach - please install 'pg' package"
145888
- );
145921
+ console.error("To connect to Cockroach - please install 'pg' package");
145889
145922
  process.exit(1);
145890
145923
  };
145891
145924
  prepareGelDB = async (credentials) => {
@@ -145944,9 +145977,7 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
145944
145977
  };
145945
145978
  return { packageName: "gel", query, proxy, transactionProxy };
145946
145979
  }
145947
- console.error(
145948
- "To connect to gel database - please install 'edgedb' driver"
145949
- );
145980
+ console.error("To connect to gel database - please install 'edgedb' driver");
145950
145981
  process.exit(1);
145951
145982
  };
145952
145983
  parseSingleStoreCredentials = (credentials) => {
@@ -146060,6 +146091,7 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
146060
146091
  }
146061
146092
  return next();
146062
146093
  };
146094
+ await connection.connect();
146063
146095
  const query = async (sql, params) => {
146064
146096
  const res = await connection.execute({
146065
146097
  sql,
@@ -146099,156 +146131,11 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
146099
146131
  }
146100
146132
  return results;
146101
146133
  };
146102
- const benchmarkQuery = async (newConnection, sql, params) => {
146103
- const explainResult = await connection.query({
146104
- sql: `EXPLAIN ANALYZE ${sql}`,
146105
- values: params ?? [],
146106
- typeCast
146107
- });
146108
- const stringifiedResult = JSON.stringify(explainResult[0]);
146109
- const timeMatch = stringifiedResult.match(
146110
- /actual time=([0-9.eE+-]+)\.\.([0-9.eE+-]+)/
146111
- );
146112
- const lastRowTime = Number(timeMatch[2]);
146113
- let executionTime = lastRowTime;
146114
- let querySentAt = 0n;
146115
- let firstDataAt = 0n;
146116
- let lastDataAt = 0n;
146117
- let lastRowParsedAt = 0n;
146118
- let queryCompletedAt = 0n;
146119
- let bytesReceived = 0;
146120
- let rowCount = 0;
146121
- let parseTime = 0;
146122
- let lastParseTime = 0;
146123
- querySentAt = process.hrtime.bigint();
146124
- await new Promise((resolve2, reject) => {
146125
- const query2 = newConnection.query({
146126
- sql,
146127
- values: params ?? [],
146128
- typeCast
146129
- });
146130
- const originalRowHandler = query2.row;
146131
- let packets = 0;
146132
- const wrappedRowListener = (packet, connection2) => {
146133
- packets += 1;
146134
- if (firstDataAt === 0n) {
146135
- firstDataAt = process.hrtime.bigint();
146136
- bytesReceived += packet.start;
146137
- }
146138
- const start = process.hrtime.bigint();
146139
- lastDataAt = start;
146140
- const res = originalRowHandler.apply(query2, [packet, connection2]);
146141
- const end2 = process.hrtime.bigint();
146142
- lastRowParsedAt = end2;
146143
- lastParseTime = ms(start, end2);
146144
- parseTime += lastParseTime;
146145
- bytesReceived += packet.length();
146146
- if (!res || packet.isEOF()) {
146147
- return res;
146148
- }
146149
- return wrappedRowListener;
146150
- };
146151
- query2.row = wrappedRowListener;
146152
- query2.on("result", () => {
146153
- rowCount += 1;
146154
- });
146155
- query2.on("error", (err2) => {
146156
- reject(err2);
146157
- });
146158
- query2.on("end", () => {
146159
- resolve2();
146160
- });
146161
- });
146162
- queryCompletedAt = process.hrtime.bigint();
146163
- let querySentTime = ms(querySentAt, firstDataAt) - executionTime;
146164
- if (querySentTime < 0) {
146165
- const percent = 0.1;
146166
- const overflow = -querySentTime;
146167
- const keepForSent = overflow * percent;
146168
- const adjustedOverflow = overflow * (1 + percent);
146169
- const total2 = executionTime;
146170
- const ratioExecution = executionTime / total2;
146171
- executionTime -= adjustedOverflow * ratioExecution;
146172
- querySentTime = keepForSent;
146173
- }
146174
- const networkLatencyBefore = querySentTime / 2;
146175
- const networkLatencyAfter = querySentTime / 2;
146176
- const downloadTime = ms(firstDataAt, lastDataAt) - (rowCount > 1 ? parseTime - lastParseTime : 0);
146177
- const total = ms(querySentAt, queryCompletedAt);
146178
- const calculatedTotal = networkLatencyBefore + executionTime + networkLatencyAfter + downloadTime + parseTime + ms(lastRowParsedAt, queryCompletedAt);
146179
- const errorMargin = Math.abs(total - calculatedTotal);
146180
- return {
146181
- networkLatencyBefore,
146182
- planning: null,
146183
- execution: executionTime,
146184
- networkLatencyAfter,
146185
- dataDownload: downloadTime,
146186
- dataParse: parseTime,
146187
- total,
146188
- errorMargin,
146189
- dataSize: bytesReceived
146190
- };
146191
- };
146192
- const benchmarkProxy = async ({ sql, params }, repeats) => {
146193
- const { createConnection: createConnection2 } = require("mysql2");
146194
- let startAt = 0n;
146195
- let tcpConnectedAt = 0n;
146196
- let tlsConnectedAt = null;
146197
- const createStream = ({ config }) => {
146198
- let stream;
146199
- if (config.socketPath) {
146200
- stream = import_net.default.connect(config.socketPath);
146201
- } else {
146202
- stream = import_net.default.connect(config.port, config.host);
146203
- }
146204
- if (config.enableKeepAlive) {
146205
- stream.on("connect", () => {
146206
- stream.setKeepAlive(true, config.keepAliveInitialDelay);
146207
- });
146208
- }
146209
- stream.setNoDelay(true);
146210
- stream.once("connect", () => {
146211
- tcpConnectedAt = process.hrtime.bigint();
146212
- });
146213
- return stream;
146214
- };
146215
- startAt = process.hrtime.bigint();
146216
- const connection2 = result2.url ? createConnection2({
146217
- uri: result2.url,
146218
- stream: createStream
146219
- }) : createConnection2({
146220
- ...result2.credentials,
146221
- stream: createStream
146222
- });
146223
- await new Promise((resolve2, reject) => {
146224
- connection2.connect((err2) => {
146225
- tlsConnectedAt = process.hrtime.bigint();
146226
- if (err2) {
146227
- reject(err2);
146228
- } else {
146229
- resolve2();
146230
- }
146231
- });
146232
- });
146233
- const results = [];
146234
- for (let i7 = 0; i7 < repeats; i7++) {
146235
- const r7 = await benchmarkQuery(connection2, sql, params);
146236
- results.push(r7);
146237
- }
146238
- connection2.end();
146239
- return {
146240
- tcpHandshake: ms(startAt, tcpConnectedAt),
146241
- tlsHandshake: tlsConnectedAt ? ms(tcpConnectedAt, tlsConnectedAt) : null,
146242
- dbHandshake: null,
146243
- queries: results
146244
- };
146245
- };
146246
146134
  return {
146247
146135
  db: { query },
146248
146136
  packageName: "mysql2",
146249
146137
  proxy,
146250
146138
  transactionProxy,
146251
- benchmarkProxy,
146252
146139
  database: result2.database,
146253
146140
  migrate: migrateFn
146254
146141
  };
@@ -146398,9 +146285,7 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
146398
146285
  migrate: migrateFn
146399
146286
  };
146400
146287
  }
146401
- console.error(
146402
- "To connect to MsSQL database - please install 'mssql' driver"
146403
- );
146288
+ console.error("To connect to MsSQL database - please install 'mssql' driver");
146404
146289
  process.exit(1);
146405
146290
  };
146406
146291
  prepareSqliteParams = (params, driver2) => {
@@ -146505,7 +146390,10 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
146505
146390
  await remoteCallback(query2, [], "run");
146506
146391
  };
146507
146392
  const proxy = async (params) => {
146508
- const preparedParams = prepareSqliteParams(params.params || [], "d1-http");
146393
+ const preparedParams = prepareSqliteParams(
146394
+ params.params || [],
146395
+ "d1-http"
146396
+ );
146509
146397
  const result2 = await remoteCallback(
146510
146398
  params.sql,
146511
146399
  preparedParams,
@@ -146730,17 +146618,19 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
146730
146618
  };
146731
146619
  const transactionProxy = async (queries) => {
146732
146620
  const results = [];
146733
- const tx = sqlite.transaction((queries2) => {
146734
- for (const query of queries2) {
146735
- let result2 = [];
146736
- if (query.method === "values" || query.method === "get" || query.method === "all") {
146737
- result2 = sqlite.prepare(query.sql).all();
146738
- } else {
146739
- sqlite.prepare(query.sql).run();
146621
+ const tx = sqlite.transaction(
146622
+ (queries2) => {
146623
+ for (const query of queries2) {
146624
+ let result2 = [];
146625
+ if (query.method === "values" || query.method === "get" || query.method === "all") {
146626
+ result2 = sqlite.prepare(query.sql).all();
146627
+ } else {
146628
+ sqlite.prepare(query.sql).run();
146629
+ }
146630
+ results.push(result2);
146740
146631
  }
146741
- results.push(result2);
146742
146632
  }
146743
- });
146633
+ );
146744
146634
  try {
146745
146635
  tx(queries);
146746
146636
  } catch (error3) {
@@ -146748,7 +146638,13 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
146748
146638
  }
146749
146639
  return results;
146750
146640
  };
146751
- return { ...db, packageName: "better-sqlite3", proxy, transactionProxy, migrate: migrateFn };
146641
+ return {
146642
+ ...db,
146643
+ packageName: "better-sqlite3",
146644
+ proxy,
146645
+ transactionProxy,
146646
+ migrate: migrateFn
146647
+ };
146752
146648
  }
146753
146649
  if (await checkPackage("bun")) {
146754
146650
  console.log(withStyle.info(`Using 'bun' driver for database querying`));
@@ -148802,8 +148698,8 @@ ${sql}
148802
148698
  `;
148803
148699
  return content;
148804
148700
  };
148805
- prepareSnapshotFolderName = (ms2) => {
148806
- const now = ms2 ? new Date(ms2) : /* @__PURE__ */ new Date();
148701
+ prepareSnapshotFolderName = (ms) => {
148702
+ const now = ms ? new Date(ms) : /* @__PURE__ */ new Date();
148807
148703
  return `${now.getFullYear()}${two(now.getUTCMonth() + 1)}${two(
148808
148704
  now.getUTCDate()
148809
148705
  )}${two(now.getUTCHours())}${two(now.getUTCMinutes())}${two(
@@ -152288,6 +152184,7 @@ var init_cors = __esm({
152288
152184
  // src/cli/commands/studio.ts
152289
152185
  var studio_exports = {};
152290
152186
  __export(studio_exports, {
152187
+ drizzleForDuckDb: () => drizzleForDuckDb,
152291
152188
  drizzleForLibSQL: () => drizzleForLibSQL,
152292
152189
  drizzleForMySQL: () => drizzleForMySQL,
152293
152190
  drizzleForPostgres: () => drizzleForPostgres,
@@ -152301,7 +152198,7 @@ __export(studio_exports, {
152301
152198
  prepareServer: () => prepareServer,
152302
152199
  prepareSingleStoreSchema: () => prepareSingleStoreSchema
152303
152200
  });
152304
- var import_crypto10, import_drizzle_orm3, import_relations3, import_mssql_core2, import_mysql_core2, import_pg_core3, import_singlestore_core, import_sqlite_core2, import_fs6, import_node_https2, preparePgSchema, prepareMySqlSchema, prepareMsSqlSchema, prepareSQLiteSchema, prepareSingleStoreSchema, getCustomDefaults, drizzleForPostgres, drizzleForMySQL, drizzleForSQLite, drizzleForLibSQL, drizzleForSingleStore, extractRelations, init2, proxySchema, transactionProxySchema, benchmarkProxySchema, defaultsSchema, schema5, jsonStringify, prepareServer;
152201
+ var import_crypto10, import_drizzle_orm3, import_relations3, import_mssql_core2, import_mysql_core2, import_pg_core3, import_singlestore_core, import_sqlite_core2, import_fs6, import_node_https2, preparePgSchema, prepareMySqlSchema, prepareMsSqlSchema, prepareSQLiteSchema, prepareSingleStoreSchema, getCustomDefaults, drizzleForPostgres, drizzleForDuckDb, drizzleForMySQL, drizzleForSQLite, drizzleForLibSQL, drizzleForSingleStore, extractRelations, init2, proxySchema, transactionProxySchema, defaultsSchema, schema5, jsonStringify, prepareServer;
152305
152202
  var init_studio = __esm({
152306
152203
  "src/cli/commands/studio.ts"() {
152307
152204
  "use strict";
@@ -152525,7 +152422,6 @@ var init_studio = __esm({
152525
152422
  packageName: db.packageName,
152526
152423
  proxy: db.proxy,
152527
152424
  transactionProxy: db.transactionProxy,
152528
- benchmarkProxy: db.benchmarkProxy,
152529
152425
  customDefaults,
152530
152426
  schema: pgSchema2,
152531
152427
  relations: relations2,
@@ -152533,9 +152429,26 @@ var init_studio = __esm({
152533
152429
  casing: casing2
152534
152430
  };
152535
152431
  };
152432
+ drizzleForDuckDb = async (credentials) => {
152433
+ const { prepareDuckDb: prepareDuckDb2 } = await Promise.resolve().then(() => (init_connections(), connections_exports));
152434
+ const db = await prepareDuckDb2(credentials);
152435
+ const dbUrl = `duckdb://${credentials.url}`;
152436
+ const dbHash = (0, import_crypto10.createHash)("sha256").update(dbUrl).digest("hex");
152437
+ return {
152438
+ dbHash,
152439
+ dialect: "duckdb",
152440
+ driver: void 0,
152441
+ packageName: db.packageName,
152442
+ proxy: db.proxy,
152443
+ transactionProxy: db.transactionProxy,
152444
+ customDefaults: [],
152445
+ schema: {},
152446
+ relations: {}
152447
+ };
152448
+ };
152536
152449
  drizzleForMySQL = async (credentials, mysqlSchema, relations2, schemaFiles, casing2) => {
152537
152450
  const { connectToMySQL: connectToMySQL2 } = await Promise.resolve().then(() => (init_connections(), connections_exports));
152538
- const { proxy, transactionProxy, benchmarkProxy, database, packageName } = await connectToMySQL2(credentials);
152451
+ const { proxy, transactionProxy, database, packageName } = await connectToMySQL2(credentials);
152539
152452
  const customDefaults = getCustomDefaults(mysqlSchema, casing2);
152540
152453
  let dbUrl;
152541
152454
  if ("url" in credentials) {
@@ -152551,7 +152464,6 @@ var init_studio = __esm({
152551
152464
  databaseName: database,
152552
152465
  proxy,
152553
152466
  transactionProxy,
152554
- benchmarkProxy,
152555
152467
  customDefaults,
152556
152468
  schema: mysqlSchema,
152557
152469
  relations: relations2,
@@ -152721,23 +152633,6 @@ var init_studio = __esm({
152721
152633
  ]).optional()
152722
152634
  }).array()
152723
152635
  });
152724
- benchmarkProxySchema = external_exports.object({
152725
- type: external_exports.literal("bproxy"),
152726
- data: external_exports.object({
152727
- query: external_exports.object({
152728
- sql: external_exports.string(),
152729
- params: external_exports.array(external_exports.any()).optional(),
152730
- method: external_exports.union([
152731
- external_exports.literal("values"),
152732
- external_exports.literal("get"),
152733
- external_exports.literal("all"),
152734
- external_exports.literal("run"),
152735
- external_exports.literal("execute")
152736
- ]).optional()
152737
- }),
152738
- repeats: external_exports.number().min(1).optional()
152739
- })
152740
- });
152741
152636
  defaultsSchema = external_exports.object({
152742
152637
  type: external_exports.literal("defaults"),
152743
152638
  data: external_exports.array(
@@ -152752,7 +152647,6 @@ var init_studio = __esm({
152752
152647
  init2,
152753
152648
  proxySchema,
152754
152649
  transactionProxySchema,
152755
- benchmarkProxySchema,
152756
152650
  defaultsSchema
152757
152651
  ]);
152758
152652
  jsonStringify = (data) => {
@@ -152775,7 +152669,6 @@ var init_studio = __esm({
152775
152669
  databaseName,
152776
152670
  proxy,
152777
152671
  transactionProxy,
152778
- benchmarkProxy,
152779
152672
  customDefaults,
152780
152673
  schema: drizzleSchema,
152781
152674
  relations: relations2,
@@ -152839,7 +152732,7 @@ var init_studio = __esm({
152839
152732
  console.warn("Error message:", error3.message);
152840
152733
  }
152841
152734
  return c6.json({
152842
- version: "6.3",
152735
+ version: "6.2",
152843
152736
  dialect: dialect6,
152844
152737
  driver: driver2,
152845
152738
  packageName,
@@ -152877,21 +152770,6 @@ var init_studio = __esm({
152877
152770
  }
152878
152771
  );
152879
152772
  }
152880
- if (type === "bproxy") {
152881
- if (!benchmarkProxy) {
152882
- throw new Error("Benchmark proxy is not configured for this database.");
152883
- }
152884
- const result2 = await benchmarkProxy(body.data.query, body.data.repeats || 1);
152885
- const res = jsonStringify(result2);
152886
- return c6.body(
152887
- res,
152888
- {
152889
- headers: {
152890
- "Content-Type": "application/json"
152891
- }
152892
- }
152893
- );
152894
- }
152895
152773
  if (type === "defaults") {
152896
152774
  const columns = body.data;
152897
152775
  const result2 = columns.map((column8) => {