drizzle-kit 1.0.0-beta.2-4e5ecef → 1.0.0-beta.2-f9236e3

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,8 +15199,7 @@ var init_schemaValidator = __esm({
15199
15199
  "singlestore",
15200
15200
  "gel",
15201
15201
  "mssql",
15202
- "cockroach",
15203
- "duckdb"
15202
+ "cockroach"
15204
15203
  ];
15205
15204
  dialect = enumType(dialects);
15206
15205
  }
@@ -24990,7 +24989,7 @@ var init_introspect = __esm({
24990
24989
  let checksCount = 0;
24991
24990
  let viewsCount = 0;
24992
24991
  for (const seq of sequencesList) {
24993
- const depend = dependList.find((it) => Number(it.oid) === Number(seq.oid));
24992
+ const depend = dependList.find((it) => it.oid === seq.oid);
24994
24993
  if (depend && (depend.deptype === "a" || depend.deptype === "i")) {
24995
24994
  continue;
24996
24995
  }
@@ -25056,22 +25055,22 @@ var init_introspect = __esm({
25056
25055
  continue;
25057
25056
  }
25058
25057
  const expr = serialsList.find(
25059
- (it) => Number(it.tableId) === Number(column8.tableId) && it.ordinality === column8.ordinality
25058
+ (it) => it.tableId === column8.tableId && it.ordinality === column8.ordinality
25060
25059
  );
25061
25060
  if (expr) {
25062
- const table7 = tablesList.find((it) => Number(it.oid) === Number(column8.tableId));
25061
+ const table7 = tablesList.find((it) => it.oid === column8.tableId);
25063
25062
  const isSerial = isSerialExpression(expr.expression, table7.schema);
25064
25063
  column8.type = isSerial ? type === "bigint" ? "bigserial" : type === "integer" ? "serial" : "smallserial" : type;
25065
25064
  }
25066
25065
  }
25067
25066
  for (const column8 of columnsList.filter((x6) => x6.kind === "r" || x6.kind === "p")) {
25068
- const table7 = tablesList.find((it) => Number(it.oid) === Number(column8.tableId));
25067
+ const table7 = tablesList.find((it) => it.oid === column8.tableId);
25069
25068
  const enumType2 = column8.typeId in groupedEnums ? groupedEnums[column8.typeId] : column8.typeId in groupedArrEnums ? groupedArrEnums[column8.typeId] : null;
25070
25069
  let columnTypeMapped = enumType2 ? enumType2.name : column8.type.replaceAll("[]", "");
25071
25070
  columnTypeMapped = columnTypeMapped.replace("character varying", "varchar").replace(" without time zone", "").replace("character", "char").replace("geometry(Point", "geometry(point");
25072
25071
  columnTypeMapped = trimChar(columnTypeMapped, '"');
25073
25072
  const columnDefault = defaultsList.find(
25074
- (it) => Number(it.tableId) === Number(column8.tableId) && it.ordinality === column8.ordinality
25073
+ (it) => it.tableId === column8.tableId && it.ordinality === column8.ordinality
25075
25074
  );
25076
25075
  const defaultValue = defaultForColumn(
25077
25076
  columnTypeMapped,
@@ -25080,10 +25079,10 @@ var init_introspect = __esm({
25080
25079
  Boolean(enumType2)
25081
25080
  );
25082
25081
  const unique = constraintsList.find((it) => {
25083
- return it.type === "u" && Number(it.tableId) === Number(column8.tableId) && it.columnsOrdinals.length === 1 && it.columnsOrdinals.includes(column8.ordinality);
25082
+ return it.type === "u" && it.tableId === column8.tableId && it.columnsOrdinals.length === 1 && it.columnsOrdinals.includes(column8.ordinality);
25084
25083
  }) ?? null;
25085
25084
  const pk = constraintsList.find((it) => {
25086
- return it.type === "p" && Number(it.tableId) === Number(column8.tableId) && it.columnsOrdinals.length === 1 && it.columnsOrdinals.includes(column8.ordinality);
25085
+ return it.type === "p" && it.tableId === column8.tableId && it.columnsOrdinals.length === 1 && it.columnsOrdinals.includes(column8.ordinality);
25087
25086
  }) ?? null;
25088
25087
  const metadata = column8.metadata;
25089
25088
  if (column8.generatedType === "s" && (!metadata || !metadata.expression)) {
@@ -25098,7 +25097,7 @@ ${JSON.stringify(column8.metadata)}`
25098
25097
  ${JSON.stringify(column8.metadata)}`
25099
25098
  );
25100
25099
  }
25101
- const sequence = metadata?.seqId ? sequencesList.find((it) => Number(it.oid) === Number(metadata.seqId)) ?? null : null;
25100
+ const sequence = metadata?.seqId ? sequencesList.find((it) => it.oid === Number(metadata.seqId)) ?? null : null;
25102
25101
  columns.push({
25103
25102
  entityType: "columns",
25104
25103
  schema: table7.schema,
@@ -25128,12 +25127,10 @@ ${JSON.stringify(column8.metadata)}`
25128
25127
  });
25129
25128
  }
25130
25129
  for (const unique of constraintsList.filter((it) => it.type === "u")) {
25131
- const table7 = tablesList.find((it) => Number(it.oid) === Number(unique.tableId));
25132
- const schema6 = namespaces.find((it) => Number(it.oid) === Number(unique.schemaId));
25130
+ const table7 = tablesList.find((it) => it.oid === unique.tableId);
25131
+ const schema6 = namespaces.find((it) => it.oid === unique.schemaId);
25133
25132
  const columns2 = unique.columnsOrdinals.map((it) => {
25134
- const column8 = columnsList.find(
25135
- (column9) => Number(column9.tableId) === Number(unique.tableId) && column9.ordinality === it
25136
- );
25133
+ const column8 = columnsList.find((column9) => column9.tableId === unique.tableId && column9.ordinality === it);
25137
25134
  return column8.name;
25138
25135
  });
25139
25136
  uniques.push({
@@ -25147,12 +25144,10 @@ ${JSON.stringify(column8.metadata)}`
25147
25144
  });
25148
25145
  }
25149
25146
  for (const pk of constraintsList.filter((it) => it.type === "p")) {
25150
- const table7 = tablesList.find((it) => Number(it.oid) === Number(pk.tableId));
25151
- const schema6 = namespaces.find((it) => Number(it.oid) === Number(pk.schemaId));
25147
+ const table7 = tablesList.find((it) => it.oid === pk.tableId);
25148
+ const schema6 = namespaces.find((it) => it.oid === pk.schemaId);
25152
25149
  const columns2 = pk.columnsOrdinals.map((it) => {
25153
- const column8 = columnsList.find(
25154
- (column9) => Number(column9.tableId) === Number(pk.tableId) && column9.ordinality === it
25155
- );
25150
+ const column8 = columnsList.find((column9) => column9.tableId === pk.tableId && column9.ordinality === it);
25156
25151
  return column8.name;
25157
25152
  });
25158
25153
  pks.push({
@@ -25165,19 +25160,15 @@ ${JSON.stringify(column8.metadata)}`
25165
25160
  });
25166
25161
  }
25167
25162
  for (const fk6 of constraintsList.filter((it) => it.type === "f")) {
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));
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);
25171
25166
  const columns2 = fk6.columnsOrdinals.map((it) => {
25172
- const column8 = columnsList.find(
25173
- (column9) => Number(column9.tableId) === Number(fk6.tableId) && column9.ordinality === it
25174
- );
25167
+ const column8 = columnsList.find((column9) => column9.tableId === fk6.tableId && column9.ordinality === it);
25175
25168
  return column8.name;
25176
25169
  });
25177
25170
  const columnsTo = fk6.columnsToOrdinals.map((it) => {
25178
- const column8 = columnsList.find(
25179
- (column9) => Number(column9.tableId) === Number(fk6.tableToId) && column9.ordinality === it
25180
- );
25171
+ const column8 = columnsList.find((column9) => column9.tableId === fk6.tableToId && column9.ordinality === it);
25181
25172
  return column8.name;
25182
25173
  });
25183
25174
  fks.push({
@@ -25195,8 +25186,8 @@ ${JSON.stringify(column8.metadata)}`
25195
25186
  });
25196
25187
  }
25197
25188
  for (const check of constraintsList.filter((it) => it.type === "c")) {
25198
- const table7 = tablesList.find((it) => Number(it.oid) === Number(check.tableId));
25199
- const schema6 = namespaces.find((it) => Number(it.oid) === Number(check.schemaId));
25189
+ const table7 = tablesList.find((it) => it.oid === check.tableId);
25190
+ const schema6 = namespaces.find((it) => it.oid === check.schemaId);
25200
25191
  checks.push({
25201
25192
  entityType: "checks",
25202
25193
  schema: schema6.name,
@@ -25257,10 +25248,10 @@ ${JSON.stringify(column8.metadata)}`
25257
25248
  });
25258
25249
  for (const idx of idxs) {
25259
25250
  const { metadata } = idx;
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));
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);
25262
25253
  const expr = splitExpressions(metadata.expression);
25263
- const table7 = tablesList.find((it) => Number(it.oid) === Number(idx.metadata.tableId));
25254
+ const table7 = tablesList.find((it) => it.oid === idx.metadata.tableId);
25264
25255
  const nonColumnsCount = metadata.columnOrdinals.reduce((acc, it) => {
25265
25256
  if (it === 0) acc += 1;
25266
25257
  return acc;
@@ -25292,7 +25283,7 @@ ${JSON.stringify(column8.metadata)}`
25292
25283
  k6 += 1;
25293
25284
  } else {
25294
25285
  const column8 = columnsList.find((column9) => {
25295
- return Number(column9.tableId) === Number(metadata.tableId) && column9.ordinality === ordinal;
25286
+ return column9.tableId === metadata.tableId && column9.ordinality === ordinal;
25296
25287
  });
25297
25288
  if (!column8) throw new Error(`missing column: ${metadata.tableId}:${ordinal}`);
25298
25289
  const options = opts[i7];
@@ -25341,7 +25332,7 @@ ${JSON.stringify(column8.metadata)}`
25341
25332
  progressCallback("indexes", indexesCount, "fetching");
25342
25333
  progressCallback("tables", tableCount, "done");
25343
25334
  for (const it of columnsList.filter((x6) => x6.kind === "m" || x6.kind === "v")) {
25344
- const view6 = viewsList.find((x6) => Number(x6.oid) === Number(it.tableId));
25335
+ const view6 = viewsList.find((x6) => x6.oid === it.tableId);
25345
25336
  const typeDimensions = it.type.split("[]").length - 1;
25346
25337
  const enumType2 = it.typeId in groupedEnums ? groupedEnums[it.typeId] : it.typeId in groupedArrEnums ? groupedArrEnums[it.typeId] : null;
25347
25338
  let columnTypeMapped = enumType2 ? enumType2.name : it.type.replace("[]", "");
@@ -25364,8 +25355,8 @@ ${JSON.stringify(column8.metadata)}`
25364
25355
  }
25365
25356
  for (const view6 of viewsList) {
25366
25357
  tableCount += 1;
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;
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;
25369
25360
  const definition = parseViewDefinition(view6.definition);
25370
25361
  const withOpts = wrapRecord(
25371
25362
  view6.options?.reduce((acc, it) => {
@@ -34404,7 +34395,7 @@ var require_websocket = __commonJS({
34404
34395
  var EventEmitter = require("events");
34405
34396
  var https2 = require("https");
34406
34397
  var http3 = require("http");
34407
- var net = require("net");
34398
+ var net2 = require("net");
34408
34399
  var tls = require("tls");
34409
34400
  var { randomBytes, createHash: createHash5 } = require("crypto");
34410
34401
  var { Duplex, Readable: Readable6 } = require("stream");
@@ -35135,12 +35126,12 @@ var require_websocket = __commonJS({
35135
35126
  }
35136
35127
  function netConnect(options) {
35137
35128
  options.path = options.socketPath;
35138
- return net.connect(options);
35129
+ return net2.connect(options);
35139
35130
  }
35140
35131
  function tlsConnect(options) {
35141
35132
  options.path = void 0;
35142
35133
  if (!options.servername && options.servername !== "") {
35143
- options.servername = net.isIP(options.host) ? "" : options.host;
35134
+ options.servername = net2.isIP(options.host) ? "" : options.host;
35144
35135
  }
35145
35136
  return tls.connect(options);
35146
35137
  }
@@ -39459,7 +39450,7 @@ var init_timing = __esm({
39459
39450
  "../node_modules/.pnpm/@smithy+node-http-handler@4.4.5/node_modules/@smithy/node-http-handler/dist-es/timing.js"() {
39460
39451
  "use strict";
39461
39452
  timing = {
39462
- setTimeout: (cb, ms) => setTimeout(cb, ms),
39453
+ setTimeout: (cb, ms2) => setTimeout(cb, ms2),
39463
39454
  clearTimeout: (timeoutId) => clearTimeout(timeoutId)
39464
39455
  };
39465
39456
  }
@@ -41347,13 +41338,13 @@ var init_schema_date_utils = __esm({
41347
41338
  if (!matches) {
41348
41339
  throw new TypeError(`Invalid RFC3339 timestamp format ${value}`);
41349
41340
  }
41350
- const [, yearStr, monthStr, dayStr, hours, minutes, seconds, , ms, offsetStr] = matches;
41341
+ const [, yearStr, monthStr, dayStr, hours, minutes, seconds, , ms2, offsetStr] = matches;
41351
41342
  range(monthStr, 1, 12);
41352
41343
  range(dayStr, 1, 31);
41353
41344
  range(hours, 0, 23);
41354
41345
  range(minutes, 0, 59);
41355
41346
  range(seconds, 0, 60);
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));
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));
41357
41348
  date2.setUTCFullYear(Number(yearStr));
41358
41349
  if (offsetStr.toUpperCase() != "Z") {
41359
41350
  const [, sign2, offsetH, offsetM] = /([+-])(\d\d):(\d\d)/.exec(offsetStr) || [void 0, "+", 0, 0];
@@ -61367,8 +61358,8 @@ var require_datetime2 = __commonJS({
61367
61358
  if (!(object instanceof Date)) {
61368
61359
  throw new errors_1.InvalidArgumentError(`a Date instance was expected, got "${object}"`);
61369
61360
  }
61370
- const ms = object.getTime() - TIMESHIFT;
61371
- const us = ms * 1e3;
61361
+ const ms2 = object.getTime() - TIMESHIFT;
61362
+ const us = ms2 * 1e3;
61372
61363
  buf.writeInt32(8);
61373
61364
  buf.writeInt64(us);
61374
61365
  }
@@ -61378,12 +61369,12 @@ var require_datetime2 = __commonJS({
61378
61369
  return ctx.postDecode(this, us2 + BI_TIMESHIFT_US);
61379
61370
  }
61380
61371
  const us = Number(buf.readBigInt64());
61381
- let ms = Math.round(us / 1e3);
61382
- if (Math.abs(us % 1e3) === 500 && Math.abs(ms) % 2 === 1) {
61383
- ms -= 1;
61372
+ let ms2 = Math.round(us / 1e3);
61373
+ if (Math.abs(us % 1e3) === 500 && Math.abs(ms2) % 2 === 1) {
61374
+ ms2 -= 1;
61384
61375
  }
61385
- ms += TIMESHIFT;
61386
- return new Date(ms);
61376
+ ms2 += TIMESHIFT;
61377
+ return new Date(ms2);
61387
61378
  }
61388
61379
  };
61389
61380
  exports2.DateTimeCodec = DateTimeCodec;
@@ -61404,8 +61395,8 @@ var require_datetime2 = __commonJS({
61404
61395
  if (!(object instanceof datetime_1.LocalDateTime)) {
61405
61396
  throw new errors_1.InvalidArgumentError(`a LocalDateTime instance was expected, got "${object}"`);
61406
61397
  }
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);
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);
61409
61400
  if (object.nanosecond === 500 && Math.abs(object.microsecond) % 2 === 1 || object.nanosecond > 500) {
61410
61401
  us += 1n;
61411
61402
  }
@@ -61419,13 +61410,13 @@ var require_datetime2 = __commonJS({
61419
61410
  }
61420
61411
  const bi_ms = bi_us / 1000n;
61421
61412
  let us = Number(bi_us - bi_ms * 1000n);
61422
- let ms = Number(bi_ms);
61413
+ let ms2 = Number(bi_ms);
61423
61414
  if (us < 0) {
61424
61415
  us += 1e3;
61425
- ms -= 1;
61416
+ ms2 -= 1;
61426
61417
  }
61427
- ms += TIMESHIFT;
61428
- const date2 = new Date(ms);
61418
+ ms2 += TIMESHIFT;
61419
+ const date2 = new Date(ms2);
61429
61420
  return new datetime_1.LocalDateTime(date2.getUTCFullYear(), date2.getUTCMonth() + 1, date2.getUTCDate(), date2.getUTCHours(), date2.getUTCMinutes(), date2.getUTCSeconds(), date2.getUTCMilliseconds(), us);
61430
61421
  }
61431
61422
  };
@@ -61487,13 +61478,13 @@ var require_datetime2 = __commonJS({
61487
61478
  }
61488
61479
  let us = Number(bius);
61489
61480
  let seconds = Math.floor(us / 1e6);
61490
- const ms = Math.floor(us % 1e6 / 1e3);
61491
- us = us % 1e6 - ms * 1e3;
61481
+ const ms2 = Math.floor(us % 1e6 / 1e3);
61482
+ us = us % 1e6 - ms2 * 1e3;
61492
61483
  let minutes = Math.floor(seconds / 60);
61493
61484
  seconds = Math.floor(seconds % 60);
61494
61485
  const hours = Math.floor(minutes / 60);
61495
61486
  minutes = Math.floor(minutes % 60);
61496
- return new datetime_1.LocalTime(hours, minutes, seconds, ms, us);
61487
+ return new datetime_1.LocalTime(hours, minutes, seconds, ms2, us);
61497
61488
  }
61498
61489
  };
61499
61490
  exports2.LocalTimeCodec = LocalTimeCodec;
@@ -61570,14 +61561,14 @@ var require_datetime2 = __commonJS({
61570
61561
  const biMillion = 1000000n;
61571
61562
  const biSeconds = bius / biMillion;
61572
61563
  let us = Number(bius - biSeconds * biMillion);
61573
- const ms = Math.floor(us / 1e3);
61564
+ const ms2 = Math.floor(us / 1e3);
61574
61565
  us = us % 1e3;
61575
61566
  let seconds = Number(biSeconds);
61576
61567
  let minutes = Math.floor(seconds / 60);
61577
61568
  seconds = Math.floor(seconds % 60);
61578
61569
  const hours = Math.floor(minutes / 60);
61579
61570
  minutes = Math.floor(minutes % 60);
61580
- return new datetime_1.Duration(0, 0, 0, 0, hours * sign2, minutes * sign2, seconds * sign2, ms * sign2, us * sign2);
61571
+ return new datetime_1.Duration(0, 0, 0, 0, hours * sign2, minutes * sign2, seconds * sign2, ms2 * sign2, us * sign2);
61581
61572
  }
61582
61573
  };
61583
61574
  exports2.DurationCodec = DurationCodec;
@@ -61623,7 +61614,7 @@ var require_datetime2 = __commonJS({
61623
61614
  const million = BigInt(1e6);
61624
61615
  const biSeconds = bius / million;
61625
61616
  let us = Number(bius - biSeconds * million);
61626
- const ms = Math.trunc(us / 1e3);
61617
+ const ms2 = Math.trunc(us / 1e3);
61627
61618
  us = us % 1e3;
61628
61619
  let seconds = Number(biSeconds);
61629
61620
  let minutes = Math.trunc(seconds / 60);
@@ -61634,7 +61625,7 @@ var require_datetime2 = __commonJS({
61634
61625
  days = Math.trunc(days % 7);
61635
61626
  const years = Math.trunc(months2 / 12);
61636
61627
  months2 = Math.trunc(months2 % 12);
61637
- return new datetime_1.RelativeDuration(years, months2, weeks, days, hours * sign2, minutes * sign2, seconds * sign2, ms * sign2, us * sign2);
61628
+ return new datetime_1.RelativeDuration(years, months2, weeks, days, hours * sign2, minutes * sign2, seconds * sign2, ms2 * sign2, us * sign2);
61638
61629
  }
61639
61630
  };
61640
61631
  exports2.RelativeDurationCodec = RelativeDurationCodec;
@@ -71798,41 +71789,41 @@ var require_ms = __commonJS({
71798
71789
  return void 0;
71799
71790
  }
71800
71791
  }
71801
- function fmtShort(ms) {
71802
- var msAbs = Math.abs(ms);
71792
+ function fmtShort(ms2) {
71793
+ var msAbs = Math.abs(ms2);
71803
71794
  if (msAbs >= d6) {
71804
- return Math.round(ms / d6) + "d";
71795
+ return Math.round(ms2 / d6) + "d";
71805
71796
  }
71806
71797
  if (msAbs >= h7) {
71807
- return Math.round(ms / h7) + "h";
71798
+ return Math.round(ms2 / h7) + "h";
71808
71799
  }
71809
71800
  if (msAbs >= m7) {
71810
- return Math.round(ms / m7) + "m";
71801
+ return Math.round(ms2 / m7) + "m";
71811
71802
  }
71812
71803
  if (msAbs >= s7) {
71813
- return Math.round(ms / s7) + "s";
71804
+ return Math.round(ms2 / s7) + "s";
71814
71805
  }
71815
- return ms + "ms";
71806
+ return ms2 + "ms";
71816
71807
  }
71817
- function fmtLong(ms) {
71818
- var msAbs = Math.abs(ms);
71808
+ function fmtLong(ms2) {
71809
+ var msAbs = Math.abs(ms2);
71819
71810
  if (msAbs >= d6) {
71820
- return plural2(ms, msAbs, d6, "day");
71811
+ return plural2(ms2, msAbs, d6, "day");
71821
71812
  }
71822
71813
  if (msAbs >= h7) {
71823
- return plural2(ms, msAbs, h7, "hour");
71814
+ return plural2(ms2, msAbs, h7, "hour");
71824
71815
  }
71825
71816
  if (msAbs >= m7) {
71826
- return plural2(ms, msAbs, m7, "minute");
71817
+ return plural2(ms2, msAbs, m7, "minute");
71827
71818
  }
71828
71819
  if (msAbs >= s7) {
71829
- return plural2(ms, msAbs, s7, "second");
71820
+ return plural2(ms2, msAbs, s7, "second");
71830
71821
  }
71831
- return ms + " ms";
71822
+ return ms2 + " ms";
71832
71823
  }
71833
- function plural2(ms, msAbs, n6, name) {
71824
+ function plural2(ms2, msAbs, n6, name) {
71834
71825
  var isPlural = msAbs >= n6 * 1.5;
71835
- return Math.round(ms / n6) + " " + name + (isPlural ? "s" : "");
71826
+ return Math.round(ms2 / n6) + " " + name + (isPlural ? "s" : "");
71836
71827
  }
71837
71828
  }
71838
71829
  });
@@ -71876,8 +71867,8 @@ var require_common2 = __commonJS({
71876
71867
  }
71877
71868
  const self2 = debug;
71878
71869
  const curr = Number(/* @__PURE__ */ new Date());
71879
- const ms = curr - (prevTime || curr);
71880
- self2.diff = ms;
71870
+ const ms2 = curr - (prevTime || curr);
71871
+ self2.diff = ms2;
71881
71872
  self2.prev = prevTime;
71882
71873
  self2.curr = curr;
71883
71874
  prevTime = curr;
@@ -87380,11 +87371,11 @@ var require_TokenExpiredError = __commonJS({
87380
87371
  var require_timespan = __commonJS({
87381
87372
  "../node_modules/.pnpm/jsonwebtoken@9.0.2/node_modules/jsonwebtoken/lib/timespan.js"(exports2, module2) {
87382
87373
  "use strict";
87383
- var ms = require_ms();
87374
+ var ms2 = require_ms();
87384
87375
  module2.exports = function(time2, iat) {
87385
87376
  var timestamp = iat || Math.floor(Date.now() / 1e3);
87386
87377
  if (typeof time2 === "string") {
87387
- var milliseconds = ms(time2);
87378
+ var milliseconds = ms2(time2);
87388
87379
  if (typeof milliseconds === "undefined") {
87389
87380
  return;
87390
87381
  }
@@ -101922,7 +101913,7 @@ var require_dist = __commonJS({
101922
101913
  };
101923
101914
  Object.defineProperty(exports2, "__esModule", { value: true });
101924
101915
  exports2.Agent = void 0;
101925
- var net = __importStar2(require("net"));
101916
+ var net2 = __importStar2(require("net"));
101926
101917
  var http3 = __importStar2(require("http"));
101927
101918
  var https_1 = require("https");
101928
101919
  __exportStar2(require_helpers2(), exports2);
@@ -101962,7 +101953,7 @@ var require_dist = __commonJS({
101962
101953
  if (!this.sockets[name]) {
101963
101954
  this.sockets[name] = [];
101964
101955
  }
101965
- const fakeSocket = new net.Socket({ writable: false });
101956
+ const fakeSocket = new net2.Socket({ writable: false });
101966
101957
  this.sockets[name].push(fakeSocket);
101967
101958
  this.totalSocketCount++;
101968
101959
  return fakeSocket;
@@ -102174,7 +102165,7 @@ var require_dist2 = __commonJS({
102174
102165
  };
102175
102166
  Object.defineProperty(exports2, "__esModule", { value: true });
102176
102167
  exports2.HttpsProxyAgent = void 0;
102177
- var net = __importStar2(require("net"));
102168
+ var net2 = __importStar2(require("net"));
102178
102169
  var tls = __importStar2(require("tls"));
102179
102170
  var assert_1 = __importDefault2(require("assert"));
102180
102171
  var debug_1 = __importDefault2(require_src2());
@@ -102183,7 +102174,7 @@ var require_dist2 = __commonJS({
102183
102174
  var parse_proxy_response_1 = require_parse_proxy_response();
102184
102175
  var debug = (0, debug_1.default)("https-proxy-agent");
102185
102176
  var setServernameFromNonIpHost = (options) => {
102186
- if (options.servername === void 0 && options.host && !net.isIP(options.host)) {
102177
+ if (options.servername === void 0 && options.host && !net2.isIP(options.host)) {
102187
102178
  return {
102188
102179
  ...options,
102189
102180
  servername: options.host
@@ -102223,10 +102214,10 @@ var require_dist2 = __commonJS({
102223
102214
  socket = tls.connect(setServernameFromNonIpHost(this.connectOpts));
102224
102215
  } else {
102225
102216
  debug("Creating `net.Socket`: %o", this.connectOpts);
102226
- socket = net.connect(this.connectOpts);
102217
+ socket = net2.connect(this.connectOpts);
102227
102218
  }
102228
102219
  const headers = typeof this.proxyHeaders === "function" ? this.proxyHeaders() : { ...this.proxyHeaders };
102229
- const host = net.isIPv6(opts.host) ? `[${opts.host}]` : opts.host;
102220
+ const host = net2.isIPv6(opts.host) ? `[${opts.host}]` : opts.host;
102230
102221
  let payload = `CONNECT ${host}:${opts.port} HTTP/1.1\r
102231
102222
  `;
102232
102223
  if (proxy.username || proxy.password) {
@@ -102259,7 +102250,7 @@ var require_dist2 = __commonJS({
102259
102250
  return socket;
102260
102251
  }
102261
102252
  socket.destroy();
102262
- const fakeSocket = new net.Socket({ writable: false });
102253
+ const fakeSocket = new net2.Socket({ writable: false });
102263
102254
  fakeSocket.readable = true;
102264
102255
  req.once("socket", (s7) => {
102265
102256
  debug("Replaying proxy buffer for failed request");
@@ -102324,7 +102315,7 @@ var require_dist3 = __commonJS({
102324
102315
  };
102325
102316
  Object.defineProperty(exports2, "__esModule", { value: true });
102326
102317
  exports2.HttpProxyAgent = void 0;
102327
- var net = __importStar2(require("net"));
102318
+ var net2 = __importStar2(require("net"));
102328
102319
  var tls = __importStar2(require("tls"));
102329
102320
  var debug_1 = __importDefault2(require_src2());
102330
102321
  var events_1 = require("events");
@@ -102397,7 +102388,7 @@ var require_dist3 = __commonJS({
102397
102388
  socket = tls.connect(this.connectOpts);
102398
102389
  } else {
102399
102390
  debug("Creating `net.Socket`: %o", this.connectOpts);
102400
- socket = net.connect(this.connectOpts);
102391
+ socket = net2.connect(this.connectOpts);
102401
102392
  }
102402
102393
  await (0, events_1.once)(socket, "connect");
102403
102394
  return socket;
@@ -141277,7 +141268,7 @@ var require_connection = __commonJS({
141277
141268
  var _crypto = _interopRequireDefault(require("crypto"));
141278
141269
  var _os = _interopRequireDefault(require("os"));
141279
141270
  var tls = _interopRequireWildcard(require("tls"));
141280
- var net = _interopRequireWildcard(require("net"));
141271
+ var net2 = _interopRequireWildcard(require("net"));
141281
141272
  var _dns = _interopRequireDefault(require("dns"));
141282
141273
  var _constants = _interopRequireDefault(require("constants"));
141283
141274
  var _stream = require("stream");
@@ -142326,7 +142317,7 @@ var require_connection = __commonJS({
142326
142317
  async wrapWithTls(socket, signal) {
142327
142318
  signal.throwIfAborted();
142328
142319
  const secureContext = tls.createSecureContext(this.secureContextOptions);
142329
- const serverName = !net.isIP(this.config.server) ? this.config.server : "";
142320
+ const serverName = !net2.isIP(this.config.server) ? this.config.server : "";
142330
142321
  const encryptOptions = {
142331
142322
  host: this.config.server,
142332
142323
  socket,
@@ -145232,7 +145223,6 @@ __export(connections_exports, {
145232
145223
  connectToSQLite: () => connectToSQLite,
145233
145224
  connectToSingleStore: () => connectToSingleStore,
145234
145225
  prepareCockroach: () => prepareCockroach,
145235
- prepareDuckDb: () => prepareDuckDb,
145236
145226
  prepareGelDB: () => prepareGelDB,
145237
145227
  preparePostgresDB: () => preparePostgresDB
145238
145228
  });
@@ -145249,10 +145239,11 @@ function parseMssqlUrl(url) {
145249
145239
  }
145250
145240
  };
145251
145241
  }
145252
- var normalisePGliteUrl, preparePostgresDB, prepareDuckDb, prepareCockroach, prepareGelDB, parseSingleStoreCredentials, connectToSingleStore, parseMysqlCredentials, connectToMySQL, parseMssqlCredentials, connectToMsSQL, prepareSqliteParams, preparePGliteParams, connectToSQLite, connectToLibSQL;
145242
+ var import_net, ms, normalisePGliteUrl, preparePostgresDB, prepareCockroach, prepareGelDB, parseSingleStoreCredentials, connectToSingleStore, parseMysqlCredentials, connectToMySQL, parseMssqlCredentials, connectToMsSQL, prepareSqliteParams, preparePGliteParams, connectToSQLite, connectToLibSQL;
145253
145243
  var init_connections = __esm({
145254
145244
  "src/cli/connections.ts"() {
145255
145245
  "use strict";
145246
+ import_net = __toESM(require("net"));
145256
145247
  init_src();
145257
145248
  init_wrapper();
145258
145249
  init_utils();
@@ -145260,6 +145251,7 @@ var init_connections = __esm({
145260
145251
  init_when_json_met_bigint();
145261
145252
  init_utils3();
145262
145253
  init_outputs();
145254
+ ms = (a6, b6) => Number(b6 - a6) / 1e6;
145263
145255
  normalisePGliteUrl = (it) => {
145264
145256
  if (it.startsWith("file:")) {
145265
145257
  return it.substring(5);
@@ -145383,13 +145375,7 @@ var init_connections = __esm({
145383
145375
  }
145384
145376
  return results;
145385
145377
  };
145386
- return {
145387
- packageName: "pglite",
145388
- query,
145389
- proxy,
145390
- transactionProxy,
145391
- migrate: migrateFn
145392
- };
145378
+ return { packageName: "pglite", query, proxy, transactionProxy, migrate: migrateFn };
145393
145379
  }
145394
145380
  assertUnreachable(driver2);
145395
145381
  }
@@ -145420,13 +145406,13 @@ var init_connections = __esm({
145420
145406
  return pg.types.getTypeParser(typeId, format2);
145421
145407
  }
145422
145408
  };
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 });
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 });
145425
145411
  const migrateFn = async (config) => {
145426
145412
  return migrate(db, config);
145427
145413
  };
145428
145414
  const query = async (sql, params) => {
145429
- const result2 = await client.query({
145415
+ const result2 = await pool.query({
145430
145416
  text: sql,
145431
145417
  values: params ?? [],
145432
145418
  types: types3
@@ -145436,7 +145422,7 @@ var init_connections = __esm({
145436
145422
  return result2.rows;
145437
145423
  };
145438
145424
  const proxy = async (params) => {
145439
- const result2 = await client.query({
145425
+ const result2 = await pool.query({
145440
145426
  text: params.sql,
145441
145427
  values: params.params,
145442
145428
  ...params.mode === "array" && { rowMode: "array" },
@@ -145448,7 +145434,7 @@ var init_connections = __esm({
145448
145434
  };
145449
145435
  const transactionProxy = async (queries) => {
145450
145436
  const results = [];
145451
- const tx = await client.connect();
145437
+ const tx = await pool.connect();
145452
145438
  try {
145453
145439
  await tx.query("BEGIN");
145454
145440
  for (const query2 of queries) {
@@ -145467,13 +145453,119 @@ var init_connections = __esm({
145467
145453
  }
145468
145454
  return results;
145469
145455
  };
145470
- return {
145471
- packageName: "pg",
145472
- query,
145473
- proxy,
145474
- transactionProxy,
145475
- migrate: migrateFn
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
+ };
145476
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
+ };
145567
+ };
145568
+ return { packageName: "pg", query, proxy, transactionProxy, benchmarkProxy, migrate: migrateFn };
145477
145569
  }
145478
145570
  if (await checkPackage("postgres")) {
145479
145571
  console.log(
@@ -145524,13 +145616,7 @@ var init_connections = __esm({
145524
145616
  }
145525
145617
  return results;
145526
145618
  };
145527
- return {
145528
- packageName: "postgres",
145529
- query,
145530
- proxy,
145531
- transactionProxy,
145532
- migrate: migrateFn
145533
- };
145619
+ return { packageName: "postgres", query, proxy, transactionProxy, migrate: migrateFn };
145534
145620
  }
145535
145621
  if (await checkPackage("@vercel/postgres")) {
145536
145622
  console.log(
@@ -145611,13 +145697,7 @@ var init_connections = __esm({
145611
145697
  }
145612
145698
  return results;
145613
145699
  };
145614
- return {
145615
- packageName: "@vercel/postgres",
145616
- query,
145617
- proxy,
145618
- transactionProxy,
145619
- migrate: migrateFn
145620
- };
145700
+ return { packageName: "@vercel/postgres", query, proxy, transactionProxy, migrate: migrateFn };
145621
145701
  }
145622
145702
  if (await checkPackage("@neondatabase/serverless")) {
145623
145703
  console.log(
@@ -145630,11 +145710,7 @@ var init_connections = __esm({
145630
145710
  "'@neondatabase/serverless' can only connect to remote Neon/Vercel Postgres/Supabase instances through a websocket"
145631
145711
  )
145632
145712
  );
145633
- const {
145634
- Pool,
145635
- neonConfig,
145636
- types: pgTypes
145637
- } = require("@neondatabase/serverless");
145713
+ const { Pool, neonConfig, types: pgTypes } = require("@neondatabase/serverless");
145638
145714
  const { drizzle } = require("drizzle-orm/neon-serverless");
145639
145715
  const { migrate } = require("drizzle-orm/neon-serverless/migrator");
145640
145716
  const ssl = "ssl" in credentials ? credentials.ssl === "prefer" || credentials.ssl === "require" || credentials.ssl === "allow" ? { rejectUnauthorized: false } : credentials.ssl === "verify-full" ? {} : credentials.ssl : {};
@@ -145704,13 +145780,7 @@ var init_connections = __esm({
145704
145780
  }
145705
145781
  return results;
145706
145782
  };
145707
- return {
145708
- packageName: "@neondatabase/serverless",
145709
- query,
145710
- proxy,
145711
- transactionProxy,
145712
- migrate: migrateFn
145713
- };
145783
+ return { packageName: "@neondatabase/serverless", query, proxy, transactionProxy, migrate: migrateFn };
145714
145784
  }
145715
145785
  if (await checkPackage("bun")) {
145716
145786
  console.log(withStyle.info(`Using 'bun' driver for database querying`));
@@ -145761,54 +145831,6 @@ var init_connections = __esm({
145761
145831
  console.warn("For the 'bun' driver, run your script using: bun --bun");
145762
145832
  process.exit(1);
145763
145833
  };
145764
- prepareDuckDb = async (credentials) => {
145765
- if (await checkPackage("@duckdb/node-api")) {
145766
- console.log(
145767
- withStyle.info(`Using '@duckdb/node-api' driver for database querying`)
145768
- );
145769
- const { DuckDBInstance } = require("@duckdb/node-api");
145770
- const instance = await DuckDBInstance.create(credentials.url);
145771
- const client = await instance.connect();
145772
- const query = async (sql, params = []) => {
145773
- const result2 = await client.run(sql, params);
145774
- const rows = await result2.getRowObjectsJson();
145775
- return rows;
145776
- };
145777
- const proxy = async (params) => {
145778
- const result2 = await client.run(params.sql, params.params);
145779
- return params.mode === "array" ? await result2.getRowsJson() : await result2.getRowObjectsJson();
145780
- };
145781
- const transactionProxy = async (queries) => {
145782
- const results = [];
145783
- try {
145784
- await client.run("BEGIN");
145785
- for (const query2 of queries) {
145786
- const result2 = await client.run(query2.sql);
145787
- results.push(await result2.getRowObjectsJson());
145788
- }
145789
- await client.run("COMMIT");
145790
- } catch (error3) {
145791
- await client.run("ROLLBACK");
145792
- results.push(error3);
145793
- }
145794
- return results;
145795
- };
145796
- return {
145797
- packageName: "@duckdb/node-api",
145798
- query,
145799
- proxy,
145800
- transactionProxy,
145801
- migrate: () => {
145802
- throw new Error("DuckDB does not support migrations");
145803
- }
145804
- };
145805
- }
145806
- console.error(
145807
- // "To connect to DuckDb database - please install either of 'duckdb', '@duckdb/node-api' drivers",
145808
- "To connect to DuckDb database - please install '@duckdb/node-api' driver"
145809
- );
145810
- process.exit(1);
145811
- };
145812
145834
  prepareCockroach = async (credentials) => {
145813
145835
  if (await checkPackage("pg")) {
145814
145836
  const { default: pg } = require("pg");
@@ -145861,7 +145883,9 @@ var init_connections = __esm({
145861
145883
  };
145862
145884
  return { query, proxy, migrate: migrateFn };
145863
145885
  }
145864
- console.error("To connect to Cockroach - please install 'pg' package");
145886
+ console.error(
145887
+ "To connect to Cockroach - please install 'pg' package"
145888
+ );
145865
145889
  process.exit(1);
145866
145890
  };
145867
145891
  prepareGelDB = async (credentials) => {
@@ -145920,7 +145944,9 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
145920
145944
  };
145921
145945
  return { packageName: "gel", query, proxy, transactionProxy };
145922
145946
  }
145923
- console.error("To connect to gel database - please install 'edgedb' driver");
145947
+ console.error(
145948
+ "To connect to gel database - please install 'edgedb' driver"
145949
+ );
145924
145950
  process.exit(1);
145925
145951
  };
145926
145952
  parseSingleStoreCredentials = (credentials) => {
@@ -146034,7 +146060,6 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
146034
146060
  }
146035
146061
  return next();
146036
146062
  };
146037
- await connection.connect();
146038
146063
  const query = async (sql, params) => {
146039
146064
  const res = await connection.execute({
146040
146065
  sql,
@@ -146074,11 +146099,156 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
146074
146099
  }
146075
146100
  return results;
146076
146101
  };
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
+ };
146077
146246
  return {
146078
146247
  db: { query },
146079
146248
  packageName: "mysql2",
146080
146249
  proxy,
146081
146250
  transactionProxy,
146251
+ benchmarkProxy,
146082
146252
  database: result2.database,
146083
146253
  migrate: migrateFn
146084
146254
  };
@@ -146228,7 +146398,9 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
146228
146398
  migrate: migrateFn
146229
146399
  };
146230
146400
  }
146231
- console.error("To connect to MsSQL database - please install 'mssql' driver");
146401
+ console.error(
146402
+ "To connect to MsSQL database - please install 'mssql' driver"
146403
+ );
146232
146404
  process.exit(1);
146233
146405
  };
146234
146406
  prepareSqliteParams = (params, driver2) => {
@@ -146333,10 +146505,7 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
146333
146505
  await remoteCallback(query2, [], "run");
146334
146506
  };
146335
146507
  const proxy = async (params) => {
146336
- const preparedParams = prepareSqliteParams(
146337
- params.params || [],
146338
- "d1-http"
146339
- );
146508
+ const preparedParams = prepareSqliteParams(params.params || [], "d1-http");
146340
146509
  const result2 = await remoteCallback(
146341
146510
  params.sql,
146342
146511
  preparedParams,
@@ -146561,19 +146730,17 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
146561
146730
  };
146562
146731
  const transactionProxy = async (queries) => {
146563
146732
  const results = [];
146564
- const tx = sqlite.transaction(
146565
- (queries2) => {
146566
- for (const query of queries2) {
146567
- let result2 = [];
146568
- if (query.method === "values" || query.method === "get" || query.method === "all") {
146569
- result2 = sqlite.prepare(query.sql).all();
146570
- } else {
146571
- sqlite.prepare(query.sql).run();
146572
- }
146573
- results.push(result2);
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();
146574
146740
  }
146741
+ results.push(result2);
146575
146742
  }
146576
- );
146743
+ });
146577
146744
  try {
146578
146745
  tx(queries);
146579
146746
  } catch (error3) {
@@ -146581,13 +146748,7 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
146581
146748
  }
146582
146749
  return results;
146583
146750
  };
146584
- return {
146585
- ...db,
146586
- packageName: "better-sqlite3",
146587
- proxy,
146588
- transactionProxy,
146589
- migrate: migrateFn
146590
- };
146751
+ return { ...db, packageName: "better-sqlite3", proxy, transactionProxy, migrate: migrateFn };
146591
146752
  }
146592
146753
  if (await checkPackage("bun")) {
146593
146754
  console.log(withStyle.info(`Using 'bun' driver for database querying`));
@@ -148641,8 +148802,8 @@ ${sql}
148641
148802
  `;
148642
148803
  return content;
148643
148804
  };
148644
- prepareSnapshotFolderName = (ms) => {
148645
- const now = ms ? new Date(ms) : /* @__PURE__ */ new Date();
148805
+ prepareSnapshotFolderName = (ms2) => {
148806
+ const now = ms2 ? new Date(ms2) : /* @__PURE__ */ new Date();
148646
148807
  return `${now.getFullYear()}${two(now.getUTCMonth() + 1)}${two(
148647
148808
  now.getUTCDate()
148648
148809
  )}${two(now.getUTCHours())}${two(now.getUTCMinutes())}${two(
@@ -152127,7 +152288,6 @@ var init_cors = __esm({
152127
152288
  // src/cli/commands/studio.ts
152128
152289
  var studio_exports = {};
152129
152290
  __export(studio_exports, {
152130
- drizzleForDuckDb: () => drizzleForDuckDb,
152131
152291
  drizzleForLibSQL: () => drizzleForLibSQL,
152132
152292
  drizzleForMySQL: () => drizzleForMySQL,
152133
152293
  drizzleForPostgres: () => drizzleForPostgres,
@@ -152141,7 +152301,7 @@ __export(studio_exports, {
152141
152301
  prepareServer: () => prepareServer,
152142
152302
  prepareSingleStoreSchema: () => prepareSingleStoreSchema
152143
152303
  });
152144
- 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;
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;
152145
152305
  var init_studio = __esm({
152146
152306
  "src/cli/commands/studio.ts"() {
152147
152307
  "use strict";
@@ -152365,6 +152525,7 @@ var init_studio = __esm({
152365
152525
  packageName: db.packageName,
152366
152526
  proxy: db.proxy,
152367
152527
  transactionProxy: db.transactionProxy,
152528
+ benchmarkProxy: db.benchmarkProxy,
152368
152529
  customDefaults,
152369
152530
  schema: pgSchema2,
152370
152531
  relations: relations2,
@@ -152372,26 +152533,9 @@ var init_studio = __esm({
152372
152533
  casing: casing2
152373
152534
  };
152374
152535
  };
152375
- drizzleForDuckDb = async (credentials) => {
152376
- const { prepareDuckDb: prepareDuckDb2 } = await Promise.resolve().then(() => (init_connections(), connections_exports));
152377
- const db = await prepareDuckDb2(credentials);
152378
- const dbUrl = `duckdb://${credentials.url}`;
152379
- const dbHash = (0, import_crypto10.createHash)("sha256").update(dbUrl).digest("hex");
152380
- return {
152381
- dbHash,
152382
- dialect: "duckdb",
152383
- driver: void 0,
152384
- packageName: db.packageName,
152385
- proxy: db.proxy,
152386
- transactionProxy: db.transactionProxy,
152387
- customDefaults: [],
152388
- schema: {},
152389
- relations: {}
152390
- };
152391
- };
152392
152536
  drizzleForMySQL = async (credentials, mysqlSchema, relations2, schemaFiles, casing2) => {
152393
152537
  const { connectToMySQL: connectToMySQL2 } = await Promise.resolve().then(() => (init_connections(), connections_exports));
152394
- const { proxy, transactionProxy, database, packageName } = await connectToMySQL2(credentials);
152538
+ const { proxy, transactionProxy, benchmarkProxy, database, packageName } = await connectToMySQL2(credentials);
152395
152539
  const customDefaults = getCustomDefaults(mysqlSchema, casing2);
152396
152540
  let dbUrl;
152397
152541
  if ("url" in credentials) {
@@ -152407,6 +152551,7 @@ var init_studio = __esm({
152407
152551
  databaseName: database,
152408
152552
  proxy,
152409
152553
  transactionProxy,
152554
+ benchmarkProxy,
152410
152555
  customDefaults,
152411
152556
  schema: mysqlSchema,
152412
152557
  relations: relations2,
@@ -152576,6 +152721,23 @@ var init_studio = __esm({
152576
152721
  ]).optional()
152577
152722
  }).array()
152578
152723
  });
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
+ });
152579
152741
  defaultsSchema = external_exports.object({
152580
152742
  type: external_exports.literal("defaults"),
152581
152743
  data: external_exports.array(
@@ -152590,6 +152752,7 @@ var init_studio = __esm({
152590
152752
  init2,
152591
152753
  proxySchema,
152592
152754
  transactionProxySchema,
152755
+ benchmarkProxySchema,
152593
152756
  defaultsSchema
152594
152757
  ]);
152595
152758
  jsonStringify = (data) => {
@@ -152612,6 +152775,7 @@ var init_studio = __esm({
152612
152775
  databaseName,
152613
152776
  proxy,
152614
152777
  transactionProxy,
152778
+ benchmarkProxy,
152615
152779
  customDefaults,
152616
152780
  schema: drizzleSchema,
152617
152781
  relations: relations2,
@@ -152675,7 +152839,7 @@ var init_studio = __esm({
152675
152839
  console.warn("Error message:", error3.message);
152676
152840
  }
152677
152841
  return c6.json({
152678
- version: "6.2",
152842
+ version: "6.3",
152679
152843
  dialect: dialect6,
152680
152844
  driver: driver2,
152681
152845
  packageName,
@@ -152713,6 +152877,21 @@ var init_studio = __esm({
152713
152877
  }
152714
152878
  );
152715
152879
  }
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
+ }
152716
152895
  if (type === "defaults") {
152717
152896
  const columns = body.data;
152718
152897
  const result2 = columns.map((column8) => {