drizzle-kit 1.0.0-beta.2-09cddcb → 1.0.0-beta.2-1be5069

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/bin.cjs CHANGED
@@ -28623,41 +28623,41 @@ var require_ms = __commonJS({
28623
28623
  return void 0;
28624
28624
  }
28625
28625
  }
28626
- function fmtShort(ms) {
28627
- var msAbs = Math.abs(ms);
28626
+ function fmtShort(ms2) {
28627
+ var msAbs = Math.abs(ms2);
28628
28628
  if (msAbs >= d5) {
28629
- return Math.round(ms / d5) + "d";
28629
+ return Math.round(ms2 / d5) + "d";
28630
28630
  }
28631
28631
  if (msAbs >= h6) {
28632
- return Math.round(ms / h6) + "h";
28632
+ return Math.round(ms2 / h6) + "h";
28633
28633
  }
28634
28634
  if (msAbs >= m6) {
28635
- return Math.round(ms / m6) + "m";
28635
+ return Math.round(ms2 / m6) + "m";
28636
28636
  }
28637
28637
  if (msAbs >= s6) {
28638
- return Math.round(ms / s6) + "s";
28638
+ return Math.round(ms2 / s6) + "s";
28639
28639
  }
28640
- return ms + "ms";
28640
+ return ms2 + "ms";
28641
28641
  }
28642
- function fmtLong(ms) {
28643
- var msAbs = Math.abs(ms);
28642
+ function fmtLong(ms2) {
28643
+ var msAbs = Math.abs(ms2);
28644
28644
  if (msAbs >= d5) {
28645
- return plural2(ms, msAbs, d5, "day");
28645
+ return plural2(ms2, msAbs, d5, "day");
28646
28646
  }
28647
28647
  if (msAbs >= h6) {
28648
- return plural2(ms, msAbs, h6, "hour");
28648
+ return plural2(ms2, msAbs, h6, "hour");
28649
28649
  }
28650
28650
  if (msAbs >= m6) {
28651
- return plural2(ms, msAbs, m6, "minute");
28651
+ return plural2(ms2, msAbs, m6, "minute");
28652
28652
  }
28653
28653
  if (msAbs >= s6) {
28654
- return plural2(ms, msAbs, s6, "second");
28654
+ return plural2(ms2, msAbs, s6, "second");
28655
28655
  }
28656
- return ms + " ms";
28656
+ return ms2 + " ms";
28657
28657
  }
28658
- function plural2(ms, msAbs, n5, name) {
28658
+ function plural2(ms2, msAbs, n5, name) {
28659
28659
  var isPlural = msAbs >= n5 * 1.5;
28660
- return Math.round(ms / n5) + " " + name + (isPlural ? "s" : "");
28660
+ return Math.round(ms2 / n5) + " " + name + (isPlural ? "s" : "");
28661
28661
  }
28662
28662
  }
28663
28663
  });
