drizzle-kit 1.0.0-beta.2-b705c25 → 1.0.0-beta.2-e689d82

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,72 @@ 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 (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
+ const planningTime = Number(planningMatch[1]);
164509
+ const executionTime = Number(executionMatch[1]);
164510
+ let startAt = 0n;
164511
+ let tcpConnectedAt = 0n;
164512
+ let tlsConnectedAt = null;
164513
+ let dbReadyAt = 0n;
164514
+ let querySentAt = 0n;
164515
+ let firstDataAt = 0n;
164516
+ let lastDataAt = 0n;
164517
+ let bytesReceived = 0;
164518
+ const client = "url" in credentials2 ? new pg.Client({ connectionString: credentials2.url }) : new pg.Client({ ...credentials2, ssl });
164519
+ client.connection.once("connect", () => {
164520
+ tcpConnectedAt = process.hrtime.bigint();
164521
+ });
164522
+ client.connection.prependOnceListener("sslconnect", () => {
164523
+ tlsConnectedAt = process.hrtime.bigint();
164524
+ });
164525
+ client.connection.prependOnceListener("readyForQuery", () => {
164526
+ dbReadyAt = process.hrtime.bigint();
164527
+ });
164528
+ client.connection.addListener("rowDescription", (data2) => {
164529
+ if (firstDataAt === 0n) {
164530
+ firstDataAt = process.hrtime.bigint();
164531
+ }
164532
+ bytesReceived += data2.length;
164533
+ });
164534
+ client.connection.addListener("dataRow", (data2) => {
164535
+ bytesReceived += data2.length;
164536
+ });
164537
+ client.connection.addListener("commandComplete", () => {
164538
+ lastDataAt = process.hrtime.bigint();
164539
+ });
164540
+ startAt = process.hrtime.bigint();
164541
+ await client.connect();
164542
+ querySentAt = process.hrtime.bigint();
164543
+ await client.query(sql, params);
164544
+ await client.end();
164545
+ return {
164546
+ tcpHandshake: ms(startAt, tcpConnectedAt),
164547
+ tlsHandshake: tlsConnectedAt ? ms(tcpConnectedAt, tlsConnectedAt) : null,
164548
+ dbHandshake: ms(tlsConnectedAt ?? tcpConnectedAt, dbReadyAt),
164549
+ planning: planningTime,
164550
+ execution: executionTime,
164551
+ dataDownload: ms(firstDataAt, lastDataAt) + ms(querySentAt, firstDataAt) - executionTime - planningTime,
164552
+ total: ms(startAt, lastDataAt),
164553
+ dataSize: bytesReceived
164554
+ };
164555
+ };
164556
+ const benchmarkProxy = async ({ sql, params }, repeats) => {
164557
+ const results = [];
164558
+ for (let i6 = 0; i6 < repeats; i6++) {
164559
+ const r6 = await benchmarkQuery(sql, params);
164560
+ results.push(r6);
164561
+ }
164562
+ return results;
164563
+ };
164564
+ return { packageName: "pg", query, proxy, transactionProxy, benchmarkProxy, migrate: migrateFn };
164498
164565
  }
