drizzle-kit 1.0.0-beta.2-278d7e6 → 1.0.0-beta.2-31baa2b

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.mjs CHANGED
@@ -15205,7 +15205,8 @@ var init_schemaValidator = __esm({
15205
15205
  "singlestore",
15206
15206
  "gel",
15207
15207
  "mssql",
15208
- "cockroach"
15208
+ "cockroach",
15209
+ "duckdb"
15209
15210
  ];
15210
15211
  dialect = enumType(dialects);
15211
15212
  }
@@ -25025,7 +25026,7 @@ var init_introspect = __esm({
25025
25026
  let checksCount = 0;
25026
25027
  let viewsCount = 0;
25027
25028
  for (const seq of sequencesList) {
25028
- const depend = dependList.find((it) => it.oid === seq.oid);
25029
+ const depend = dependList.find((it) => Number(it.oid) === Number(seq.oid));
25029
25030
  if (depend && (depend.deptype === "a" || depend.deptype === "i")) {
25030
25031
  continue;
25031
25032
  }
@@ -25091,22 +25092,22 @@ var init_introspect = __esm({
25091
25092
  continue;
25092
25093
  }
25093
25094
  const expr = serialsList.find(
25094
- (it) => it.tableId === column8.tableId && it.ordinality === column8.ordinality
25095
+ (it) => Number(it.tableId) === Number(column8.tableId) && it.ordinality === column8.ordinality
25095
25096
  );
25096
25097
  if (expr) {
25097
- const table7 = tablesList.find((it) => it.oid === column8.tableId);
25098
+ const table7 = tablesList.find((it) => Number(it.oid) === Number(column8.tableId));
25098
25099
  const isSerial = isSerialExpression(expr.expression, table7.schema);
25099
25100
  column8.type = isSerial ? type === "bigint" ? "bigserial" : type === "integer" ? "serial" : "smallserial" : type;
25100
25101
  }
25101
25102
  }
25102
25103
  for (const column8 of columnsList.filter((x6) => x6.kind === "r" || x6.kind === "p")) {
25103
- const table7 = tablesList.find((it) => it.oid === column8.tableId);
25104
+ const table7 = tablesList.find((it) => Number(it.oid) === Number(column8.tableId));
25104
25105
  const enumType2 = column8.typeId in groupedEnums ? groupedEnums[column8.typeId] : column8.typeId in groupedArrEnums ? groupedArrEnums[column8.typeId] : null;
25105
25106
  let columnTypeMapped = enumType2 ? enumType2.name : column8.type.replaceAll("[]", "");
25106
25107
  columnTypeMapped = columnTypeMapped.replace("character varying", "varchar").replace(" without time zone", "").replace("character", "char").replace("geometry(Point", "geometry(point");
25107
25108
  columnTypeMapped = trimChar(columnTypeMapped, '"');
25108
25109
  const columnDefault = defaultsList.find(
25109
- (it) => it.tableId === column8.tableId && it.ordinality === column8.ordinality
25110
+ (it) => Number(it.tableId) === Number(column8.tableId) && it.ordinality === column8.ordinality
25110
25111
  );
25111
25112
  const defaultValue = defaultForColumn(
25112
25113
  columnTypeMapped,
@@ -25115,10 +25116,10 @@ var init_introspect = __esm({
25115
25116
  Boolean(enumType2)
25116
25117
  );
25117
25118
  const unique = constraintsList.find((it) => {
25118
- return it.type === "u" && it.tableId === column8.tableId && it.columnsOrdinals.length === 1 && it.columnsOrdinals.includes(column8.ordinality);
25119
+ return it.type === "u" && Number(it.tableId) === Number(column8.tableId) && it.columnsOrdinals.length === 1 && it.columnsOrdinals.includes(column8.ordinality);
25119
25120
  }) ?? null;
25120
25121
  const pk = constraintsList.find((it) => {
25121
- return it.type === "p" && it.tableId === column8.tableId && it.columnsOrdinals.length === 1 && it.columnsOrdinals.includes(column8.ordinality);
25122
+ return it.type === "p" && Number(it.tableId) === Number(column8.tableId) && it.columnsOrdinals.length === 1 && it.columnsOrdinals.includes(column8.ordinality);
25122
25123
  }) ?? null;
25123
25124
  const metadata = column8.metadata;
25124
25125
  if (column8.generatedType === "s" && (!metadata || !metadata.expression)) {
@@ -25133,7 +25134,7 @@ ${JSON.stringify(column8.metadata)}`
25133
25134
  ${JSON.stringify(column8.metadata)}`
25134
25135
  );
25135
25136
  }
25136
- const sequence = metadata?.seqId ? sequencesList.find((it) => it.oid === Number(metadata.seqId)) ?? null : null;
25137
+ const sequence = metadata?.seqId ? sequencesList.find((it) => Number(it.oid) === Number(metadata.seqId)) ?? null : null;
25137
25138
  columns.push({
25138
25139
  entityType: "columns",
25139
25140
  schema: table7.schema,
@@ -25163,10 +25164,12 @@ ${JSON.stringify(column8.metadata)}`
25163
25164
  });
25164
25165
  }
25165
25166
  for (const unique of constraintsList.filter((it) => it.type === "u")) {
25166
- const table7 = tablesList.find((it) => it.oid === unique.tableId);
25167
- const schema6 = namespaces.find((it) => it.oid === unique.schemaId);
25167
+ const table7 = tablesList.find((it) => Number(it.oid) === Number(unique.tableId));
25168
+ const schema6 = namespaces.find((it) => Number(it.oid) === Number(unique.schemaId));
25168
25169
  const columns2 = unique.columnsOrdinals.map((it) => {
25169
- const column8 = columnsList.find((column9) => column9.tableId === unique.tableId && column9.ordinality === it);
25170
+ const column8 = columnsList.find(
25171
+ (column9) => Number(column9.tableId) === Number(unique.tableId) && column9.ordinality === it
25172
+ );
25170
25173
  return column8.name;
25171
25174
  });
25172
25175
  uniques.push({
@@ -25180,10 +25183,12 @@ ${JSON.stringify(column8.metadata)}`
25180
25183
  });
25181
25184
  }
25182
25185
  for (const pk of constraintsList.filter((it) => it.type === "p")) {
25183
- const table7 = tablesList.find((it) => it.oid === pk.tableId);
25184
- const schema6 = namespaces.find((it) => it.oid === pk.schemaId);
25186
+ const table7 = tablesList.find((it) => Number(it.oid) === Number(pk.tableId));
25187
+ const schema6 = namespaces.find((it) => Number(it.oid) === Number(pk.schemaId));
25185
25188
  const columns2 = pk.columnsOrdinals.map((it) => {
25186
- const column8 = columnsList.find((column9) => column9.tableId === pk.tableId && column9.ordinality === it);
25189
+ const column8 = columnsList.find(
25190
+ (column9) => Number(column9.tableId) === Number(pk.tableId) && column9.ordinality === it
25191
+ );
25187
25192
  return column8.name;
25188
25193
  });
25189
25194
  pks.push({
@@ -25196,15 +25201,19 @@ ${JSON.stringify(column8.metadata)}`
25196
25201
  });
25197
25202
  }
25198
25203
  for (const fk6 of constraintsList.filter((it) => it.type === "f")) {
25199
- const table7 = tablesList.find((it) => it.oid === fk6.tableId);
25200
- const schema6 = namespaces.find((it) => it.oid === fk6.schemaId);
25201
- const tableTo = tablesList.find((it) => it.oid === fk6.tableToId);
25204
+ const table7 = tablesList.find((it) => Number(it.oid) === Number(fk6.tableId));
25205
+ const schema6 = namespaces.find((it) => Number(it.oid) === Number(fk6.schemaId));
25206
+ const tableTo = tablesList.find((it) => Number(it.oid) === Number(fk6.tableToId));
25202
25207
  const columns2 = fk6.columnsOrdinals.map((it) => {
25203
- const column8 = columnsList.find((column9) => column9.tableId === fk6.tableId && column9.ordinality === it);
25208
+ const column8 = columnsList.find(
25209
+ (column9) => Number(column9.tableId) === Number(fk6.tableId) && column9.ordinality === it
25210
+ );
25204
25211
  return column8.name;
25205
25212
  });
25206
25213
  const columnsTo = fk6.columnsToOrdinals.map((it) => {
25207
- const column8 = columnsList.find((column9) => column9.tableId === fk6.tableToId && column9.ordinality === it);
25214
+ const column8 = columnsList.find(
25215
+ (column9) => Number(column9.tableId) === Number(fk6.tableToId) && column9.ordinality === it
25216
+ );
25208
25217
  return column8.name;
25209
25218
  });
25210
25219
  fks.push({
@@ -25222,8 +25231,8 @@ ${JSON.stringify(column8.metadata)}`
25222
25231
  });
25223
25232
  }
25224
25233
  for (const check of constraintsList.filter((it) => it.type === "c")) {
25225
- const table7 = tablesList.find((it) => it.oid === check.tableId);
25226
- const schema6 = namespaces.find((it) => it.oid === check.schemaId);
25234
+ const table7 = tablesList.find((it) => Number(it.oid) === Number(check.tableId));
25235
+ const schema6 = namespaces.find((it) => Number(it.oid) === Number(check.schemaId));
25227
25236
  checks.push({
25228
25237
  entityType: "checks",
25229
25238
  schema: schema6.name,
@@ -25284,10 +25293,10 @@ ${JSON.stringify(column8.metadata)}`
25284
25293
  });
25285
25294
  for (const idx of idxs) {
25286
25295
  const { metadata } = idx;
25287
- const forUnique = metadata.isUnique && constraintsList.some((x6) => x6.type === "u" && x6.indexId === idx.oid);
25288
- const forPK = metadata.isPrimary && constraintsList.some((x6) => x6.type === "p" && x6.indexId === idx.oid);
25296
+ const forUnique = metadata.isUnique && constraintsList.some((x6) => x6.type === "u" && Number(x6.indexId) === Number(idx.oid));
25297
+ const forPK = metadata.isPrimary && constraintsList.some((x6) => x6.type === "p" && Number(x6.indexId) === Number(idx.oid));
25289
25298
  const expr = splitExpressions(metadata.expression);
25290
- const table7 = tablesList.find((it) => it.oid === idx.metadata.tableId);
25299
+ const table7 = tablesList.find((it) => Number(it.oid) === Number(idx.metadata.tableId));
25291
25300
  const nonColumnsCount = metadata.columnOrdinals.reduce((acc, it) => {
25292
25301
  if (it === 0) acc += 1;
25293
25302
  return acc;
@@ -25319,7 +25328,7 @@ ${JSON.stringify(column8.metadata)}`
25319
25328
  k6 += 1;
25320
25329
  } else {
25321
25330
  const column8 = columnsList.find((column9) => {
25322
- return column9.tableId === metadata.tableId && column9.ordinality === ordinal;
25331
+ return Number(column9.tableId) === Number(metadata.tableId) && column9.ordinality === ordinal;
25323
25332
  });
25324
25333
  if (!column8) throw new Error(`missing column: ${metadata.tableId}:${ordinal}`);
25325
25334
  const options = opts[i7];
@@ -25368,7 +25377,7 @@ ${JSON.stringify(column8.metadata)}`
25368
25377
  progressCallback("indexes", indexesCount, "fetching");
25369
25378
  progressCallback("tables", tableCount, "done");
25370
25379
  for (const it of columnsList.filter((x6) => x6.kind === "m" || x6.kind === "v")) {
25371
- const view6 = viewsList.find((x6) => x6.oid === it.tableId);
25380
+ const view6 = viewsList.find((x6) => Number(x6.oid) === Number(it.tableId));
25372
25381
  const typeDimensions = it.type.split("[]").length - 1;
25373
25382
  const enumType2 = it.typeId in groupedEnums ? groupedEnums[it.typeId] : it.typeId in groupedArrEnums ? groupedArrEnums[it.typeId] : null;
25374
25383
  let columnTypeMapped = enumType2 ? enumType2.name : it.type.replace("[]", "");
@@ -25391,8 +25400,8 @@ ${JSON.stringify(column8.metadata)}`
25391
25400
  }
25392
25401
  for (const view6 of viewsList) {
25393
25402
  tableCount += 1;
25394
- const accessMethod = view6.accessMethod === 0 ? null : ams.find((it) => it.oid === view6.accessMethod);
25395
- const tablespace = view6.tablespaceid === 0 ? null : tablespaces.find((it) => it.oid === view6.tablespaceid).name;
25403
+ const accessMethod = Number(view6.accessMethod) === 0 ? null : ams.find((it) => Number(it.oid) === Number(view6.accessMethod));
25404
+ const tablespace = Number(view6.tablespaceid) === 0 ? null : tablespaces.find((it) => Number(it.oid) === Number(view6.tablespaceid)).name;
25396
25405
  const definition = parseViewDefinition(view6.definition);
25397
25406
  const withOpts = wrapRecord(
25398
25407
  view6.options?.reduce((acc, it) => {
@@ -34431,7 +34440,7 @@ var require_websocket = __commonJS({
34431
34440
  var EventEmitter = __require("events");
34432
34441
  var https2 = __require("https");
34433
34442
  var http3 = __require("http");
34434
- var net2 = __require("net");
34443
+ var net = __require("net");
34435
34444
  var tls = __require("tls");
34436
34445
  var { randomBytes, createHash: createHash5 } = __require("crypto");
34437
34446
  var { Duplex, Readable: Readable6 } = __require("stream");
@@ -35162,12 +35171,12 @@ var require_websocket = __commonJS({
35162
35171
  }
35163
35172
  function netConnect(options) {
35164
35173
  options.path = options.socketPath;
35165
- return net2.connect(options);
35174
+ return net.connect(options);
35166
35175
  }
35167
35176
  function tlsConnect(options) {
35168
35177
  options.path = void 0;
35169
35178
  if (!options.servername && options.servername !== "") {
35170
- options.servername = net2.isIP(options.host) ? "" : options.host;
35179
+ options.servername = net.isIP(options.host) ? "" : options.host;
35171
35180
  }
35172
35181
  return tls.connect(options);
35173
35182
  }
@@ -39485,7 +39494,7 @@ var init_timing = __esm({
39485
39494
  "../node_modules/.pnpm/@smithy+node-http-handler@4.4.5/node_modules/@smithy/node-http-handler/dist-es/timing.js"() {
39486
39495
  "use strict";
39487
39496
  timing = {
39488
- setTimeout: (cb, ms2) => setTimeout(cb, ms2),
39497
+ setTimeout: (cb, ms) => setTimeout(cb, ms),
39489
39498
  clearTimeout: (timeoutId) => clearTimeout(timeoutId)
39490
39499
  };
39491
39500
  }
@@ -41373,13 +41382,13 @@ var init_schema_date_utils = __esm({
41373
41382
  if (!matches) {
41374
41383
  throw new TypeError(`Invalid RFC3339 timestamp format ${value}`);
41375
41384
  }
41376
- const [, yearStr, monthStr, dayStr, hours, minutes, seconds, , ms2, offsetStr] = matches;
41385
+ const [, yearStr, monthStr, dayStr, hours, minutes, seconds, , ms, offsetStr] = matches;
41377
41386
  range(monthStr, 1, 12);
41378
41387
  range(dayStr, 1, 31);
41379
41388
  range(hours, 0, 23);
41380
41389
  range(minutes, 0, 59);
41381
41390
  range(seconds, 0, 60);
41382
- 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));
41391
+ 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));
41383
41392
  date2.setUTCFullYear(Number(yearStr));
41384
41393
  if (offsetStr.toUpperCase() != "Z") {
41385
41394
  const [, sign2, offsetH, offsetM] = /([+-])(\d\d):(\d\d)/.exec(offsetStr) || [void 0, "+", 0, 0];
@@ -61392,8 +61401,8 @@ var require_datetime2 = __commonJS({
61392
61401
  if (!(object instanceof Date)) {
61393
61402
  throw new errors_1.InvalidArgumentError(`a Date instance was expected, got "${object}"`);
61394
61403
  }
61395
- const ms2 = object.getTime() - TIMESHIFT;
61396
- const us = ms2 * 1e3;
61404
+ const ms = object.getTime() - TIMESHIFT;
61405
+ const us = ms * 1e3;
61397
61406
  buf.writeInt32(8);
61398
61407
  buf.writeInt64(us);
61399
61408
  }
@@ -61403,12 +61412,12 @@ var require_datetime2 = __commonJS({
61403
61412
  return ctx.postDecode(this, us2 + BI_TIMESHIFT_US);
61404
61413
  }
61405
61414
  const us = Number(buf.readBigInt64());
61406
- let ms2 = Math.round(us / 1e3);
61407
- if (Math.abs(us % 1e3) === 500 && Math.abs(ms2) % 2 === 1) {
61408
- ms2 -= 1;
61415
+ let ms = Math.round(us / 1e3);
61416
+ if (Math.abs(us % 1e3) === 500 && Math.abs(ms) % 2 === 1) {
61417
+ ms -= 1;
61409
61418
  }
61410
- ms2 += TIMESHIFT;
61411
- return new Date(ms2);
61419
+ ms += TIMESHIFT;
61420
+ return new Date(ms);
61412
61421
  }
61413
61422
  };
61414
61423
  exports2.DateTimeCodec = DateTimeCodec;
@@ -61429,8 +61438,8 @@ var require_datetime2 = __commonJS({
61429
61438
  if (!(object instanceof datetime_1.LocalDateTime)) {
61430
61439
  throw new errors_1.InvalidArgumentError(`a LocalDateTime instance was expected, got "${object}"`);
61431
61440
  }
61432
- const ms2 = BigInt(datetime_1.localDateInstances.get(object).getTime() - TIMESHIFT);
61433
- let us = ms2 * 1000n + BigInt(object.hour * 36e8 + object.minute * 6e7 + object.second * 1e6 + object.millisecond * 1e3 + object.microsecond);
61441
+ const ms = BigInt(datetime_1.localDateInstances.get(object).getTime() - TIMESHIFT);
61442
+ let us = ms * 1000n + BigInt(object.hour * 36e8 + object.minute * 6e7 + object.second * 1e6 + object.millisecond * 1e3 + object.microsecond);
61434
61443
  if (object.nanosecond === 500 && Math.abs(object.microsecond) % 2 === 1 || object.nanosecond > 500) {
61435
61444
  us += 1n;
61436
61445
  }
@@ -61444,13 +61453,13 @@ var require_datetime2 = __commonJS({
61444
61453
  }
61445
61454
  const bi_ms = bi_us / 1000n;
61446
61455
  let us = Number(bi_us - bi_ms * 1000n);
61447
- let ms2 = Number(bi_ms);
61456
+ let ms = Number(bi_ms);
61448
61457
  if (us < 0) {
61449
61458
  us += 1e3;
61450
- ms2 -= 1;
61459
+ ms -= 1;
61451
61460
  }
61452
- ms2 += TIMESHIFT;
61453
- const date2 = new Date(ms2);
61461
+ ms += TIMESHIFT;
61462
+ const date2 = new Date(ms);
61454
61463
  return new datetime_1.LocalDateTime(date2.getUTCFullYear(), date2.getUTCMonth() + 1, date2.getUTCDate(), date2.getUTCHours(), date2.getUTCMinutes(), date2.getUTCSeconds(), date2.getUTCMilliseconds(), us);
61455
61464
  }
61456
61465
  };
@@ -61512,13 +61521,13 @@ var require_datetime2 = __commonJS({
61512
61521
  }
61513
61522
  let us = Number(bius);
61514
61523
  let seconds = Math.floor(us / 1e6);
61515
- const ms2 = Math.floor(us % 1e6 / 1e3);
61516
- us = us % 1e6 - ms2 * 1e3;
61524
+ const ms = Math.floor(us % 1e6 / 1e3);
61525
+ us = us % 1e6 - ms * 1e3;
61517
61526
  let minutes = Math.floor(seconds / 60);
61518
61527
  seconds = Math.floor(seconds % 60);
61519
61528
  const hours = Math.floor(minutes / 60);
61520
61529
  minutes = Math.floor(minutes % 60);
61521
- return new datetime_1.LocalTime(hours, minutes, seconds, ms2, us);
61530
+ return new datetime_1.LocalTime(hours, minutes, seconds, ms, us);
61522
61531
  }
61523
61532
  };
61524
61533
  exports2.LocalTimeCodec = LocalTimeCodec;
@@ -61595,14 +61604,14 @@ var require_datetime2 = __commonJS({
61595
61604
  const biMillion = 1000000n;
61596
61605
  const biSeconds = bius / biMillion;
61597
61606
  let us = Number(bius - biSeconds * biMillion);
61598
- const ms2 = Math.floor(us / 1e3);
61607
+ const ms = Math.floor(us / 1e3);
61599
61608
  us = us % 1e3;
61600
61609
  let seconds = Number(biSeconds);
61601
61610
  let minutes = Math.floor(seconds / 60);
61602
61611
  seconds = Math.floor(seconds % 60);
61603
61612
  const hours = Math.floor(minutes / 60);
61604
61613
  minutes = Math.floor(minutes % 60);
61605
- return new datetime_1.Duration(0, 0, 0, 0, hours * sign2, minutes * sign2, seconds * sign2, ms2 * sign2, us * sign2);
61614
+ return new datetime_1.Duration(0, 0, 0, 0, hours * sign2, minutes * sign2, seconds * sign2, ms * sign2, us * sign2);
61606
61615
  }
61607
61616
  };
61608
61617
  exports2.DurationCodec = DurationCodec;
@@ -61648,7 +61657,7 @@ var require_datetime2 = __commonJS({
61648
61657
  const million = BigInt(1e6);
61649
61658
  const biSeconds = bius / million;
61650
61659
  let us = Number(bius - biSeconds * million);
61651
- const ms2 = Math.trunc(us / 1e3);
61660
+ const ms = Math.trunc(us / 1e3);
61652
61661
  us = us % 1e3;
61653
61662
  let seconds = Number(biSeconds);
61654
61663
  let minutes = Math.trunc(seconds / 60);
@@ -61659,7 +61668,7 @@ var require_datetime2 = __commonJS({
61659
61668
  days = Math.trunc(days % 7);
61660
61669
  const years = Math.trunc(months2 / 12);
61661
61670
  months2 = Math.trunc(months2 % 12);
61662
- return new datetime_1.RelativeDuration(years, months2, weeks, days, hours * sign2, minutes * sign2, seconds * sign2, ms2 * sign2, us * sign2);
61671
+ return new datetime_1.RelativeDuration(years, months2, weeks, days, hours * sign2, minutes * sign2, seconds * sign2, ms * sign2, us * sign2);
61663
61672
  }
61664
61673
  };
61665
61674
  exports2.RelativeDurationCodec = RelativeDurationCodec;
@@ -71823,41 +71832,41 @@ var require_ms = __commonJS({
71823
71832
  return void 0;
71824
71833
  }
71825
71834
  }
71826
- function fmtShort(ms2) {
71827
- var msAbs = Math.abs(ms2);
71835
+ function fmtShort(ms) {
71836
+ var msAbs = Math.abs(ms);
71828
71837
  if (msAbs >= d6) {
71829
- return Math.round(ms2 / d6) + "d";
71838
+ return Math.round(ms / d6) + "d";
71830
71839
  }
71831
71840
  if (msAbs >= h7) {
71832
- return Math.round(ms2 / h7) + "h";
71841
+ return Math.round(ms / h7) + "h";
71833
71842
  }
71834
71843
  if (msAbs >= m7) {
71835
- return Math.round(ms2 / m7) + "m";
71844
+ return Math.round(ms / m7) + "m";
71836
71845
  }
71837
71846
  if (msAbs >= s7) {
71838
- return Math.round(ms2 / s7) + "s";
71847
+ return Math.round(ms / s7) + "s";
71839
71848
  }
71840
- return ms2 + "ms";
71849
+ return ms + "ms";
71841
71850
  }
71842
- function fmtLong(ms2) {
71843
- var msAbs = Math.abs(ms2);
71851
+ function fmtLong(ms) {
71852
+ var msAbs = Math.abs(ms);
71844
71853
  if (msAbs >= d6) {
71845
- return plural2(ms2, msAbs, d6, "day");
71854
+ return plural2(ms, msAbs, d6, "day");
71846
71855
  }
71847
71856
  if (msAbs >= h7) {
71848
- return plural2(ms2, msAbs, h7, "hour");
71857
+ return plural2(ms, msAbs, h7, "hour");
71849
71858
  }
71850
71859
  if (msAbs >= m7) {
71851
- return plural2(ms2, msAbs, m7, "minute");
71860
+ return plural2(ms, msAbs, m7, "minute");
71852
71861
  }
71853
71862
  if (msAbs >= s7) {
71854
- return plural2(ms2, msAbs, s7, "second");
71863
+ return plural2(ms, msAbs, s7, "second");
71855
71864
  }
71856
- return ms2 + " ms";
71865
+ return ms + " ms";
71857
71866
  }
71858
- function plural2(ms2, msAbs, n6, name) {
71867
+ function plural2(ms, msAbs, n6, name) {
71859
71868
  var isPlural = msAbs >= n6 * 1.5;
71860
- return Math.round(ms2 / n6) + " " + name + (isPlural ? "s" : "");
71869
+ return Math.round(ms / n6) + " " + name + (isPlural ? "s" : "");
71861
71870
  }
71862
71871
  }
71863
71872
  });
@@ -71901,8 +71910,8 @@ var require_common2 = __commonJS({
71901
71910
  }
71902
71911
  const self2 = debug;
71903
71912
  const curr = Number(/* @__PURE__ */ new Date());
71904
- const ms2 = curr - (prevTime || curr);
71905
- self2.diff = ms2;
71913
+ const ms = curr - (prevTime || curr);
71914
+ self2.diff = ms;
71906
71915
  self2.prev = prevTime;
71907
71916
  self2.curr = curr;
71908
71917
  prevTime = curr;
@@ -87405,11 +87414,11 @@ var require_TokenExpiredError = __commonJS({
87405
87414
  var require_timespan = __commonJS({
87406
87415
  "../node_modules/.pnpm/jsonwebtoken@9.0.2/node_modules/jsonwebtoken/lib/timespan.js"(exports2, module) {
87407
87416
  "use strict";
87408
- var ms2 = require_ms();
87417
+ var ms = require_ms();
87409
87418
  module.exports = function(time2, iat) {
87410
87419
  var timestamp = iat || Math.floor(Date.now() / 1e3);
87411
87420
  if (typeof time2 === "string") {
87412
- var milliseconds = ms2(time2);
87421
+ var milliseconds = ms(time2);
87413
87422
  if (typeof milliseconds === "undefined") {
87414
87423
  return;
87415
87424
  }
@@ -101947,7 +101956,7 @@ var require_dist = __commonJS({
101947
101956
  };
101948
101957
  Object.defineProperty(exports2, "__esModule", { value: true });
101949
101958
  exports2.Agent = void 0;
101950
- var net2 = __importStar2(__require("net"));
101959
+ var net = __importStar2(__require("net"));
101951
101960
  var http3 = __importStar2(__require("http"));
101952
101961
  var https_1 = __require("https");
101953
101962
  __exportStar2(require_helpers2(), exports2);
@@ -101987,7 +101996,7 @@ var require_dist = __commonJS({
101987
101996
  if (!this.sockets[name]) {
101988
101997
  this.sockets[name] = [];
101989
101998
  }
101990
- const fakeSocket = new net2.Socket({ writable: false });
101999
+ const fakeSocket = new net.Socket({ writable: false });
101991
102000
  this.sockets[name].push(fakeSocket);
101992
102001
  this.totalSocketCount++;
101993
102002
  return fakeSocket;
@@ -102199,7 +102208,7 @@ var require_dist2 = __commonJS({
102199
102208
  };
102200
102209
  Object.defineProperty(exports2, "__esModule", { value: true });
102201
102210
  exports2.HttpsProxyAgent = void 0;
102202
- var net2 = __importStar2(__require("net"));
102211
+ var net = __importStar2(__require("net"));
102203
102212
  var tls = __importStar2(__require("tls"));
102204
102213
  var assert_1 = __importDefault2(__require("assert"));
102205
102214
  var debug_1 = __importDefault2(require_src2());
@@ -102208,7 +102217,7 @@ var require_dist2 = __commonJS({
102208
102217
  var parse_proxy_response_1 = require_parse_proxy_response();
102209
102218
  var debug = (0, debug_1.default)("https-proxy-agent");
102210
102219
  var setServernameFromNonIpHost = (options) => {
102211
- if (options.servername === void 0 && options.host && !net2.isIP(options.host)) {
102220
+ if (options.servername === void 0 && options.host && !net.isIP(options.host)) {
102212
102221
  return {
102213
102222
  ...options,
102214
102223
  servername: options.host
@@ -102248,10 +102257,10 @@ var require_dist2 = __commonJS({
102248
102257
  socket = tls.connect(setServernameFromNonIpHost(this.connectOpts));
102249
102258
  } else {
102250
102259
  debug("Creating `net.Socket`: %o", this.connectOpts);
102251
- socket = net2.connect(this.connectOpts);
102260
+ socket = net.connect(this.connectOpts);
102252
102261
  }
102253
102262
  const headers = typeof this.proxyHeaders === "function" ? this.proxyHeaders() : { ...this.proxyHeaders };
102254
- const host = net2.isIPv6(opts.host) ? `[${opts.host}]` : opts.host;
102263
+ const host = net.isIPv6(opts.host) ? `[${opts.host}]` : opts.host;
102255
102264
  let payload = `CONNECT ${host}:${opts.port} HTTP/1.1\r
102256
102265
  `;
102257
102266
  if (proxy.username || proxy.password) {
@@ -102284,7 +102293,7 @@ var require_dist2 = __commonJS({
102284
102293
  return socket;
102285
102294
  }
102286
102295
  socket.destroy();
102287
- const fakeSocket = new net2.Socket({ writable: false });
102296
+ const fakeSocket = new net.Socket({ writable: false });
102288
102297
  fakeSocket.readable = true;
102289
102298
  req.once("socket", (s7) => {
102290
102299
  debug("Replaying proxy buffer for failed request");
@@ -102349,7 +102358,7 @@ var require_dist3 = __commonJS({
102349
102358
  };
102350
102359
  Object.defineProperty(exports2, "__esModule", { value: true });
102351
102360
  exports2.HttpProxyAgent = void 0;
102352
- var net2 = __importStar2(__require("net"));
102361
+ var net = __importStar2(__require("net"));
102353
102362
  var tls = __importStar2(__require("tls"));
102354
102363
  var debug_1 = __importDefault2(require_src2());
102355
102364
  var events_1 = __require("events");
@@ -102422,7 +102431,7 @@ var require_dist3 = __commonJS({
102422
102431
  socket = tls.connect(this.connectOpts);
102423
102432
  } else {
102424
102433
  debug("Creating `net.Socket`: %o", this.connectOpts);
102425
- socket = net2.connect(this.connectOpts);
102434
+ socket = net.connect(this.connectOpts);
102426
102435
  }
102427
102436
  await (0, events_1.once)(socket, "connect");
102428
102437
  return socket;
@@ -141301,7 +141310,7 @@ var require_connection = __commonJS({
141301
141310
  var _crypto = _interopRequireDefault(__require("crypto"));
141302
141311
  var _os = _interopRequireDefault(__require("os"));
141303
141312
  var tls = _interopRequireWildcard(__require("tls"));
141304
- var net2 = _interopRequireWildcard(__require("net"));
141313
+ var net = _interopRequireWildcard(__require("net"));
141305
141314
  var _dns = _interopRequireDefault(__require("dns"));
141306
141315
  var _constants = _interopRequireDefault(__require("constants"));
141307
141316
  var _stream = __require("stream");
@@ -142350,7 +142359,7 @@ var require_connection = __commonJS({
142350
142359
  async wrapWithTls(socket, signal) {
142351
142360
  signal.throwIfAborted();
142352
142361
  const secureContext = tls.createSecureContext(this.secureContextOptions);
142353
- const serverName = !net2.isIP(this.config.server) ? this.config.server : "";
142362
+ const serverName = !net.isIP(this.config.server) ? this.config.server : "";
142354
142363
  const encryptOptions = {
142355
142364
  host: this.config.server,
142356
142365
  socket,
@@ -145256,10 +145265,10 @@ __export(connections_exports, {
145256
145265
  connectToSQLite: () => connectToSQLite,
145257
145266
  connectToSingleStore: () => connectToSingleStore,
145258
145267
  prepareCockroach: () => prepareCockroach,
145268
+ prepareDuckDb: () => prepareDuckDb,
145259
145269
  prepareGelDB: () => prepareGelDB,
145260
145270
  preparePostgresDB: () => preparePostgresDB
145261
145271
  });
145262
- import net from "net";
145263
145272
  function parseMssqlUrl(url) {
145264
145273
  return {
145265
145274
  user: url.username,
@@ -145273,7 +145282,7 @@ function parseMssqlUrl(url) {
145273
145282
  }
145274
145283
  };
145275
145284
  }
145276
- var ms, normalisePGliteUrl, preparePostgresDB, prepareCockroach, prepareGelDB, parseSingleStoreCredentials, connectToSingleStore, parseMysqlCredentials, connectToMySQL, parseMssqlCredentials, connectToMsSQL, prepareSqliteParams, preparePGliteParams, connectToSQLite, connectToLibSQL;
145285
+ var normalisePGliteUrl, preparePostgresDB, prepareDuckDb, prepareCockroach, prepareGelDB, parseSingleStoreCredentials, connectToSingleStore, parseMysqlCredentials, connectToMySQL, parseMssqlCredentials, connectToMsSQL, prepareSqliteParams, preparePGliteParams, connectToSQLite, connectToLibSQL;
145277
145286
  var init_connections = __esm({
145278
145287
  "src/cli/connections.ts"() {
145279
145288
  "use strict";
@@ -145284,7 +145293,6 @@ var init_connections = __esm({
145284
145293
  init_when_json_met_bigint();
145285
145294
  init_utils3();
145286
145295
  init_outputs();
145287
- ms = (a6, b6) => Number(b6 - a6) / 1e6;
145288
145296
  normalisePGliteUrl = (it) => {
145289
145297
  if (it.startsWith("file:")) {
145290
145298
  return it.substring(5);
@@ -145408,7 +145416,13 @@ var init_connections = __esm({
145408
145416
  }
145409
145417
  return results;
145410
145418
  };
145411
- return { packageName: "pglite", query, proxy, transactionProxy, migrate: migrateFn };
145419
+ return {
145420
+ packageName: "pglite",
145421
+ query,
145422
+ proxy,
145423
+ transactionProxy,
145424
+ migrate: migrateFn
145425
+ };
145412
145426
  }
145413
145427
  assertUnreachable(driver2);
145414
145428
  }
@@ -145439,13 +145453,13 @@ var init_connections = __esm({
145439
145453
  return pg.types.getTypeParser(typeId, format2);
145440
145454
  }
145441
145455
  };
145442
- const pool = "url" in credentials ? new pg.Pool({ connectionString: credentials.url, max: 1 }) : new pg.Pool({ ...credentials, ssl, max: 1 });
145443
- const db = drizzle({ client: pool });
145456
+ const client = "url" in credentials ? new pg.Pool({ connectionString: credentials.url, max: 1 }) : new pg.Pool({ ...credentials, ssl, max: 1 });
145457
+ const db = drizzle({ client });
145444
145458
  const migrateFn = async (config) => {
145445
145459
  return migrate(db, config);
145446
145460
  };
145447
145461
  const query = async (sql, params) => {
145448
- const result2 = await pool.query({
145462
+ const result2 = await client.query({
145449
145463
  text: sql,
145450
145464
  values: params ?? [],
145451
145465
  types: types3
@@ -145455,7 +145469,7 @@ var init_connections = __esm({
145455
145469
  return result2.rows;
145456
145470
  };
145457
145471
  const proxy = async (params) => {
145458
- const result2 = await pool.query({
145472
+ const result2 = await client.query({
145459
145473
  text: params.sql,
145460
145474
  values: params.params,
145461
145475
  ...params.mode === "array" && { rowMode: "array" },
@@ -145467,7 +145481,7 @@ var init_connections = __esm({
145467
145481
  };
145468
145482
  const transactionProxy = async (queries) => {
145469
145483
  const results = [];
145470
- const tx = await pool.connect();
145484
+ const tx = await client.connect();
145471
145485
  try {
145472
145486
  await tx.query("BEGIN");
145473
145487
  for (const query2 of queries) {
@@ -145486,119 +145500,13 @@ var init_connections = __esm({
145486
145500
  }
145487
145501
  return results;
145488
145502
  };
145489
- const benchmarkQuery = async (client, sql, params) => {
145490
- const explainResult = await pool.query({
145491
- text: `EXPLAIN ANALYZE ${sql}`,
145492
- values: params ?? [],
145493
- types: types3
145494
- });
145495
- const stringifiedResult = JSON.stringify(explainResult.rows);
145496
- const planningMatch = stringifiedResult.match(/Planning Time:\s*([\d.]+)\s*ms/i);
145497
- const executionMatch = stringifiedResult.match(/Execution Time:\s*([\d.]+)\s*ms/i);
145498
- let planningTime = Number(planningMatch[1]);
145499
- let executionTime = Number(executionMatch[1]);
145500
- let querySentAt = 0n;
145501
- let firstDataAt = 0n;
145502
- let lastDataAt = 0n;
145503
- let lastRowParsedAt = 0n;
145504
- let queryCompletedAt = 0n;
145505
- let bytesReceived = 0;
145506
- let rowCount = 0;
145507
- let parseTime = 0;
145508
- let lastParseTime = 0;
145509
- const rowDescriptionListener = (data) => {
145510
- if (firstDataAt === 0n) {
145511
- firstDataAt = process.hrtime.bigint();
145512
- }
145513
- bytesReceived += data.length;
145514
- };
145515
- const originalRowListener = client.connection.listeners("dataRow")[0];
145516
- const wrappedRowListener = (data) => {
145517
- rowCount += 1;
145518
- const start = process.hrtime.bigint();
145519
- lastDataAt = start;
145520
- originalRowListener.apply(client.connection, [data]);
145521
- const end2 = process.hrtime.bigint();
145522
- lastRowParsedAt = end2;
145523
- lastParseTime = ms(start, end2);
145524
- parseTime += lastParseTime;
145525
- bytesReceived += data.length;
145526
- };
145527
- client.connection.removeAllListeners("dataRow");
145528
- client.connection.addListener("dataRow", wrappedRowListener);
145529
- client.connection.prependListener("rowDescription", rowDescriptionListener);
145530
- querySentAt = process.hrtime.bigint();
145531
- await client.query({
145532
- text: sql,
145533
- values: params,
145534
- types: types3
145535
- });
145536
- queryCompletedAt = process.hrtime.bigint();
145537
- client.connection.removeListener("rowDescription", rowDescriptionListener);
145538
- client.connection.removeAllListeners("dataRow");
145539
- client.connection.addListener("dataRow", originalRowListener);
145540
- let querySentTime = ms(querySentAt, firstDataAt) - executionTime - planningTime;
145541
- if (querySentTime < 0) {
145542
- const percent = 0.1;
145543
- const overflow = -querySentTime;
145544
- const keepForSent = overflow * percent;
145545
- const adjustedOverflow = overflow * (1 + percent);
145546
- const total2 = planningTime + executionTime;
145547
- const ratioPlanning = planningTime / total2;
145548
- const ratioExecution = executionTime / total2;
145549
- planningTime -= adjustedOverflow * ratioPlanning;
145550
- executionTime -= adjustedOverflow * ratioExecution;
145551
- querySentTime = keepForSent;
145552
- }
145553
- const networkLatencyBefore = querySentTime / 2;
145554
- const networkLatencyAfter = querySentTime / 2;
145555
- const downloadTime = ms(firstDataAt, lastDataAt) - (rowCount > 1 ? parseTime - lastParseTime : 0);
145556
- const total = ms(querySentAt, queryCompletedAt);
145557
- const calculatedTotal = networkLatencyBefore + planningTime + executionTime + networkLatencyAfter + downloadTime + parseTime + ms(lastRowParsedAt, queryCompletedAt);
145558
- const errorMargin = Math.abs(total - calculatedTotal);
145559
- return {
145560
- networkLatencyBefore,
145561
- planning: planningTime,
145562
- execution: executionTime,
145563
- networkLatencyAfter,
145564
- dataDownload: downloadTime,
145565
- dataParse: parseTime,
145566
- total,
145567
- errorMargin,
145568
- dataSize: bytesReceived
145569
- };
145570
- };
145571
- const benchmarkProxy = async ({ sql, params }, repeats) => {
145572
- let startAt = 0n;
145573
- let tcpConnectedAt = 0n;
145574
- let tlsConnectedAt = null;
145575
- let dbReadyAt = 0n;
145576
- const client = "url" in credentials ? new pg.Client({ connectionString: credentials.url }) : new pg.Client({ ...credentials, ssl });
145577
- client.connection.once("connect", () => {
145578
- tcpConnectedAt = process.hrtime.bigint();
145579
- });
145580
- client.connection.prependOnceListener("sslconnect", () => {
145581
- tlsConnectedAt = process.hrtime.bigint();
145582
- });
145583
- client.connection.prependOnceListener("readyForQuery", () => {
145584
- dbReadyAt = process.hrtime.bigint();
145585
- });
145586
- startAt = process.hrtime.bigint();
145587
- await client.connect();
145588
- const results = [];
145589
- for (let i7 = 0; i7 < repeats; i7++) {
145590
- const r7 = await benchmarkQuery(client, sql, params);
145591
- results.push(r7);
145592
- }
145593
- await client.end();
145594
- return {
145595
- tcpHandshake: ms(startAt, tcpConnectedAt),
145596
- tlsHandshake: tlsConnectedAt ? ms(tcpConnectedAt, tlsConnectedAt) : null,
145597
- dbHandshake: ms(tlsConnectedAt ?? tcpConnectedAt, dbReadyAt),
145598
- queries: results
145599
- };
145503
+ return {
145504
+ packageName: "pg",
145505
+ query,
145506
+ proxy,
145507
+ transactionProxy,
145508
+ migrate: migrateFn
145600
145509
  };
145601
- return { packageName: "pg", query, proxy, transactionProxy, benchmarkProxy, migrate: migrateFn };
145602
145510
  }
145603
145511
  if (await checkPackage("postgres")) {
145604
145512
  console.log(
@@ -145649,7 +145557,13 @@ var init_connections = __esm({
145649
145557
  }
145650
145558
  return results;
145651
145559
  };
145652
- return { packageName: "postgres", query, proxy, transactionProxy, migrate: migrateFn };
145560
+ return {
145561
+ packageName: "postgres",
145562
+ query,
145563
+ proxy,
145564
+ transactionProxy,
145565
+ migrate: migrateFn
145566
+ };
145653
145567
  }
145654
145568
  if (await checkPackage("@vercel/postgres")) {
145655
145569
  console.log(
@@ -145730,7 +145644,13 @@ var init_connections = __esm({
145730
145644
  }
145731
145645
  return results;
145732
145646
  };
145733
- return { packageName: "@vercel/postgres", query, proxy, transactionProxy, migrate: migrateFn };
145647
+ return {
145648
+ packageName: "@vercel/postgres",
145649
+ query,
145650
+ proxy,
145651
+ transactionProxy,
145652
+ migrate: migrateFn
145653
+ };
145734
145654
  }
145735
145655
  if (await checkPackage("@neondatabase/serverless")) {
145736
145656
  console.log(
@@ -145743,7 +145663,11 @@ var init_connections = __esm({
145743
145663
  "'@neondatabase/serverless' can only connect to remote Neon/Vercel Postgres/Supabase instances through a websocket"
145744
145664
  )
145745
145665
  );
145746
- const { Pool, neonConfig, types: pgTypes } = await import("@neondatabase/serverless");
145666
+ const {
145667
+ Pool,
145668
+ neonConfig,
145669
+ types: pgTypes
145670
+ } = await import("@neondatabase/serverless");
145747
145671
  const { drizzle } = await import("drizzle-orm/neon-serverless");
145748
145672
  const { migrate } = await import("drizzle-orm/neon-serverless/migrator");
145749
145673
  const ssl = "ssl" in credentials ? credentials.ssl === "prefer" || credentials.ssl === "require" || credentials.ssl === "allow" ? { rejectUnauthorized: false } : credentials.ssl === "verify-full" ? {} : credentials.ssl : {};
@@ -145813,7 +145737,13 @@ var init_connections = __esm({
145813
145737
  }
145814
145738
  return results;
145815
145739
  };
145816
- return { packageName: "@neondatabase/serverless", query, proxy, transactionProxy, migrate: migrateFn };
145740
+ return {
145741
+ packageName: "@neondatabase/serverless",
145742
+ query,
145743
+ proxy,
145744
+ transactionProxy,
145745
+ migrate: migrateFn
145746
+ };
145817
145747
  }
145818
145748
  if (await checkPackage("bun")) {
145819
145749
  console.log(withStyle.info(`Using 'bun' driver for database querying`));
@@ -145864,6 +145794,54 @@ var init_connections = __esm({
145864
145794
  console.warn("For the 'bun' driver, run your script using: bun --bun");
145865
145795
  process.exit(1);
145866
145796
  };
145797
+ prepareDuckDb = async (credentials) => {
145798
+ if (await checkPackage("@duckdb/node-api")) {
145799
+ console.log(
145800
+ withStyle.info(`Using '@duckdb/node-api' driver for database querying`)
145801
+ );
145802
+ const { DuckDBInstance } = await import("@duckdb/node-api");
145803
+ const instance = await DuckDBInstance.create(credentials.url);
145804
+ const client = await instance.connect();
145805
+ const query = async (sql, params = []) => {
145806
+ const result2 = await client.run(sql, params);
145807
+ const rows = await result2.getRowObjectsJson();
145808
+ return rows;
145809
+ };
145810
+ const proxy = async (params) => {
145811
+ const result2 = await client.run(params.sql, params.params);
145812
+ return params.mode === "array" ? await result2.getRowsJson() : await result2.getRowObjectsJson();
145813
+ };
145814
+ const transactionProxy = async (queries) => {
145815
+ const results = [];
145816
+ try {
145817
+ await client.run("BEGIN");
145818
+ for (const query2 of queries) {
145819
+ const result2 = await client.run(query2.sql);
145820
+ results.push(await result2.getRowObjectsJson());
145821
+ }
145822
+ await client.run("COMMIT");
145823
+ } catch (error3) {
145824
+ await client.run("ROLLBACK");
145825
+ results.push(error3);
145826
+ }
145827
+ return results;
145828
+ };
145829
+ return {
145830
+ packageName: "@duckdb/node-api",
145831
+ query,
145832
+ proxy,
145833
+ transactionProxy,
145834
+ migrate: () => {
145835
+ throw new Error("DuckDB does not support migrations");
145836
+ }
145837
+ };
145838
+ }
145839
+ console.error(
145840
+ // "To connect to DuckDb database - please install either of 'duckdb', '@duckdb/node-api' drivers",
145841
+ "To connect to DuckDb database - please install '@duckdb/node-api' driver"
145842
+ );
145843
+ process.exit(1);
145844
+ };
145867
145845
  prepareCockroach = async (credentials) => {
145868
145846
  if (await checkPackage("pg")) {
145869
145847
  const { default: pg } = await import("pg");
@@ -145916,9 +145894,7 @@ var init_connections = __esm({
145916
145894
  };
145917
145895
  return { query, proxy, migrate: migrateFn };
145918
145896
  }
145919
- console.error(
145920
- "To connect to Cockroach - please install 'pg' package"
145921
- );
145897
+ console.error("To connect to Cockroach - please install 'pg' package");
145922
145898
  process.exit(1);
145923
145899
  };
145924
145900
  prepareGelDB = async (credentials) => {
@@ -145977,9 +145953,7 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
145977
145953
  };
145978
145954
  return { packageName: "gel", query, proxy, transactionProxy };
145979
145955
  }
145980
- console.error(
145981
- "To connect to gel database - please install 'edgedb' driver"
145982
- );
145956
+ console.error("To connect to gel database - please install 'edgedb' driver");
145983
145957
  process.exit(1);
145984
145958
  };
145985
145959
  parseSingleStoreCredentials = (credentials) => {
@@ -146093,6 +146067,7 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
146093
146067
  }
146094
146068
  return next();
146095
146069
  };
146070
+ await connection.connect();
146096
146071
  const query = async (sql, params) => {
146097
146072
  const res = await connection.execute({
146098
146073
  sql,
@@ -146132,156 +146107,11 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
146132
146107
  }
146133
146108
  return results;
146134
146109
  };
146135
- const benchmarkQuery = async (newConnection, sql, params) => {
146136
- const explainResult = await connection.query({
146137
- sql: `EXPLAIN ANALYZE ${sql}`,
146138
- values: params ?? [],
146139
- typeCast
146140
- });
146141
- const stringifiedResult = JSON.stringify(explainResult[0]);
146142
- const timeMatch = stringifiedResult.match(
146143
- /actual time=([0-9.eE+-]+)\.\.([0-9.eE+-]+)/
146144
- );
146145
- const lastRowTime = Number(timeMatch[2]);
146146
- let executionTime = lastRowTime;
146147
- let querySentAt = 0n;
146148
- let firstDataAt = 0n;
146149
- let lastDataAt = 0n;
146150
- let lastRowParsedAt = 0n;
146151
- let queryCompletedAt = 0n;
146152
- let bytesReceived = 0;
146153
- let rowCount = 0;
146154
- let parseTime = 0;
146155
- let lastParseTime = 0;
146156
- querySentAt = process.hrtime.bigint();
146157
- await new Promise((resolve2, reject) => {
146158
- const query2 = newConnection.query({
146159
- sql,
146160
- values: params ?? [],
146161
- typeCast
146162
- });
146163
- const originalRowHandler = query2.row;
146164
- let packets = 0;
146165
- const wrappedRowListener = (packet, connection2) => {
146166
- packets += 1;
146167
- if (firstDataAt === 0n) {
146168
- firstDataAt = process.hrtime.bigint();
146169
- bytesReceived += packet.start;
146170
- }
146171
- const start = process.hrtime.bigint();
146172
- lastDataAt = start;
146173
- const res = originalRowHandler.apply(query2, [packet, connection2]);
146174
- const end2 = process.hrtime.bigint();
146175
- lastRowParsedAt = end2;
146176
- lastParseTime = ms(start, end2);
146177
- parseTime += lastParseTime;
146178
- bytesReceived += packet.length();
146179
- if (!res || packet.isEOF()) {
146180
- return res;
146181
- }
146182
- return wrappedRowListener;
146183
- };
146184
- query2.row = wrappedRowListener;
146185
- query2.on("result", () => {
146186
- rowCount += 1;
146187
- });
146188
- query2.on("error", (err2) => {
146189
- reject(err2);
146190
- });
146191
- query2.on("end", () => {
146192
- resolve2();
146193
- });
146194
- });
146195
- queryCompletedAt = process.hrtime.bigint();
146196
- let querySentTime = ms(querySentAt, firstDataAt) - executionTime;
146197
- if (querySentTime < 0) {
146198
- const percent = 0.1;
146199
- const overflow = -querySentTime;
146200
- const keepForSent = overflow * percent;
146201
- const adjustedOverflow = overflow * (1 + percent);
146202
- const total2 = executionTime;
146203
- const ratioExecution = executionTime / total2;
146204
- executionTime -= adjustedOverflow * ratioExecution;
146205
- querySentTime = keepForSent;
146206
- }
146207
- const networkLatencyBefore = querySentTime / 2;
146208
- const networkLatencyAfter = querySentTime / 2;
146209
- const downloadTime = ms(firstDataAt, lastDataAt) - (rowCount > 1 ? parseTime - lastParseTime : 0);
146210
- const total = ms(querySentAt, queryCompletedAt);
146211
- const calculatedTotal = networkLatencyBefore + executionTime + networkLatencyAfter + downloadTime + parseTime + ms(lastRowParsedAt, queryCompletedAt);
146212
- const errorMargin = Math.abs(total - calculatedTotal);
146213
- return {
146214
- networkLatencyBefore,
146215
- planning: null,
146216
- execution: executionTime,
146217
- networkLatencyAfter,
146218
- dataDownload: downloadTime,
146219
- dataParse: parseTime,
146220
- total,
146221
- errorMargin,
146222
- dataSize: bytesReceived
146223
- };
146224
- };
146225
- const benchmarkProxy = async ({ sql, params }, repeats) => {
146226
- const { createConnection: createConnection2 } = await import("mysql2");
146227
- let startAt = 0n;
146228
- let tcpConnectedAt = 0n;
146229
- let tlsConnectedAt = null;
146230
- const createStream = ({ config }) => {
146231
- let stream;
146232
- if (config.socketPath) {
146233
- stream = net.connect(config.socketPath);
146234
- } else {
146235
- stream = net.connect(config.port, config.host);
146236
- }
146237
- if (config.enableKeepAlive) {
146238
- stream.on("connect", () => {
146239
- stream.setKeepAlive(true, config.keepAliveInitialDelay);
146240
- });
146241
- }
146242
- stream.setNoDelay(true);
146243
- stream.once("connect", () => {
146244
- tcpConnectedAt = process.hrtime.bigint();
146245
- });
146246
- return stream;
146247
- };
146248
- startAt = process.hrtime.bigint();
146249
- const connection2 = result2.url ? createConnection2({
146250
- uri: result2.url,
146251
- stream: createStream
146252
- }) : createConnection2({
146253
- ...result2.credentials,
146254
- stream: createStream
146255
- });
146256
- await new Promise((resolve2, reject) => {
146257
- connection2.connect((err2) => {
146258
- tlsConnectedAt = process.hrtime.bigint();
146259
- if (err2) {
146260
- reject(err2);
146261
- } else {
146262
- resolve2();
146263
- }
146264
- });
146265
- });
146266
- const results = [];
146267
- for (let i7 = 0; i7 < repeats; i7++) {
146268
- const r7 = await benchmarkQuery(connection2, sql, params);
146269
- results.push(r7);
146270
- }
146271
- connection2.end();
146272
- return {
146273
- tcpHandshake: ms(startAt, tcpConnectedAt),
146274
- tlsHandshake: tlsConnectedAt ? ms(tcpConnectedAt, tlsConnectedAt) : null,
146275
- dbHandshake: null,
146276
- queries: results
146277
- };
146278
- };
146279
146110
  return {
146280
146111
  db: { query },
146281
146112
  packageName: "mysql2",
146282
146113
  proxy,
146283
146114
  transactionProxy,
146284
- benchmarkProxy,
146285
146115
  database: result2.database,
146286
146116
  migrate: migrateFn
146287
146117
  };
@@ -146431,9 +146261,7 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
146431
146261
  migrate: migrateFn
146432
146262
  };
146433
146263
  }
146434
- console.error(
146435
- "To connect to MsSQL database - please install 'mssql' driver"
146436
- );
146264
+ console.error("To connect to MsSQL database - please install 'mssql' driver");
146437
146265
  process.exit(1);
146438
146266
  };
146439
146267
  prepareSqliteParams = (params, driver2) => {
@@ -146538,7 +146366,10 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
146538
146366
  await remoteCallback(query2, [], "run");
146539
146367
  };
146540
146368
  const proxy = async (params) => {
146541
- const preparedParams = prepareSqliteParams(params.params || [], "d1-http");
146369
+ const preparedParams = prepareSqliteParams(
146370
+ params.params || [],
146371
+ "d1-http"
146372
+ );
146542
146373
  const result2 = await remoteCallback(
146543
146374
  params.sql,
146544
146375
  preparedParams,
@@ -146763,17 +146594,19 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
146763
146594
  };
146764
146595
  const transactionProxy = async (queries) => {
146765
146596
  const results = [];
146766
- const tx = sqlite.transaction((queries2) => {
146767
- for (const query of queries2) {
146768
- let result2 = [];
146769
- if (query.method === "values" || query.method === "get" || query.method === "all") {
146770
- result2 = sqlite.prepare(query.sql).all();
146771
- } else {
146772
- sqlite.prepare(query.sql).run();
146597
+ const tx = sqlite.transaction(
146598
+ (queries2) => {
146599
+ for (const query of queries2) {
146600
+ let result2 = [];
146601
+ if (query.method === "values" || query.method === "get" || query.method === "all") {
146602
+ result2 = sqlite.prepare(query.sql).all();
146603
+ } else {
146604
+ sqlite.prepare(query.sql).run();
146605
+ }
146606
+ results.push(result2);
146773
146607
  }
146774
- results.push(result2);
146775
146608
  }
146776
- });
146609
+ );
146777
146610
  try {
146778
146611
  tx(queries);
146779
146612
  } catch (error3) {
@@ -146781,7 +146614,13 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
146781
146614
  }
146782
146615
  return results;
146783
146616
  };
146784
- return { ...db, packageName: "better-sqlite3", proxy, transactionProxy, migrate: migrateFn };
146617
+ return {
146618
+ ...db,
146619
+ packageName: "better-sqlite3",
146620
+ proxy,
146621
+ transactionProxy,
146622
+ migrate: migrateFn
146623
+ };
146785
146624
  }
146786
146625
  if (await checkPackage("bun")) {
146787
146626
  console.log(withStyle.info(`Using 'bun' driver for database querying`));
@@ -148835,8 +148674,8 @@ ${sql}
148835
148674
  `;
148836
148675
  return content;
148837
148676
  };
148838
- prepareSnapshotFolderName = (ms2) => {
148839
- const now = ms2 ? new Date(ms2) : /* @__PURE__ */ new Date();
148677
+ prepareSnapshotFolderName = (ms) => {
148678
+ const now = ms ? new Date(ms) : /* @__PURE__ */ new Date();
148840
148679
  return `${now.getFullYear()}${two(now.getUTCMonth() + 1)}${two(
148841
148680
  now.getUTCDate()
148842
148681
  )}${two(now.getUTCHours())}${two(now.getUTCMinutes())}${two(
@@ -152321,6 +152160,7 @@ var init_cors = __esm({
152321
152160
  // src/cli/commands/studio.ts
152322
152161
  var studio_exports = {};
152323
152162
  __export(studio_exports, {
152163
+ drizzleForDuckDb: () => drizzleForDuckDb,
152324
152164
  drizzleForLibSQL: () => drizzleForLibSQL,
152325
152165
  drizzleForMySQL: () => drizzleForMySQL,
152326
152166
  drizzleForPostgres: () => drizzleForPostgres,
@@ -152351,7 +152191,7 @@ import { getTableConfig as singlestoreTableConfig, SingleStoreTable } from "driz
152351
152191
  import { getTableConfig as sqliteTableConfig, SQLiteTable } from "drizzle-orm/sqlite-core";
152352
152192
  import fs10 from "fs";
152353
152193
  import { createServer } from "https";
152354
- var preparePgSchema, prepareMySqlSchema, prepareMsSqlSchema, prepareSQLiteSchema, prepareSingleStoreSchema, getCustomDefaults, drizzleForPostgres, drizzleForMySQL, drizzleForSQLite, drizzleForLibSQL, drizzleForSingleStore, extractRelations, init2, proxySchema, transactionProxySchema, benchmarkProxySchema, defaultsSchema, schema5, jsonStringify, prepareServer;
152194
+ var preparePgSchema, prepareMySqlSchema, prepareMsSqlSchema, prepareSQLiteSchema, prepareSingleStoreSchema, getCustomDefaults, drizzleForPostgres, drizzleForDuckDb, drizzleForMySQL, drizzleForSQLite, drizzleForLibSQL, drizzleForSingleStore, extractRelations, init2, proxySchema, transactionProxySchema, defaultsSchema, schema5, jsonStringify, prepareServer;
152355
152195
  var init_studio = __esm({
152356
152196
  "src/cli/commands/studio.ts"() {
152357
152197
  "use strict";
@@ -152565,7 +152405,6 @@ var init_studio = __esm({
152565
152405
  packageName: db.packageName,
152566
152406
  proxy: db.proxy,
152567
152407
  transactionProxy: db.transactionProxy,
152568
- benchmarkProxy: db.benchmarkProxy,
152569
152408
  customDefaults,
152570
152409
  schema: pgSchema2,
152571
152410
  relations: relations2,
@@ -152573,9 +152412,26 @@ var init_studio = __esm({
152573
152412
  casing: casing2
152574
152413
  };
152575
152414
  };
152415
+ drizzleForDuckDb = async (credentials) => {
152416
+ const { prepareDuckDb: prepareDuckDb2 } = await Promise.resolve().then(() => (init_connections(), connections_exports));
152417
+ const db = await prepareDuckDb2(credentials);
152418
+ const dbUrl = `duckdb://${credentials.url}`;
152419
+ const dbHash = createHash4("sha256").update(dbUrl).digest("hex");
152420
+ return {
152421
+ dbHash,
152422
+ dialect: "duckdb",
152423
+ driver: void 0,
152424
+ packageName: db.packageName,
152425
+ proxy: db.proxy,
152426
+ transactionProxy: db.transactionProxy,
152427
+ customDefaults: [],
152428
+ schema: {},
152429
+ relations: {}
152430
+ };
152431
+ };
152576
152432
  drizzleForMySQL = async (credentials, mysqlSchema, relations2, schemaFiles, casing2) => {
152577
152433
  const { connectToMySQL: connectToMySQL2 } = await Promise.resolve().then(() => (init_connections(), connections_exports));
152578
- const { proxy, transactionProxy, benchmarkProxy, database, packageName } = await connectToMySQL2(credentials);
152434
+ const { proxy, transactionProxy, database, packageName } = await connectToMySQL2(credentials);
152579
152435
  const customDefaults = getCustomDefaults(mysqlSchema, casing2);
152580
152436
  let dbUrl;
152581
152437
  if ("url" in credentials) {
@@ -152591,7 +152447,6 @@ var init_studio = __esm({
152591
152447
  databaseName: database,
152592
152448
  proxy,
152593
152449
  transactionProxy,
152594
- benchmarkProxy,
152595
152450
  customDefaults,
152596
152451
  schema: mysqlSchema,
152597
152452
  relations: relations2,
@@ -152761,23 +152616,6 @@ var init_studio = __esm({
152761
152616
  ]).optional()
152762
152617
  }).array()
152763
152618
  });
152764
- benchmarkProxySchema = external_exports.object({
152765
- type: external_exports.literal("bproxy"),
152766
- data: external_exports.object({
152767
- query: external_exports.object({
152768
- sql: external_exports.string(),
152769
- params: external_exports.array(external_exports.any()).optional(),
152770
- method: external_exports.union([
152771
- external_exports.literal("values"),
152772
- external_exports.literal("get"),
152773
- external_exports.literal("all"),
152774
- external_exports.literal("run"),
152775
- external_exports.literal("execute")
152776
- ]).optional()
152777
- }),
152778
- repeats: external_exports.number().min(1).optional()
152779
- })
152780
- });
152781
152619
  defaultsSchema = external_exports.object({
152782
152620
  type: external_exports.literal("defaults"),
152783
152621
  data: external_exports.array(
@@ -152792,7 +152630,6 @@ var init_studio = __esm({
152792
152630
  init2,
152793
152631
  proxySchema,
152794
152632
  transactionProxySchema,
152795
- benchmarkProxySchema,
152796
152633
  defaultsSchema
152797
152634
  ]);
152798
152635
  jsonStringify = (data) => {
@@ -152815,7 +152652,6 @@ var init_studio = __esm({
152815
152652
  databaseName,
152816
152653
  proxy,
152817
152654
  transactionProxy,
152818
- benchmarkProxy,
152819
152655
  customDefaults,
152820
152656
  schema: drizzleSchema,
152821
152657
  relations: relations2,
@@ -152879,7 +152715,7 @@ var init_studio = __esm({
152879
152715
  console.warn("Error message:", error3.message);
152880
152716
  }
152881
152717
  return c6.json({
152882
- version: "6.3",
152718
+ version: "6.2",
152883
152719
  dialect: dialect6,
152884
152720
  driver: driver2,
152885
152721
  packageName,
@@ -152917,21 +152753,6 @@ var init_studio = __esm({
152917
152753
  }
152918
152754
  );
152919
152755
  }
152920
- if (type === "bproxy") {
152921
- if (!benchmarkProxy) {
152922
- throw new Error("Benchmark proxy is not configured for this database.");
152923
- }
152924
- const result2 = await benchmarkProxy(body.data.query, body.data.repeats || 1);
152925
- const res = jsonStringify(result2);
152926
- return c6.body(
152927
- res,
152928
- {
152929
- headers: {
152930
- "Content-Type": "application/json"
152931
- }
152932
- }
152933
- );
152934
- }
152935
152756
  if (type === "defaults") {
152936
152757
  const columns = body.data;
152937
152758
  const result2 = columns.map((column8) => {