@@ -28700,8 +28700,8 @@ var require_common2 = __commonJS({
28700
28700
  }
28701
28701
  const self2 = debug;
28702
28702
  const curr = Number(/* @__PURE__ */ new Date());
28703
- const ms = curr - (prevTime || curr);
28704
- self2.diff = ms;
28703
+ const ms2 = curr - (prevTime || curr);
28704
+ self2.diff = ms2;
28705
28705
  self2.prev = prevTime;
28706
28706
  self2.curr = curr;
28707
28707
  prevTime = curr;
@@ -35839,8 +35839,8 @@ ${sql}
35839
35839
  `;
35840
35840
  return content;
35841
35841
  };
35842
- prepareSnapshotFolderName = (ms) => {
35843
- const now = ms ? new Date(ms) : /* @__PURE__ */ new Date();
35842
+ prepareSnapshotFolderName = (ms2) => {
35843
+ const now = ms2 ? new Date(ms2) : /* @__PURE__ */ new Date();
35844
35844
  return `${now.getFullYear()}${two(now.getUTCMonth() + 1)}${two(
35845
35845
  now.getUTCDate()
35846
35846
  )}${two(now.getUTCHours())}${two(now.getUTCMinutes())}${two(
@@ -55589,7 +55589,7 @@ var require_websocket = __commonJS({
55589
55589
  var EventEmitter = require("events");
55590
55590
  var https2 = require("https");
55591
55591
  var http3 = require("http");
55592
- var net = require("net");
55592
+ var net2 = require("net");
55593
55593
  var tls = require("tls");
55594
55594
  var { randomBytes, createHash: createHash2 } = require("crypto");
55595
55595
  var { Duplex, Readable: Readable2 } = require("stream");
@@ -56320,12 +56320,12 @@ var require_websocket = __commonJS({
56320
56320
  }
56321
56321
  function netConnect(options) {
56322
56322
  options.path = options.socketPath;
56323
- return net.connect(options);
56323
+ return net2.connect(options);
56324
56324
  }
56325
56325
  function tlsConnect(options) {
56326
56326
  options.path = void 0;
56327
56327
  if (!options.servername && options.servername !== "") {
56328
- options.servername = net.isIP(options.host) ? "" : options.host;
56328
+ options.servername = net2.isIP(options.host) ? "" : options.host;
56329
56329
  }
56330
56330
  return tls.connect(options);
56331
56331
  }
@@ -58616,7 +58616,7 @@ var require_dist_cjs14 = __commonJS({
58616
58616
  return transformedHeaders;
58617
58617
  };
58618
58618
  var timing = {
58619
- setTimeout: (cb, ms) => setTimeout(cb, ms),
58619
+ setTimeout: (cb, ms2) => setTimeout(cb, ms2),
58620
58620
  clearTimeout: (timeoutId) => clearTimeout(timeoutId)
58621
58621
  };
58622
58622
  var DEFER_EVENT_LISTENER_TIME$2 = 1e3;
@@ -61675,13 +61675,13 @@ var init_schema_date_utils = __esm({
61675
61675
  if (!matches) {
61676
61676
  throw new TypeError(`Invalid RFC3339 timestamp format ${value}`);
61677
61677
  }
61678
- const [, yearStr, monthStr, dayStr, hours, minutes, seconds, , ms, offsetStr] = matches;
61678
+ const [, yearStr, monthStr, dayStr, hours, minutes, seconds, , ms2, offsetStr] = matches;
61679
61679
  range(monthStr, 1, 12);
61680
61680
  range(dayStr, 1, 31);
61681
61681
  range(hours, 0, 23);
61682
61682
  range(minutes, 0, 59);
61683
61683
  range(seconds, 0, 60);
61684
- 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));
61684
+ 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));
61685
61685
  date2.setUTCFullYear(Number(yearStr));
61686
61686
  if (offsetStr.toUpperCase() != "Z") {
61687
61687
  const [, sign, offsetH, offsetM] = /([+-])(\d\d):(\d\d)/.exec(offsetStr) || [void 0, "+", 0, 0];
@@ -81572,8 +81572,8 @@ var require_datetime2 = __commonJS({
81572
81572
  if (!(object instanceof Date)) {
81573
81573
  throw new errors_1.InvalidArgumentError(`a Date instance was expected, got "${object}"`);
81574
81574
  }
81575
- const ms = object.getTime() - TIMESHIFT;
81576
- const us = ms * 1e3;
81575
+ const ms2 = object.getTime() - TIMESHIFT;
81576
+ const us = ms2 * 1e3;
81577
81577
  buf.writeInt32(8);
81578
81578
  buf.writeInt64(us);
81579
81579
  }
@@ -81583,12 +81583,12 @@ var require_datetime2 = __commonJS({
81583
81583
  return ctx.postDecode(this, us2 + BI_TIMESHIFT_US);
81584
81584
  }
81585
81585
  const us = Number(buf.readBigInt64());
81586
- let ms = Math.round(us / 1e3);
81587
- if (Math.abs(us % 1e3) === 500 && Math.abs(ms) % 2 === 1) {
81588
- ms -= 1;
81586
+ let ms2 = Math.round(us / 1e3);
81587
+ if (Math.abs(us % 1e3) === 500 && Math.abs(ms2) % 2 === 1) {
81588
+ ms2 -= 1;
81589
81589
  }
81590
- ms += TIMESHIFT;
81591
- return new Date(ms);
81590
+ ms2 += TIMESHIFT;
81591
+ return new Date(ms2);
81592
81592
  }
81593
81593
  };
81594
81594
  exports2.DateTimeCodec = DateTimeCodec;
@@ -81609,8 +81609,8 @@ var require_datetime2 = __commonJS({
81609
81609
  if (!(object instanceof datetime_1.LocalDateTime)) {
81610
81610
  throw new errors_1.InvalidArgumentError(`a LocalDateTime instance was expected, got "${object}"`);
81611
81611
  }
81612
- const ms = BigInt(datetime_1.localDateInstances.get(object).getTime() - TIMESHIFT);
81613
- let us = ms * 1000n + BigInt(object.hour * 36e8 + object.minute * 6e7 + object.second * 1e6 + object.millisecond * 1e3 + object.microsecond);
81612
+ const ms2 = BigInt(datetime_1.localDateInstances.get(object).getTime() - TIMESHIFT);
81613
+ let us = ms2 * 1000n + BigInt(object.hour * 36e8 + object.minute * 6e7 + object.second * 1e6 + object.millisecond * 1e3 + object.microsecond);
81614
81614
  if (object.nanosecond === 500 && Math.abs(object.microsecond) % 2 === 1 || object.nanosecond > 500) {
81615
81615
  us += 1n;
81616
81616
  }
@@ -81624,13 +81624,13 @@ var require_datetime2 = __commonJS({
81624
81624
  }
81625
81625
  const bi_ms = bi_us / 1000n;
81626
81626
  let us = Number(bi_us - bi_ms * 1000n);
81627
- let ms = Number(bi_ms);
81627
+ let ms2 = Number(bi_ms);
81628
81628
  if (us < 0) {
81629
81629
  us += 1e3;
81630
- ms -= 1;
81630
+ ms2 -= 1;
81631
81631
  }
81632
- ms += TIMESHIFT;
81633
- const date2 = new Date(ms);
81632
+ ms2 += TIMESHIFT;
81633
+ const date2 = new Date(ms2);
81634
81634
  return new datetime_1.LocalDateTime(date2.getUTCFullYear(), date2.getUTCMonth() + 1, date2.getUTCDate(), date2.getUTCHours(), date2.getUTCMinutes(), date2.getUTCSeconds(), date2.getUTCMilliseconds(), us);
81635
81635
  }
81636
81636
  };
@@ -81692,13 +81692,13 @@ var require_datetime2 = __commonJS({
81692
81692
  }
81693
81693
  let us = Number(bius);
81694
81694
  let seconds = Math.floor(us / 1e6);
81695
- const ms = Math.floor(us % 1e6 / 1e3);
81696
- us = us % 1e6 - ms * 1e3;
81695
+ const ms2 = Math.floor(us % 1e6 / 1e3);
81696
+ us = us % 1e6 - ms2 * 1e3;
81697
81697
  let minutes = Math.floor(seconds / 60);
81698
81698
  seconds = Math.floor(seconds % 60);
81699
81699
  const hours = Math.floor(minutes / 60);
81700
81700
  minutes = Math.floor(minutes % 60);
81701
- return new datetime_1.LocalTime(hours, minutes, seconds, ms, us);
81701
+ return new datetime_1.LocalTime(hours, minutes, seconds, ms2, us);
81702
81702
  }
81703
81703
  };
81704
81704
  exports2.LocalTimeCodec = LocalTimeCodec;
@@ -81775,14 +81775,14 @@ var require_datetime2 = __commonJS({
81775
81775
  const biMillion = 1000000n;
81776
81776
  const biSeconds = bius / biMillion;
81777
81777
  let us = Number(bius - biSeconds * biMillion);
81778
- const ms = Math.floor(us / 1e3);
81778
+ const ms2 = Math.floor(us / 1e3);
81779
81779
  us = us % 1e3;
81780
81780
  let seconds = Number(biSeconds);
81781
81781
  let minutes = Math.floor(seconds / 60);
81782
81782
  seconds = Math.floor(seconds % 60);
81783
81783
  const hours = Math.floor(minutes / 60);
81784
81784
  minutes = Math.floor(minutes % 60);
81785
- return new datetime_1.Duration(0, 0, 0, 0, hours * sign, minutes * sign, seconds * sign, ms * sign, us * sign);
81785
+ return new datetime_1.Duration(0, 0, 0, 0, hours * sign, minutes * sign, seconds * sign, ms2 * sign, us * sign);
81786
81786
  }
81787
81787
  };
81788
81788
  exports2.DurationCodec = DurationCodec;
@@ -81828,7 +81828,7 @@ var require_datetime2 = __commonJS({
81828
81828
  const million = BigInt(1e6);
81829
81829
  const biSeconds = bius / million;
81830
81830
  let us = Number(bius - biSeconds * million);
81831
- const ms = Math.trunc(us / 1e3);
81831
+ const ms2 = Math.trunc(us / 1e3);
81832
81832
  us = us % 1e3;
81833
81833
  let seconds = Number(biSeconds);
81834
81834
  let minutes = Math.trunc(seconds / 60);
@@ -81839,7 +81839,7 @@ var require_datetime2 = __commonJS({
81839
81839
  days = Math.trunc(days % 7);
81840
81840
  const years = Math.trunc(months2 / 12);
81841
81841
  months2 = Math.trunc(months2 % 12);
81842
- return new datetime_1.RelativeDuration(years, months2, weeks, days, hours * sign, minutes * sign, seconds * sign, ms * sign, us * sign);
81842
+ return new datetime_1.RelativeDuration(years, months2, weeks, days, hours * sign, minutes * sign, seconds * sign, ms2 * sign, us * sign);
81843
81843
  }
81844
81844
  };
81845
81845
  exports2.RelativeDurationCodec = RelativeDurationCodec;
@@ -106326,11 +106326,11 @@ var require_TokenExpiredError = __commonJS({
106326
106326
  // ../node_modules/.pnpm/jsonwebtoken@9.0.2/node_modules/jsonwebtoken/lib/timespan.js
106327
106327
  var require_timespan = __commonJS({
106328
106328
  "../node_modules/.pnpm/jsonwebtoken@9.0.2/node_modules/jsonwebtoken/lib/timespan.js"(exports2, module2) {
106329
- var ms = require_ms();
106329
+ var ms2 = require_ms();
106330
106330
  module2.exports = function(time2, iat) {
106331
106331
  var timestamp = iat || Math.floor(Date.now() / 1e3);
106332
106332
  if (typeof time2 === "string") {
106333
- var milliseconds = ms(time2);
106333
+ var milliseconds = ms2(time2);
106334
106334
  if (typeof milliseconds === "undefined") {
106335
106335
  return;
106336
106336
  }
@@ -120917,7 +120917,7 @@ var require_dist = __commonJS({
120917
120917
  };
120918
120918
  Object.defineProperty(exports2, "__esModule", { value: true });
120919
120919
  exports2.Agent = void 0;
120920
- var net = __importStar2(require("net"));
120920
+ var net2 = __importStar2(require("net"));
120921
120921
  var http3 = __importStar2(require("http"));
120922
120922
  var https_1 = require("https");
120923
120923
  __exportStar2(require_helpers2(), exports2);
@@ -120957,7 +120957,7 @@ var require_dist = __commonJS({
120957
120957
  if (!this.sockets[name]) {
120958
120958
  this.sockets[name] = [];
120959
120959
  }
120960
- const fakeSocket = new net.Socket({ writable: false });
120960
+ const fakeSocket = new net2.Socket({ writable: false });
120961
120961
  this.sockets[name].push(fakeSocket);
120962
120962
  this.totalSocketCount++;
120963
120963
  return fakeSocket;
@@ -121169,7 +121169,7 @@ var require_dist2 = __commonJS({
121169
121169
  };
121170
121170
  Object.defineProperty(exports2, "__esModule", { value: true });
121171
121171
  exports2.HttpsProxyAgent = void 0;
121172
- var net = __importStar2(require("net"));
121172
+ var net2 = __importStar2(require("net"));
121173
121173
  var tls = __importStar2(require("tls"));
121174
121174
  var assert_1 = __importDefault2(require("assert"));
121175
121175
  var debug_1 = __importDefault2(require_src2());
@@ -121178,7 +121178,7 @@ var require_dist2 = __commonJS({
121178
121178
  var parse_proxy_response_1 = require_parse_proxy_response();
121179
121179
  var debug = (0, debug_1.default)("https-proxy-agent");
121180
121180
  var setServernameFromNonIpHost = (options) => {
121181
- if (options.servername === void 0 && options.host && !net.isIP(options.host)) {
121181
+ if (options.servername === void 0 && options.host && !net2.isIP(options.host)) {
121182
121182
  return {
121183
121183
  ...options,
121184
121184
  servername: options.host
@@ -121218,10 +121218,10 @@ var require_dist2 = __commonJS({
121218
121218
  socket = tls.connect(setServernameFromNonIpHost(this.connectOpts));
121219
121219
  } else {
121220
121220
  debug("Creating `net.Socket`: %o", this.connectOpts);
121221
- socket = net.connect(this.connectOpts);
121221
+ socket = net2.connect(this.connectOpts);
121222
121222
  }
121223
121223
  const headers = typeof this.proxyHeaders === "function" ? this.proxyHeaders() : { ...this.proxyHeaders };
121224
- const host = net.isIPv6(opts.host) ? `[${opts.host}]` : opts.host;
121224
+ const host = net2.isIPv6(opts.host) ? `[${opts.host}]` : opts.host;
121225
121225
  let payload2 = `CONNECT ${host}:${opts.port} HTTP/1.1\r
121226
121226
  `;
121227
121227
  if (proxy.username || proxy.password) {
@@ -121254,7 +121254,7 @@ var require_dist2 = __commonJS({
121254
121254
  return socket;
121255
121255
  }
121256
121256
  socket.destroy();
121257
- const fakeSocket = new net.Socket({ writable: false });
121257
+ const fakeSocket = new net2.Socket({ writable: false });
121258
121258
  fakeSocket.readable = true;
121259
121259
  req.once("socket", (s6) => {
121260
121260
  debug("Replaying proxy buffer for failed request");
@@ -121319,7 +121319,7 @@ var require_dist3 = __commonJS({
121319
121319
  };
121320
121320
  Object.defineProperty(exports2, "__esModule", { value: true });
121321
121321
  exports2.HttpProxyAgent = void 0;
121322
- var net = __importStar2(require("net"));
121322
+ var net2 = __importStar2(require("net"));
121323
121323
  var tls = __importStar2(require("tls"));
121324
121324
  var debug_1 = __importDefault2(require_src2());
121325
121325
  var events_1 = require("events");
@@ -121392,7 +121392,7 @@ var require_dist3 = __commonJS({
121392
121392
  socket = tls.connect(this.connectOpts);
121393
121393
  } else {
121394
121394
  debug("Creating `net.Socket`: %o", this.connectOpts);
121395
- socket = net.connect(this.connectOpts);
121395
+ socket = net2.connect(this.connectOpts);
121396
121396
  }
121397
121397
  await (0, events_1.once)(socket, "connect");
121398
121398
  return socket;
@@ -160306,7 +160306,7 @@ var require_connection = __commonJS({
160306
160306
  var _crypto = _interopRequireDefault(require("crypto"));
160307
160307
  var _os = _interopRequireDefault(require("os"));
160308
160308
  var tls = _interopRequireWildcard(require("tls"));
160309
- var net = _interopRequireWildcard(require("net"));
160309
+ var net2 = _interopRequireWildcard(require("net"));
160310
160310
  var _dns = _interopRequireDefault(require("dns"));
160311
160311
  var _constants = _interopRequireDefault(require("constants"));
160312
160312
  var _stream = require("stream");
@@ -161355,7 +161355,7 @@ var require_connection = __commonJS({
161355
161355
  async wrapWithTls(socket, signal) {
161356
161356
  signal.throwIfAborted();
161357
161357
  const secureContext = tls.createSecureContext(this.secureContextOptions);
161358
- const serverName = !net.isIP(this.config.server) ? this.config.server : "";
161358
+ const serverName = !net2.isIP(this.config.server) ? this.config.server : "";
161359
161359
  const encryptOptions = {
161360
161360
  host: this.config.server,
161361
161361
  socket,
@@ -164282,10 +164282,11 @@ function parseMssqlUrl(url) {
164282
164282
  }
164283
164283
  };
164284
164284
  }
164285
- var normalisePGliteUrl, preparePostgresDB, prepareCockroach, prepareGelDB, parseSingleStoreCredentials, connectToSingleStore, parseMysqlCredentials, connectToMySQL, parseMssqlCredentials, connectToMsSQL, prepareSqliteParams, preparePGliteParams, connectToSQLite, connectToLibSQL;
164285
+ var import_net, ms, normalisePGliteUrl, preparePostgresDB, prepareCockroach, prepareGelDB, parseSingleStoreCredentials, connectToSingleStore, parseMysqlCredentials, connectToMySQL, parseMssqlCredentials, connectToMsSQL, prepareSqliteParams, preparePGliteParams, connectToSQLite, connectToLibSQL;
164286
164286
  var init_connections = __esm({
164287
164287
  "src/cli/connections.ts"() {
164288
164288
  "use strict";
164289
+ import_net = __toESM(require("net"));
164289
164290
  init_src();
164290
164291
  init_wrapper();
164291
164292
  init_utils2();
@@ -164293,6 +164294,7 @@ var init_connections = __esm({
164293
164294
  init_when_json_met_bigint();
164294
164295
  init_utils4();
164295
164296
  init_outputs();
164297
+ ms = (a5, b5) => Number(b5 - a5) / 1e6;
164296
164298
  normalisePGliteUrl = (it2) => {
164297
164299
  if (it2.startsWith("file:")) {
164298
164300
  return it2.substring(5);
@@ -164447,13 +164449,13 @@ var init_connections = __esm({
164447
164449
  return pg.types.getTypeParser(typeId, format2);
164448
164450
  }
164449
164451
  };
164450
- const client = "url" in credentials2 ? new pg.Pool({ connectionString: credentials2.url, max: 1 }) : new pg.Pool({ ...credentials2, ssl, max: 1 });
164451
- const db = drizzle({ client });
164452
+ const pool = "url" in credentials2 ? new pg.Pool({ connectionString: credentials2.url, max: 1 }) : new pg.Pool({ ...credentials2, ssl, max: 1 });
164453
+ const db = drizzle({ client: pool });
164452
164454
  const migrateFn = async (config) => {
164453
164455
  return migrate2(db, config);
164454
164456
  };
164455
164457
  const query = async (sql, params) => {
164456
- const result2 = await client.query({
164458
+ const result2 = await pool.query({
164457
164459
  text: sql,
164458
164460
  values: params ?? [],
164459
164461
  types: types3
@@ -164463,7 +164465,7 @@ var init_connections = __esm({
164463
164465
  return result2.rows;
164464
164466
  };
164465
164467
  const proxy = async (params) => {
164466
- const result2 = await client.query({
164468
+ const result2 = await pool.query({
164467
164469
  text: params.sql,
164468
164470
  values: params.params,
164469
164471
  ...params.mode === "array" && { rowMode: "array" },
@@ -164475,7 +164477,7 @@ var init_connections = __esm({
164475
164477
  };
164476
164478
  const transactionProxy = async (queries) => {
164477
164479
  const results = [];
164478
- const tx = await client.connect();
164480
+ const tx = await pool.connect();
164479
164481
  try {
164480
164482
  await tx.query("BEGIN");
164481
164483
  for (const query2 of queries) {
@@ -164494,7 +164496,117 @@ var init_connections = __esm({
164494
164496
  }
164495
164497
  return results;
164496
164498
  };
164497
- return { packageName: "pg", query, proxy, transactionProxy, migrate: migrateFn };
164499
+ const benchmarkQuery = async (client, sql, params) => {
164500
+ const explainResult = await pool.query({
164501
+ text: `EXPLAIN ANALYZE ${sql}`,
164502
+ values: params ?? [],
164503
+ types: types3
164504
+ });
164505
+ const stringifiedResult = JSON.stringify(explainResult.rows);
164506
+ const planningMatch = stringifiedResult.match(/Planning Time:\s*([\d.]+)\s*ms/i);
164507
+ const executionMatch = stringifiedResult.match(/Execution Time:\s*([\d.]+)\s*ms/i);
164508
+ let planningTime = Number(planningMatch[1]);
164509
+ let executionTime = Number(executionMatch[1]);
164510
+ let querySentAt = 0n;
164511
+ let firstDataAt = 0n;
164512
+ let lastDataAt = 0n;
164513
+ let lastRowParsedAt = 0n;
164514
+ let queryCompletedAt = 0n;
164515
+ let bytesReceived = 0;
164516
+ let rowCount = 0;
164517
+ let parseTime = 0;
164518
+ const rowDescriptionListener = (data2) => {
164519
+ if (firstDataAt === 0n) {
164520
+ firstDataAt = process.hrtime.bigint();
164521
+ }
164522
+ bytesReceived += data2.length;
164523
+ };
164524
+ const originalRowListener = client.connection.listeners("dataRow")[0];
164525
+ const wrappedRowListener = (data2) => {
164526
+ rowCount += 1;
164527
+ const start = process.hrtime.bigint();
164528
+ lastDataAt = start;
164529
+ originalRowListener.apply(client.connection, [data2]);
164530
+ const end2 = process.hrtime.bigint();
164531
+ lastRowParsedAt = end2;
164532
+ parseTime += ms(start, end2);
164533
+ bytesReceived += data2.length;
164534
+ };
164535
+ client.connection.removeAllListeners("dataRow");
164536
+ client.connection.addListener("dataRow", wrappedRowListener);
164537
+ client.connection.prependListener("rowDescription", rowDescriptionListener);
164538
+ querySentAt = process.hrtime.bigint();
164539
+ await client.query({
164540
+ text: sql,
164541
+ values: params,
164542
+ types: types3
164543
+ });
164544
+ queryCompletedAt = process.hrtime.bigint();
164545
+ client.connection.removeListener("rowDescription", rowDescriptionListener);
164546
+ client.connection.removeAllListeners("dataRow");
164547
+ client.connection.addListener("dataRow", originalRowListener);
164548
+ let querySentTime = ms(querySentAt, firstDataAt) - executionTime - planningTime;
164549
+ if (querySentTime < 0) {
164550
+ const percent = 0.1;
164551
+ const overflow = -querySentTime;
164552
+ const keepForSent = overflow * percent;
164553
+ const adjustedOverflow = overflow * (1 + percent);
164554
+ const total2 = planningTime + executionTime;
164555
+ const ratioPlanning = planningTime / total2;
164556
+ const ratioExecution = executionTime / total2;
164557
+ planningTime -= adjustedOverflow * ratioPlanning;
164558
+ executionTime -= adjustedOverflow * ratioExecution;
164559
+ querySentTime = keepForSent;
164560
+ }
164561
+ const networkLatencyBefore = querySentTime / 2;
164562
+ const networkLatencyAfter = querySentTime / 2;
164563
+ const downloadTime = ms(firstDataAt, lastDataAt) - (rowCount > 1 ? parseTime - parseTime / rowCount : 0);
164564
+ const total = ms(querySentAt, queryCompletedAt);
164565
+ const calculatedTotal = networkLatencyBefore + planningTime + executionTime + networkLatencyAfter + downloadTime + parseTime + ms(lastRowParsedAt, queryCompletedAt);
164566
+ const errorMargin = Math.abs(total - calculatedTotal);
164567
+ return {
164568
+ networkLatencyBefore,
164569
+ planning: planningTime,
164570
+ execution: executionTime,
164571
+ networkLatencyAfter,
164572
+ dataDownload: downloadTime,
164573
+ dataParse: parseTime,
164574
+ total,
164575
+ errorMargin,
164576
+ dataSize: bytesReceived
164577
+ };
164578
+ };
164579
+ const benchmarkProxy = async ({ sql, params }, repeats) => {
164580
+ let startAt = 0n;
164581
+ let tcpConnectedAt = 0n;
164582
+ let tlsConnectedAt = null;
164583
+ let dbReadyAt = 0n;
164584
+ const client = "url" in credentials2 ? new pg.Client({ connectionString: credentials2.url }) : new pg.Client({ ...credentials2, ssl });
164585
+ client.connection.once("connect", () => {
164586
+ tcpConnectedAt = process.hrtime.bigint();
164587
+ });
164588
+ client.connection.prependOnceListener("sslconnect", () => {
164589
+ tlsConnectedAt = process.hrtime.bigint();
164590
+ });
164591
+ client.connection.prependOnceListener("readyForQuery", () => {
164592
+ dbReadyAt = process.hrtime.bigint();
164593
+ });
164594
+ startAt = process.hrtime.bigint();
164595
+ await client.connect();
164596
+ const results = [];
164597
+ for (let i6 = 0; i6 < repeats; i6++) {
164598
+ const r6 = await benchmarkQuery(client, sql, params);
164599
+ results.push(r6);
164600
+ }
164601
+ await client.end();
164602
+ return {
164603
+ tcpHandshake: ms(startAt, tcpConnectedAt),
164604
+ tlsHandshake: tlsConnectedAt ? ms(tcpConnectedAt, tlsConnectedAt) : null,
164605
+ dbHandshake: ms(tlsConnectedAt ?? tcpConnectedAt, dbReadyAt),
164606
+ queries: results
164607
+ };
164608
+ };
164609
+ return { packageName: "pg", query, proxy, transactionProxy, benchmarkProxy, migrate: migrateFn };
164498
164610
  }
164499
164611
  if (await checkPackage("postgres")) {
164500
164612
  console.log(
@@ -164989,7 +165101,6 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
164989
165101
  }
164990
165102
  return next();
164991
165103
  };
164992
- await connection.connect();
164993
165104
  const query = async (sql, params) => {
164994
165105
  const res = await connection.execute({
164995
165106
  sql,
@@ -165029,11 +165140,144 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
165029
165140
  }
165030
165141
  return results;
165031
165142
  };
165143
+ const benchmarkQuery = async (newConnection, sql, params) => {
165144
+ const explainResult = await connection.query({
165145
+ sql: `EXPLAIN ANALYZE ${sql}`,
165146
+ values: params ?? [],
165147
+ typeCast
165148
+ });
165149
+ const stringifiedResult = JSON.stringify(explainResult[0]);
165150
+ const timeMatch = stringifiedResult.match(
165151
+ /actual time=([0-9.eE+-]+)\.\.([0-9.eE+-]+)/
165152
+ );
165153
+ const lastRowTime = Number(timeMatch[2]);
165154
+ const executionTime = lastRowTime;
165155
+ let querySentAt = 0n;
165156
+ let firstDataAt = 0n;
165157
+ let lastDataAt = 0n;
165158
+ let lastRowParsedAt = 0n;
165159
+ let queryCompletedAt = 0n;
165160
+ let bytesReceived = 0;
165161
+ let rowCount = 0;
165162
+ let parseTime = 0;
165163
+ querySentAt = process.hrtime.bigint();
165164
+ await new Promise((resolve3, reject) => {
165165
+ const query2 = newConnection.query({
165166
+ sql,
165167
+ values: params ?? [],
165168
+ typeCast
165169
+ });
165170
+ const originalRowHandler = query2.row;
165171
+ let packets = 0;
165172
+ const wrappedRowListener = (packet, connection2) => {
165173
+ packets += 1;
165174
+ if (firstDataAt === 0n) {
165175
+ firstDataAt = process.hrtime.bigint();
165176
+ bytesReceived += packet.start;
165177
+ }
165178
+ const start = process.hrtime.bigint();
165179
+ lastDataAt = start;
165180
+ const res = originalRowHandler.apply(query2, [packet, connection2]);
165181
+ const end2 = process.hrtime.bigint();
165182
+ lastRowParsedAt = end2;
165183
+ parseTime += ms(start, end2);
165184
+ bytesReceived += packet.length();
165185
+ if (!res || packet.isEOF()) {
165186
+ return res;
165187
+ }
165188
+ return wrappedRowListener;
165189
+ };
165190
+ query2.row = wrappedRowListener;
165191
+ query2.on("result", () => {
165192
+ rowCount += 1;
165193
+ });
165194
+ query2.on("error", (err2) => {
165195
+ reject(err2);
165196
+ });
165197
+ query2.on("end", () => {
165198
+ resolve3();
165199
+ });
165200
+ });
165201
+ queryCompletedAt = process.hrtime.bigint();
165202
+ const querySentTime = ms(querySentAt, firstDataAt) - executionTime;
165203
+ const networkLatencyBefore = querySentTime / 2;
165204
+ const networkLatencyAfter = querySentTime / 2;
165205
+ const downloadTime = ms(firstDataAt, lastDataAt) - (rowCount > 1 ? parseTime - parseTime / rowCount : 0);
165206
+ const total = ms(querySentAt, queryCompletedAt);
165207
+ const calculatedTotal = networkLatencyBefore + executionTime + networkLatencyAfter + downloadTime + parseTime + ms(lastRowParsedAt, queryCompletedAt);
165208
+ const errorMargin = Math.abs(total - calculatedTotal);
165209
+ return {
165210
+ networkLatencyBefore,
165211
+ planning: null,
165212
+ execution: executionTime,
165213
+ networkLatencyAfter,
165214
+ dataDownload: downloadTime,
165215
+ dataParse: parseTime,
165216
+ total,
165217
+ errorMargin,
165218
+ dataSize: bytesReceived
165219
+ };
165220
+ };
165221
+ const benchmarkProxy = async ({ sql, params }, repeats) => {
165222
+ const { createConnection: createConnection2 } = await import("mysql2");
165223
+ let startAt = 0n;
165224
+ let tcpConnectedAt = 0n;
165225
+ let tlsConnectedAt = null;
165226
+ const createStream = ({ config }) => {
165227
+ let stream;
165228
+ if (config.socketPath) {
165229
+ stream = import_net.default.connect(config.socketPath);
165230
+ } else {
165231
+ stream = import_net.default.connect(config.port, config.host);
165232
+ }
165233
+ if (config.enableKeepAlive) {
165234
+ stream.on("connect", () => {
165235
+ stream.setKeepAlive(true, config.keepAliveInitialDelay);
165236
+ });
165237
+ }
165238
+ stream.setNoDelay(true);
165239
+ stream.once("connect", () => {
165240
+ tcpConnectedAt = process.hrtime.bigint();
165241
+ });
165242
+ return stream;
165243
+ };
165244
+ startAt = process.hrtime.bigint();
165245
+ const connection2 = result2.url ? createConnection2({
165246
+ uri: result2.url,
165247
+ stream: createStream
165248
+ }) : createConnection2({
165249
+ ...result2.credentials,
165250
+ stream: createStream
165251
+ });
165252
+ await new Promise((resolve3, reject) => {
165253
+ connection2.connect((err2) => {
165254
+ tlsConnectedAt = process.hrtime.bigint();
165255
+ if (err2) {
165256
+ reject(err2);
165257
+ } else {
165258
+ resolve3();
165259
+ }
165260
+ });
165261
+ });
165262
+ const results = [];
165263
+ for (let i6 = 0; i6 < repeats; i6++) {
165264
+ const r6 = await benchmarkQuery(connection2, sql, params);
165265
+ results.push(r6);
165266
+ }
165267
+ connection2.end();
165268
+ return {
165269
+ tcpHandshake: ms(startAt, tcpConnectedAt),
165270
+ tlsHandshake: tlsConnectedAt ? ms(tcpConnectedAt, tlsConnectedAt) : null,
165271
+ dbHandshake: null,
165272
+ queries: results
165273
+ };
165274
+ };
165032
165275
  return {
165033
165276
  db: { query },
165034
165277
  packageName: "mysql2",
165035
165278
  proxy,
165036
165279
  transactionProxy,
165280
+ benchmarkProxy,
165037
165281
  database: result2.database,
165038
165282
  migrate: migrateFn
165039
165283
  };
@@ -176688,7 +176932,7 @@ __export(studio_exports, {
176688
176932
  prepareServer: () => prepareServer,
176689
176933
  prepareSingleStoreSchema: () => prepareSingleStoreSchema
176690
176934
  });
176691
- var import_crypto11, import_drizzle_orm8, import_relations8, import_mssql_core3, import_mysql_core3, import_pg_core3, import_singlestore_core2, import_sqlite_core3, import_fs16, import_node_https2, preparePgSchema, prepareMySqlSchema, prepareMsSqlSchema, prepareSQLiteSchema, prepareSingleStoreSchema, getCustomDefaults, drizzleForPostgres, drizzleForMySQL, drizzleForSQLite, drizzleForLibSQL, drizzleForSingleStore, extractRelations, init, proxySchema, transactionProxySchema, defaultsSchema, schema5, jsonStringify, prepareServer;
176935
+ var import_crypto11, import_drizzle_orm8, import_relations8, import_mssql_core3, import_mysql_core3, import_pg_core3, import_singlestore_core2, import_sqlite_core3, import_fs16, import_node_https2, preparePgSchema, prepareMySqlSchema, prepareMsSqlSchema, prepareSQLiteSchema, prepareSingleStoreSchema, getCustomDefaults, drizzleForPostgres, drizzleForMySQL, drizzleForSQLite, drizzleForLibSQL, drizzleForSingleStore, extractRelations, init, proxySchema, transactionProxySchema, benchmarkProxySchema, defaultsSchema, schema5, jsonStringify, prepareServer;
176692
176936
  var init_studio = __esm({
176693
176937
  "src/cli/commands/studio.ts"() {
176694
176938
  "use strict";
@@ -176912,6 +177156,7 @@ var init_studio = __esm({
176912
177156
  packageName: db.packageName,
176913
177157
  proxy: db.proxy,
176914
177158
  transactionProxy: db.transactionProxy,
177159
+ benchmarkProxy: db.benchmarkProxy,
176915
177160
  customDefaults,
176916
177161
  schema: pgSchema2,
176917
177162
  relations: relations5,
@@ -176921,7 +177166,7 @@ var init_studio = __esm({
176921
177166
  };
176922
177167
  drizzleForMySQL = async (credentials2, mysqlSchema, relations5, schemaFiles, casing2) => {
176923
177168
  const { connectToMySQL: connectToMySQL2 } = await Promise.resolve().then(() => (init_connections(), connections_exports));
176924
- const { proxy, transactionProxy, database, packageName } = await connectToMySQL2(credentials2);
177169
+ const { proxy, transactionProxy, benchmarkProxy, database, packageName } = await connectToMySQL2(credentials2);
176925
177170
  const customDefaults = getCustomDefaults(mysqlSchema, casing2);
176926
177171
  let dbUrl;
176927
177172
  if ("url" in credentials2) {
@@ -176937,6 +177182,7 @@ var init_studio = __esm({
176937
177182
  databaseName: database,
176938
177183
  proxy,
176939
177184
  transactionProxy,
177185
+ benchmarkProxy,
176940
177186
  customDefaults,
176941
177187
  schema: mysqlSchema,
176942
177188
  relations: relations5,
@@ -177106,6 +177352,23 @@ var init_studio = __esm({
177106
177352
  ]).optional()
177107
177353
  }).array()
177108
177354
  });
177355
+ benchmarkProxySchema = external_exports.object({
177356
+ type: external_exports.literal("bproxy"),
177357
+ data: external_exports.object({
177358
+ query: external_exports.object({
177359
+ sql: external_exports.string(),
177360
+ params: external_exports.array(external_exports.any()).optional(),
177361
+ method: external_exports.union([
177362
+ external_exports.literal("values"),
177363
+ external_exports.literal("get"),
177364
+ external_exports.literal("all"),
177365
+ external_exports.literal("run"),
177366
+ external_exports.literal("execute")
177367
+ ]).optional()
177368
+ }),
177369
+ repeats: external_exports.number().min(1).optional()
177370
+ })
177371
+ });
177109
177372
  defaultsSchema = external_exports.object({
177110
177373
  type: external_exports.literal("defaults"),
177111
177374
  data: external_exports.array(
@@ -177120,6 +177383,7 @@ var init_studio = __esm({
177120
177383
  init,
177121
177384
  proxySchema,
177122
177385
  transactionProxySchema,
177386
+ benchmarkProxySchema,
177123
177387
  defaultsSchema
177124
177388
  ]);
177125
177389
  jsonStringify = (data2) => {
@@ -177142,6 +177406,7 @@ var init_studio = __esm({
177142
177406
  databaseName,
177143
177407
  proxy,
177144
177408
  transactionProxy,
177409
+ benchmarkProxy,
177145
177410
  customDefaults,
177146
177411
  schema: drizzleSchema,
177147
177412
  relations: relations5,
@@ -177205,7 +177470,7 @@ var init_studio = __esm({
177205
177470
  console.warn("Error message:", error4.message);
177206
177471
  }
177207
177472
  return c5.json({
177208
- version: "6.2",
177473
+ version: "6.3",
177209
177474
  dialect: dialect6,
177210
177475
  driver: driver2,
177211
177476
  packageName,
@@ -177243,6 +177508,21 @@ var init_studio = __esm({
177243
177508
  }
177244
177509
  );
177245
177510
  }
177511
+ if (type === "bproxy") {
177512
+ if (!benchmarkProxy) {
177513
+ throw new Error("Benchmark proxy is not configured for this database.");
177514
+ }
177515
+ const result2 = await benchmarkProxy(body.data.query, body.data.repeats || 1);
177516
+ const res = jsonStringify(result2);
177517
+ return c5.body(
177518
+ res,
177519
+ {
177520
+ headers: {
177521
+ "Content-Type": "application/json"
177522
+ }
177523
+ }
177524
+ );
177525
+ }
177246
177526
  if (type === "defaults") {
177247
177527
  const columns = body.data;
177248
177528
  const result2 = columns.map((column12) => {