164499
164566
  if (await checkPackage("postgres")) {
164500
164567
  console.log(
@@ -164757,6 +164824,7 @@ var init_connections = __esm({
164757
164824
  console.error(
164758
164825
  "To connect to Postgres database - please install either of 'pg', 'postgres', 'bun', '@neondatabase/serverless' or '@vercel/postgres' drivers"
164759
164826
  );
164827
+ console.warn("For the 'bun' driver, run your script using: bun --bun");
164760
164828
  process.exit(1);
164761
164829
  };
164762
164830
  prepareCockroach = async (credentials2) => {
@@ -164988,7 +165056,6 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
164988
165056
  }
164989
165057
  return next();
164990
165058
  };
164991
- await connection.connect();
164992
165059
  const query = async (sql, params) => {
164993
165060
  const res = await connection.execute({
164994
165061
  sql,
@@ -165028,11 +165095,111 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
165028
165095
  }
165029
165096
  return results;
165030
165097
  };
165098
+ const benchmarkQuery = async (sql, params) => {
165099
+ const { createConnection: createConnection2 } = await import("mysql2");
165100
+ const explainResult = await connection.query({
165101
+ sql: `EXPLAIN ANALYZE ${sql}`,
165102
+ values: params ?? [],
165103
+ typeCast
165104
+ });
165105
+ const stringifiedResult = JSON.stringify(explainResult[0]);
165106
+ const timeMatch = stringifiedResult.match(
165107
+ /actual time=([0-9.eE+-]+)\.\.([0-9.eE+-]+)/
165108
+ );
165109
+ const lastRowTime = Number(timeMatch[2]);
165110
+ const executionTime = lastRowTime;
165111
+ let startAt = 0n;
165112
+ let tcpConnectedAt = 0n;
165113
+ let tlsConnectedAt = null;
165114
+ let querySentAt = 0n;
165115
+ let firstDataAt = 0n;
165116
+ let lastDataAt = 0n;
165117
+ let bytesReceived = 0;
165118
+ const createStream = ({ config }) => {
165119
+ let stream;
165120
+ if (config.socketPath) {
165121
+ stream = import_net.default.connect(config.socketPath);
165122
+ } else {
165123
+ stream = import_net.default.connect(config.port, config.host);
165124
+ }
165125
+ if (config.enableKeepAlive) {
165126
+ stream.on("connect", () => {
165127
+ stream.setKeepAlive(true, config.keepAliveInitialDelay);
165128
+ });
165129
+ }
165130
+ stream.setNoDelay(true);
165131
+ stream.once("connect", () => {
165132
+ tcpConnectedAt = process.hrtime.bigint();
165133
+ });
165134
+ return stream;
165135
+ };
165136
+ startAt = process.hrtime.bigint();
165137
+ const newConnection = result2.url ? createConnection2({
165138
+ // debug: true,
165139
+ uri: result2.url,
165140
+ stream: createStream
165141
+ }) : createConnection2({
165142
+ ...result2.credentials,
165143
+ stream: createStream
165144
+ });
165145
+ await new Promise((resolve3, reject) => {
165146
+ newConnection.connect((err2) => {
165147
+ tlsConnectedAt = process.hrtime.bigint();
165148
+ if (err2) {
165149
+ reject(err2);
165150
+ } else {
165151
+ resolve3();
165152
+ }
165153
+ });
165154
+ });
165155
+ querySentAt = process.hrtime.bigint();
165156
+ await new Promise((resolve3, reject) => {
165157
+ const query2 = newConnection.query({
165158
+ sql,
165159
+ values: params ?? [],
165160
+ typeCast
165161
+ // rowsAsArray: true,
165162
+ });
165163
+ query2.on("error", (err2) => {
165164
+ reject(err2);
165165
+ });
165166
+ query2.on("fields", (fields) => {
165167
+ if (firstDataAt === 0n) {
165168
+ firstDataAt = process.hrtime.bigint();
165169
+ }
165170
+ bytesReceived += fields[0]._buf.length;
165171
+ });
165172
+ query2.on("end", () => {
165173
+ lastDataAt = process.hrtime.bigint();
165174
+ resolve3();
165175
+ newConnection.end();
165176
+ });
165177
+ });
165178
+ return {
165179
+ tcpHandshake: ms(startAt, tcpConnectedAt),
165180
+ tlsHandshake: tlsConnectedAt ? ms(tcpConnectedAt, tlsConnectedAt) : null,
165181
+ dbHandshake: null,
165182
+ planning: null,
165183
+ execution: executionTime,
165184
+ dataDownload: ms(firstDataAt, lastDataAt) + ms(querySentAt, firstDataAt) - executionTime,
165185
+ total: ms(startAt, lastDataAt),
165186
+ dataSize: bytesReceived
165187
+ };
165188
+ };
165189
+ const benchmarkProxy = async ({ sql, params }, repeats) => {
165190
+ const results = [];
165191
+ for (let i6 = 0; i6 < repeats; i6++) {
165192
+ const r6 = await benchmarkQuery(sql, params);
165193
+ results.push(r6);
165194
+ }
165195
+ return results;
165196
+ };
165031
165197
  return {
165032
165198
  db: { query },
165033
165199
  packageName: "mysql2",
165034
165200
  proxy,
165035
165201
  transactionProxy,
165202
+ benchmarkProxy,
165036
165203
  database: result2.database,
165037
165204
  migrate: migrateFn
165038
165205
  };
@@ -165138,6 +165305,7 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
165138
165305
  console.error(
165139
165306
  "To connect to MySQL database - please install either of 'mysql2', 'bun' or '@planetscale/database' drivers"
165140
165307
  );
165308
+ console.warn("For the 'bun' driver, run your script using: bun --bun");
165141
165309
  process.exit(1);
165142
165310
  };
165143
165311
  parseMssqlCredentials = (credentials2) => {
@@ -165586,6 +165754,7 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
165586
165754
  console.log(
165587
165755
  "Please install either 'better-sqlite3', 'bun', '@libsql/client' or '@tursodatabase/database' for Drizzle Kit to connect to SQLite databases"
165588
165756
  );
165757
+ console.warn("For the 'bun' driver, run your script using: bun --bun");
165589
165758
  process.exit(1);
165590
165759
  };
165591
165760
  connectToLibSQL = async (credentials2) => {
@@ -176685,7 +176854,7 @@ __export(studio_exports, {
176685
176854
  prepareServer: () => prepareServer,
176686
176855
  prepareSingleStoreSchema: () => prepareSingleStoreSchema
176687
176856
  });
176688
- 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;
176857
+ 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;
176689
176858
  var init_studio = __esm({
176690
176859
  "src/cli/commands/studio.ts"() {
176691
176860
  "use strict";
@@ -176909,6 +177078,7 @@ var init_studio = __esm({
176909
177078
  packageName: db.packageName,
176910
177079
  proxy: db.proxy,
176911
177080
  transactionProxy: db.transactionProxy,
177081
+ benchmarkProxy: db.benchmarkProxy,
176912
177082
  customDefaults,
176913
177083
  schema: pgSchema2,
176914
177084
  relations: relations5,
@@ -176918,7 +177088,7 @@ var init_studio = __esm({
176918
177088
  };
176919
177089
  drizzleForMySQL = async (credentials2, mysqlSchema, relations5, schemaFiles, casing2) => {
176920
177090
  const { connectToMySQL: connectToMySQL2 } = await Promise.resolve().then(() => (init_connections(), connections_exports));
176921
- const { proxy, transactionProxy, database, packageName } = await connectToMySQL2(credentials2);
177091
+ const { proxy, transactionProxy, benchmarkProxy, database, packageName } = await connectToMySQL2(credentials2);
176922
177092
  const customDefaults = getCustomDefaults(mysqlSchema, casing2);
176923
177093
  let dbUrl;
176924
177094
  if ("url" in credentials2) {
@@ -176934,6 +177104,7 @@ var init_studio = __esm({
176934
177104
  databaseName: database,
176935
177105
  proxy,
176936
177106
  transactionProxy,
177107
+ benchmarkProxy,
176937
177108
  customDefaults,
176938
177109
  schema: mysqlSchema,
176939
177110
  relations: relations5,
@@ -177103,6 +177274,23 @@ var init_studio = __esm({
177103
177274
  ]).optional()
177104
177275
  }).array()
177105
177276
  });
177277
+ benchmarkProxySchema = external_exports.object({
177278
+ type: external_exports.literal("bproxy"),
177279
+ data: external_exports.object({
177280
+ query: external_exports.object({
177281
+ sql: external_exports.string(),
177282
+ params: external_exports.array(external_exports.any()).optional(),
177283
+ method: external_exports.union([
177284
+ external_exports.literal("values"),
177285
+ external_exports.literal("get"),
177286
+ external_exports.literal("all"),
177287
+ external_exports.literal("run"),
177288
+ external_exports.literal("execute")
177289
+ ]).optional()
177290
+ }),
177291
+ repeats: external_exports.number().min(1).optional()
177292
+ })
177293
+ });
177106
177294
  defaultsSchema = external_exports.object({
177107
177295
  type: external_exports.literal("defaults"),
177108
177296
  data: external_exports.array(
@@ -177117,6 +177305,7 @@ var init_studio = __esm({
177117
177305
  init,
177118
177306
  proxySchema,
177119
177307
  transactionProxySchema,
177308
+ benchmarkProxySchema,
177120
177309
  defaultsSchema
177121
177310
  ]);
177122
177311
  jsonStringify = (data2) => {
@@ -177139,6 +177328,7 @@ var init_studio = __esm({
177139
177328
  databaseName,
177140
177329
  proxy,
177141
177330
  transactionProxy,
177331
+ benchmarkProxy,
177142
177332
  customDefaults,
177143
177333
  schema: drizzleSchema,
177144
177334
  relations: relations5,
@@ -177202,7 +177392,7 @@ var init_studio = __esm({
177202
177392
  console.warn("Error message:", error4.message);
177203
177393
  }
177204
177394
  return c5.json({
177205
- version: "6.2",
177395
+ version: "6.3",
177206
177396
  dialect: dialect6,
177207
177397
  driver: driver2,
177208
177398
  packageName,
@@ -177240,6 +177430,21 @@ var init_studio = __esm({
177240
177430
  }
177241
177431
  );
177242
177432
  }
177433
+ if (type === "bproxy") {
177434
+ if (!benchmarkProxy) {
177435
+ throw new Error("Benchmark proxy is not configured for this database.");
177436
+ }
177437
+ const result2 = await benchmarkProxy(body.data.query, body.data.repeats || 1);
177438
+ const res = jsonStringify(result2);
177439
+ return c5.body(
177440
+ res,
177441
+ {
177442
+ headers: {
177443
+ "Content-Type": "application/json"
177444
+ }
177445
+ }
177446
+ );
177447
+ }
177243
177448
  if (type === "defaults") {
177244
177449
  const columns = body.data;
177245
177450
  const result2 = columns.map((column12) => {