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/api-mysql.js CHANGED
@@ -28717,7 +28717,7 @@ var require_websocket = __commonJS({
28717
28717
  var EventEmitter = require("events");
28718
28718
  var https2 = require("https");
28719
28719
  var http3 = require("http");
28720
- var net = require("net");
28720
+ var net2 = require("net");
28721
28721
  var tls = require("tls");
28722
28722
  var { randomBytes, createHash: createHash5 } = require("crypto");
28723
28723
  var { Duplex, Readable: Readable6 } = require("stream");
@@ -29448,12 +29448,12 @@ var require_websocket = __commonJS({
29448
29448
  }
29449
29449
  function netConnect(options) {
29450
29450
  options.path = options.socketPath;
29451
- return net.connect(options);
29451
+ return net2.connect(options);
29452
29452
  }
29453
29453
  function tlsConnect(options) {
29454
29454
  options.path = void 0;
29455
29455
  if (!options.servername && options.servername !== "") {
29456
- options.servername = net.isIP(options.host) ? "" : options.host;
29456
+ options.servername = net2.isIP(options.host) ? "" : options.host;
29457
29457
  }
29458
29458
  return tls.connect(options);
29459
29459
  }
@@ -33772,7 +33772,7 @@ var init_timing = __esm({
33772
33772
  "../node_modules/.pnpm/@smithy+node-http-handler@4.4.5/node_modules/@smithy/node-http-handler/dist-es/timing.js"() {
33773
33773
  "use strict";
33774
33774
  timing = {
33775
- setTimeout: (cb, ms) => setTimeout(cb, ms),
33775
+ setTimeout: (cb, ms2) => setTimeout(cb, ms2),
33776
33776
  clearTimeout: (timeoutId) => clearTimeout(timeoutId)
33777
33777
  };
33778
33778
  }
@@ -35660,13 +35660,13 @@ var init_schema_date_utils = __esm({
35660
35660
  if (!matches) {
35661
35661
  throw new TypeError(`Invalid RFC3339 timestamp format ${value}`);
35662
35662
  }
35663
- const [, yearStr, monthStr, dayStr, hours, minutes, seconds, , ms, offsetStr] = matches;
35663
+ const [, yearStr, monthStr, dayStr, hours, minutes, seconds, , ms2, offsetStr] = matches;
35664
35664
  range(monthStr, 1, 12);
35665
35665
  range(dayStr, 1, 31);
35666
35666
  range(hours, 0, 23);
35667
35667
  range(minutes, 0, 59);
35668
35668
  range(seconds, 0, 60);
35669
- 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));
35669
+ 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));
35670
35670
  date2.setUTCFullYear(Number(yearStr));
35671
35671
  if (offsetStr.toUpperCase() != "Z") {
35672
35672
  const [, sign2, offsetH, offsetM] = /([+-])(\d\d):(\d\d)/.exec(offsetStr) || [void 0, "+", 0, 0];
@@ -55680,8 +55680,8 @@ var require_datetime2 = __commonJS({
55680
55680
  if (!(object instanceof Date)) {
55681
55681
  throw new errors_1.InvalidArgumentError(`a Date instance was expected, got "${object}"`);
55682
55682
  }
55683
- const ms = object.getTime() - TIMESHIFT;
55684
- const us = ms * 1e3;
55683
+ const ms2 = object.getTime() - TIMESHIFT;
55684
+ const us = ms2 * 1e3;
55685
55685
  buf.writeInt32(8);
55686
55686
  buf.writeInt64(us);
55687
55687
  }
@@ -55691,12 +55691,12 @@ var require_datetime2 = __commonJS({
55691
55691
  return ctx.postDecode(this, us2 + BI_TIMESHIFT_US);
55692
55692
  }
55693
55693
  const us = Number(buf.readBigInt64());
55694
- let ms = Math.round(us / 1e3);
55695
- if (Math.abs(us % 1e3) === 500 && Math.abs(ms) % 2 === 1) {
55696
- ms -= 1;
55694
+ let ms2 = Math.round(us / 1e3);
55695
+ if (Math.abs(us % 1e3) === 500 && Math.abs(ms2) % 2 === 1) {
55696
+ ms2 -= 1;
55697
55697
  }
55698
- ms += TIMESHIFT;
55699
- return new Date(ms);
55698
+ ms2 += TIMESHIFT;
55699
+ return new Date(ms2);
55700
55700
  }
55701
55701
  };
55702
55702
  exports2.DateTimeCodec = DateTimeCodec;
@@ -55717,8 +55717,8 @@ var require_datetime2 = __commonJS({
55717
55717
  if (!(object instanceof datetime_1.LocalDateTime)) {
55718
55718
  throw new errors_1.InvalidArgumentError(`a LocalDateTime instance was expected, got "${object}"`);
55719
55719
  }
55720
- const ms = BigInt(datetime_1.localDateInstances.get(object).getTime() - TIMESHIFT);
55721
- let us = ms * 1000n + BigInt(object.hour * 36e8 + object.minute * 6e7 + object.second * 1e6 + object.millisecond * 1e3 + object.microsecond);
55720
+ const ms2 = BigInt(datetime_1.localDateInstances.get(object).getTime() - TIMESHIFT);
55721
+ let us = ms2 * 1000n + BigInt(object.hour * 36e8 + object.minute * 6e7 + object.second * 1e6 + object.millisecond * 1e3 + object.microsecond);
55722
55722
  if (object.nanosecond === 500 && Math.abs(object.microsecond) % 2 === 1 || object.nanosecond > 500) {
55723
55723
  us += 1n;
55724
55724
  }
@@ -55732,13 +55732,13 @@ var require_datetime2 = __commonJS({
55732
55732
  }
55733
55733
  const bi_ms = bi_us / 1000n;
55734
55734
  let us = Number(bi_us - bi_ms * 1000n);
55735
- let ms = Number(bi_ms);
55735
+ let ms2 = Number(bi_ms);
55736
55736
  if (us < 0) {
55737
55737
  us += 1e3;
55738
- ms -= 1;
55738
+ ms2 -= 1;
55739
55739
  }
55740
- ms += TIMESHIFT;
55741
- const date2 = new Date(ms);
55740
+ ms2 += TIMESHIFT;
55741
+ const date2 = new Date(ms2);
55742
55742
  return new datetime_1.LocalDateTime(date2.getUTCFullYear(), date2.getUTCMonth() + 1, date2.getUTCDate(), date2.getUTCHours(), date2.getUTCMinutes(), date2.getUTCSeconds(), date2.getUTCMilliseconds(), us);
55743
55743
  }
55744
55744
  };
@@ -55800,13 +55800,13 @@ var require_datetime2 = __commonJS({
55800
55800
  }
55801
55801
  let us = Number(bius);
55802
55802
  let seconds = Math.floor(us / 1e6);
55803
- const ms = Math.floor(us % 1e6 / 1e3);
55804
- us = us % 1e6 - ms * 1e3;
55803
+ const ms2 = Math.floor(us % 1e6 / 1e3);
55804
+ us = us % 1e6 - ms2 * 1e3;
55805
55805
  let minutes = Math.floor(seconds / 60);
55806
55806
  seconds = Math.floor(seconds % 60);
55807
55807
  const hours = Math.floor(minutes / 60);
55808
55808
  minutes = Math.floor(minutes % 60);
55809
- return new datetime_1.LocalTime(hours, minutes, seconds, ms, us);
55809
+ return new datetime_1.LocalTime(hours, minutes, seconds, ms2, us);
55810
55810
  }
55811
55811
  };
55812
55812
  exports2.LocalTimeCodec = LocalTimeCodec;
@@ -55883,14 +55883,14 @@ var require_datetime2 = __commonJS({
55883
55883
  const biMillion = 1000000n;
55884
55884
  const biSeconds = bius / biMillion;
55885
55885
  let us = Number(bius - biSeconds * biMillion);
55886
- const ms = Math.floor(us / 1e3);
55886
+ const ms2 = Math.floor(us / 1e3);
55887
55887
  us = us % 1e3;
55888
55888
  let seconds = Number(biSeconds);
55889
55889
  let minutes = Math.floor(seconds / 60);
55890
55890
  seconds = Math.floor(seconds % 60);
55891
55891
  const hours = Math.floor(minutes / 60);
55892
55892
  minutes = Math.floor(minutes % 60);
55893
- return new datetime_1.Duration(0, 0, 0, 0, hours * sign2, minutes * sign2, seconds * sign2, ms * sign2, us * sign2);
55893
+ return new datetime_1.Duration(0, 0, 0, 0, hours * sign2, minutes * sign2, seconds * sign2, ms2 * sign2, us * sign2);
55894
55894
  }
55895
55895
  };
55896
55896
  exports2.DurationCodec = DurationCodec;
@@ -55936,7 +55936,7 @@ var require_datetime2 = __commonJS({
55936
55936
  const million = BigInt(1e6);
55937
55937
  const biSeconds = bius / million;
55938
55938
  let us = Number(bius - biSeconds * million);
55939
- const ms = Math.trunc(us / 1e3);
55939
+ const ms2 = Math.trunc(us / 1e3);
55940
55940
  us = us % 1e3;
55941
55941
  let seconds = Number(biSeconds);
55942
55942
  let minutes = Math.trunc(seconds / 60);
@@ -55947,7 +55947,7 @@ var require_datetime2 = __commonJS({
55947
55947
  days = Math.trunc(days % 7);
55948
55948
  const years = Math.trunc(months2 / 12);
55949
55949
  months2 = Math.trunc(months2 % 12);
55950
- return new datetime_1.RelativeDuration(years, months2, weeks, days, hours * sign2, minutes * sign2, seconds * sign2, ms * sign2, us * sign2);
55950
+ return new datetime_1.RelativeDuration(years, months2, weeks, days, hours * sign2, minutes * sign2, seconds * sign2, ms2 * sign2, us * sign2);
55951
55951
  }
55952
55952
  };
55953
55953
  exports2.RelativeDurationCodec = RelativeDurationCodec;
@@ -66111,41 +66111,41 @@ var require_ms = __commonJS({
66111
66111
  return void 0;
66112
66112
  }
66113
66113
  }
66114
- function fmtShort(ms) {
66115
- var msAbs = Math.abs(ms);
66114
+ function fmtShort(ms2) {
66115
+ var msAbs = Math.abs(ms2);
66116
66116
  if (msAbs >= d6) {
66117
- return Math.round(ms / d6) + "d";
66117
+ return Math.round(ms2 / d6) + "d";
66118
66118
  }
66119
66119
  if (msAbs >= h7) {
66120
- return Math.round(ms / h7) + "h";
66120
+ return Math.round(ms2 / h7) + "h";
66121
66121
  }
66122
66122
  if (msAbs >= m7) {
66123
- return Math.round(ms / m7) + "m";
66123
+ return Math.round(ms2 / m7) + "m";
66124
66124
  }
66125
66125
  if (msAbs >= s7) {
66126
- return Math.round(ms / s7) + "s";
66126
+ return Math.round(ms2 / s7) + "s";
66127
66127
  }
66128
- return ms + "ms";
66128
+ return ms2 + "ms";
66129
66129
  }
66130
- function fmtLong(ms) {
66131
- var msAbs = Math.abs(ms);
66130
+ function fmtLong(ms2) {
66131
+ var msAbs = Math.abs(ms2);
66132
66132
  if (msAbs >= d6) {
66133
- return plural(ms, msAbs, d6, "day");
66133
+ return plural(ms2, msAbs, d6, "day");
66134
66134
  }
66135
66135
  if (msAbs >= h7) {
66136
- return plural(ms, msAbs, h7, "hour");
66136
+ return plural(ms2, msAbs, h7, "hour");
66137
66137
  }
66138
66138
  if (msAbs >= m7) {
66139
- return plural(ms, msAbs, m7, "minute");
66139
+ return plural(ms2, msAbs, m7, "minute");
66140
66140
  }
66141
66141
  if (msAbs >= s7) {
66142
- return plural(ms, msAbs, s7, "second");
66142
+ return plural(ms2, msAbs, s7, "second");
66143
66143
  }
66144
- return ms + " ms";
66144
+ return ms2 + " ms";
66145
66145
  }
66146
- function plural(ms, msAbs, n6, name) {
66146
+ function plural(ms2, msAbs, n6, name) {
66147
66147
  var isPlural = msAbs >= n6 * 1.5;
66148
- return Math.round(ms / n6) + " " + name + (isPlural ? "s" : "");
66148
+ return Math.round(ms2 / n6) + " " + name + (isPlural ? "s" : "");
66149
66149
  }
66150
66150
  }
66151
66151
  });
@@ -66189,8 +66189,8 @@ var require_common2 = __commonJS({
66189
66189
  }
66190
66190
  const self2 = debug;
66191
66191
  const curr = Number(/* @__PURE__ */ new Date());
66192
- const ms = curr - (prevTime || curr);
66193
- self2.diff = ms;
66192
+ const ms2 = curr - (prevTime || curr);
66193
+ self2.diff = ms2;
66194
66194
  self2.prev = prevTime;
66195
66195
  self2.curr = curr;
66196
66196
  prevTime = curr;
@@ -81693,11 +81693,11 @@ var require_TokenExpiredError = __commonJS({
81693
81693
  var require_timespan = __commonJS({
81694
81694
  "../node_modules/.pnpm/jsonwebtoken@9.0.2/node_modules/jsonwebtoken/lib/timespan.js"(exports2, module2) {
81695
81695
  "use strict";
81696
- var ms = require_ms();
81696
+ var ms2 = require_ms();
81697
81697
  module2.exports = function(time2, iat) {
81698
81698
  var timestamp = iat || Math.floor(Date.now() / 1e3);
81699
81699
  if (typeof time2 === "string") {
81700
- var milliseconds = ms(time2);
81700
+ var milliseconds = ms2(time2);
81701
81701
  if (typeof milliseconds === "undefined") {
81702
81702
  return;
81703
81703
  }
@@ -96235,7 +96235,7 @@ var require_dist = __commonJS({
96235
96235
  };
96236
96236
  Object.defineProperty(exports2, "__esModule", { value: true });
96237
96237
  exports2.Agent = void 0;
96238
- var net = __importStar2(require("net"));
96238
+ var net2 = __importStar2(require("net"));
96239
96239
  var http3 = __importStar2(require("http"));
96240
96240
  var https_1 = require("https");
96241
96241
  __exportStar2(require_helpers2(), exports2);
@@ -96275,7 +96275,7 @@ var require_dist = __commonJS({
96275
96275
  if (!this.sockets[name]) {
96276
96276
  this.sockets[name] = [];
96277
96277
  }
96278
- const fakeSocket = new net.Socket({ writable: false });
96278
+ const fakeSocket = new net2.Socket({ writable: false });
96279
96279
  this.sockets[name].push(fakeSocket);
96280
96280
  this.totalSocketCount++;
96281
96281
  return fakeSocket;
@@ -96487,7 +96487,7 @@ var require_dist2 = __commonJS({
96487
96487
  };
96488
96488
  Object.defineProperty(exports2, "__esModule", { value: true });
96489
96489
  exports2.HttpsProxyAgent = void 0;
96490
- var net = __importStar2(require("net"));
96490
+ var net2 = __importStar2(require("net"));
96491
96491
  var tls = __importStar2(require("tls"));
96492
96492
  var assert_1 = __importDefault2(require("assert"));
96493
96493
  var debug_1 = __importDefault2(require_src2());
@@ -96496,7 +96496,7 @@ var require_dist2 = __commonJS({
96496
96496
  var parse_proxy_response_1 = require_parse_proxy_response();
96497
96497
  var debug = (0, debug_1.default)("https-proxy-agent");
96498
96498
  var setServernameFromNonIpHost = (options) => {
96499
- if (options.servername === void 0 && options.host && !net.isIP(options.host)) {
96499
+ if (options.servername === void 0 && options.host && !net2.isIP(options.host)) {
96500
96500
  return {
96501
96501
  ...options,
96502
96502
  servername: options.host
@@ -96536,10 +96536,10 @@ var require_dist2 = __commonJS({
96536
96536
  socket = tls.connect(setServernameFromNonIpHost(this.connectOpts));
96537
96537
  } else {
96538
96538
  debug("Creating `net.Socket`: %o", this.connectOpts);
96539
- socket = net.connect(this.connectOpts);
96539
+ socket = net2.connect(this.connectOpts);
96540
96540
  }
96541
96541
  const headers = typeof this.proxyHeaders === "function" ? this.proxyHeaders() : { ...this.proxyHeaders };
96542
- const host = net.isIPv6(opts.host) ? `[${opts.host}]` : opts.host;
96542
+ const host = net2.isIPv6(opts.host) ? `[${opts.host}]` : opts.host;
96543
96543
  let payload = `CONNECT ${host}:${opts.port} HTTP/1.1\r
96544
96544
  `;
96545
96545
  if (proxy.username || proxy.password) {
@@ -96572,7 +96572,7 @@ var require_dist2 = __commonJS({
96572
96572
  return socket;
96573
96573
  }
96574
96574
  socket.destroy();
96575
- const fakeSocket = new net.Socket({ writable: false });
96575
+ const fakeSocket = new net2.Socket({ writable: false });
96576
96576
  fakeSocket.readable = true;
96577
96577
  req.once("socket", (s7) => {
96578
96578
  debug("Replaying proxy buffer for failed request");
@@ -96637,7 +96637,7 @@ var require_dist3 = __commonJS({
96637
96637
  };
96638
96638
  Object.defineProperty(exports2, "__esModule", { value: true });
96639
96639
  exports2.HttpProxyAgent = void 0;
96640
- var net = __importStar2(require("net"));
96640
+ var net2 = __importStar2(require("net"));
96641
96641
  var tls = __importStar2(require("tls"));
96642
96642
  var debug_1 = __importDefault2(require_src2());
96643
96643
  var events_1 = require("events");
@@ -96710,7 +96710,7 @@ var require_dist3 = __commonJS({
96710
96710
  socket = tls.connect(this.connectOpts);
96711
96711
  } else {
96712
96712
  debug("Creating `net.Socket`: %o", this.connectOpts);
96713
- socket = net.connect(this.connectOpts);
96713
+ socket = net2.connect(this.connectOpts);
96714
96714
  }
96715
96715
  await (0, events_1.once)(socket, "connect");
96716
96716
  return socket;
@@ -135590,7 +135590,7 @@ var require_connection = __commonJS({
135590
135590
  var _crypto = _interopRequireDefault(require("crypto"));
135591
135591
  var _os = _interopRequireDefault(require("os"));
135592
135592
  var tls = _interopRequireWildcard(require("tls"));
135593
- var net = _interopRequireWildcard(require("net"));
135593
+ var net2 = _interopRequireWildcard(require("net"));
135594
135594
  var _dns = _interopRequireDefault(require("dns"));
135595
135595
  var _constants = _interopRequireDefault(require("constants"));
135596
135596
  var _stream = require("stream");
@@ -136639,7 +136639,7 @@ var require_connection = __commonJS({
136639
136639
  async wrapWithTls(socket, signal) {
136640
136640
  signal.throwIfAborted();
136641
136641
  const secureContext = tls.createSecureContext(this.secureContextOptions);
136642
- const serverName = !net.isIP(this.config.server) ? this.config.server : "";
136642
+ const serverName = !net2.isIP(this.config.server) ? this.config.server : "";
136643
136643
  const encryptOptions = {
136644
136644
  host: this.config.server,
136645
136645
  socket,
@@ -139561,10 +139561,11 @@ function parseMssqlUrl(url) {
139561
139561
  }
139562
139562
  };
139563
139563
  }
139564
- var normalisePGliteUrl, preparePostgresDB, prepareCockroach, prepareGelDB, parseSingleStoreCredentials, connectToSingleStore, parseMysqlCredentials, connectToMySQL, parseMssqlCredentials, connectToMsSQL, prepareSqliteParams, preparePGliteParams, connectToSQLite, connectToLibSQL;
139564
+ var import_net, ms, normalisePGliteUrl, preparePostgresDB, prepareCockroach, prepareGelDB, parseSingleStoreCredentials, connectToSingleStore, parseMysqlCredentials, connectToMySQL, parseMssqlCredentials, connectToMsSQL, prepareSqliteParams, preparePGliteParams, connectToSQLite, connectToLibSQL;
139565
139565
  var init_connections = __esm({
139566
139566
  "src/cli/connections.ts"() {
139567
139567
  "use strict";
139568
+ import_net = __toESM(require("net"));
139568
139569
  init_src();
139569
139570
  init_wrapper();
139570
139571
  init_utils();
@@ -139572,6 +139573,7 @@ var init_connections = __esm({
139572
139573
  init_when_json_met_bigint();
139573
139574
  init_utils3();
139574
139575
  init_outputs();
139576
+ ms = (a6, b6) => Number(b6 - a6) / 1e6;
139575
139577
  normalisePGliteUrl = (it) => {
139576
139578
  if (it.startsWith("file:")) {
139577
139579
  return it.substring(5);
@@ -139726,13 +139728,13 @@ var init_connections = __esm({
139726
139728
  return pg.types.getTypeParser(typeId, format2);
139727
139729
  }
139728
139730
  };
139729
- const client = "url" in credentials ? new pg.Pool({ connectionString: credentials.url, max: 1 }) : new pg.Pool({ ...credentials, ssl, max: 1 });
139730
- const db = drizzle({ client });
139731
+ const pool = "url" in credentials ? new pg.Pool({ connectionString: credentials.url, max: 1 }) : new pg.Pool({ ...credentials, ssl, max: 1 });
139732
+ const db = drizzle({ client: pool });
139731
139733
  const migrateFn = async (config) => {
139732
139734
  return migrate(db, config);
139733
139735
  };
139734
139736
  const query = async (sql, params) => {
139735
- const result2 = await client.query({
139737
+ const result2 = await pool.query({
139736
139738
  text: sql,
139737
139739
  values: params ?? [],
139738
139740
  types: types3
@@ -139742,7 +139744,7 @@ var init_connections = __esm({
139742
139744
  return result2.rows;
139743
139745
  };
139744
139746
  const proxy = async (params) => {
139745
- const result2 = await client.query({
139747
+ const result2 = await pool.query({
139746
139748
  text: params.sql,
139747
139749
  values: params.params,
139748
139750
  ...params.mode === "array" && { rowMode: "array" },
@@ -139754,7 +139756,7 @@ var init_connections = __esm({
139754
139756
  };
139755
139757
  const transactionProxy = async (queries) => {
139756
139758
  const results = [];
139757
- const tx = await client.connect();
139759
+ const tx = await pool.connect();
139758
139760
  try {
139759
139761
  await tx.query("BEGIN");
139760
139762
  for (const query2 of queries) {
@@ -139773,7 +139775,72 @@ var init_connections = __esm({
139773
139775
  }
139774
139776
  return results;
139775
139777
  };
139776
- return { packageName: "pg", query, proxy, transactionProxy, migrate: migrateFn };
139778
+ const benchmarkQuery = async (sql, params) => {
139779
+ const explainResult = await pool.query({
139780
+ text: `EXPLAIN ANALYZE ${sql}`,
139781
+ values: params ?? [],
139782
+ types: types3
139783
+ });
139784
+ const stringifiedResult = JSON.stringify(explainResult.rows);
139785
+ const planningMatch = stringifiedResult.match(/Planning Time:\s*([\d.]+)\s*ms/i);
139786
+ const executionMatch = stringifiedResult.match(/Execution Time:\s*([\d.]+)\s*ms/i);
139787
+ const planningTime = Number(planningMatch[1]);
139788
+ const executionTime = Number(executionMatch[1]);
139789
+ let startAt = 0n;
139790
+ let tcpConnectedAt = 0n;
139791
+ let tlsConnectedAt = null;
139792
+ let dbReadyAt = 0n;
139793
+ let querySentAt = 0n;
139794
+ let firstDataAt = 0n;
139795
+ let lastDataAt = 0n;
139796
+ let bytesReceived = 0;
139797
+ const client = "url" in credentials ? new pg.Client({ connectionString: credentials.url }) : new pg.Client({ ...credentials, ssl });
139798
+ client.connection.once("connect", () => {
139799
+ tcpConnectedAt = process.hrtime.bigint();
139800
+ });
139801
+ client.connection.prependOnceListener("sslconnect", () => {
139802
+ tlsConnectedAt = process.hrtime.bigint();
139803
+ });
139804
+ client.connection.prependOnceListener("readyForQuery", () => {
139805
+ dbReadyAt = process.hrtime.bigint();
139806
+ });
139807
+ client.connection.addListener("rowDescription", (data) => {
139808
+ if (firstDataAt === 0n) {
139809
+ firstDataAt = process.hrtime.bigint();
139810
+ }
139811
+ bytesReceived += data.length;
139812
+ });
139813
+ client.connection.addListener("dataRow", (data) => {
139814
+ bytesReceived += data.length;
139815
+ });
139816
+ client.connection.addListener("commandComplete", () => {
139817
+ lastDataAt = process.hrtime.bigint();
139818
+ });
139819
+ startAt = process.hrtime.bigint();
139820
+ await client.connect();
139821
+ querySentAt = process.hrtime.bigint();
139822
+ await client.query(sql, params);
139823
+ await client.end();
139824
+ return {
139825
+ tcpHandshake: ms(startAt, tcpConnectedAt),
139826
+ tlsHandshake: tlsConnectedAt ? ms(tcpConnectedAt, tlsConnectedAt) : null,
139827
+ dbHandshake: ms(tlsConnectedAt ?? tcpConnectedAt, dbReadyAt),
139828
+ planning: planningTime,
139829
+ execution: executionTime,
139830
+ dataDownload: ms(firstDataAt, lastDataAt) + ms(querySentAt, firstDataAt) - executionTime - planningTime,
139831
+ total: ms(startAt, lastDataAt),
139832
+ dataSize: bytesReceived
139833
+ };
139834
+ };
139835
+ const benchmarkProxy = async ({ sql, params }, repeats) => {
139836
+ const results = [];
139837
+ for (let i7 = 0; i7 < repeats; i7++) {
139838
+ const r7 = await benchmarkQuery(sql, params);
139839
+ results.push(r7);
139840
+ }
139841
+ return results;
139842
+ };
139843
+ return { packageName: "pg", query, proxy, transactionProxy, benchmarkProxy, migrate: migrateFn };
139777
139844
  }
139778
139845
  if (await checkPackage("postgres")) {
139779
139846
  console.log(
@@ -140036,6 +140103,7 @@ var init_connections = __esm({
140036
140103
  console.error(
140037
140104
  "To connect to Postgres database - please install either of 'pg', 'postgres', 'bun', '@neondatabase/serverless' or '@vercel/postgres' drivers"
140038
140105
  );
140106
+ console.warn("For the 'bun' driver, run your script using: bun --bun");
140039
140107
  process.exit(1);
140040
140108
  };
140041
140109
  prepareCockroach = async (credentials) => {
@@ -140267,7 +140335,6 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
140267
140335
  }
140268
140336
  return next();
140269
140337
  };
140270
- await connection.connect();
140271
140338
  const query = async (sql, params) => {
140272
140339
  const res = await connection.execute({
140273
140340
  sql,
@@ -140307,11 +140374,111 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
140307
140374
  }
140308
140375
  return results;
140309
140376
  };
140377
+ const benchmarkQuery = async (sql, params) => {
140378
+ const { createConnection: createConnection2 } = require("mysql2");
140379
+ const explainResult = await connection.query({
140380
+ sql: `EXPLAIN ANALYZE ${sql}`,
140381
+ values: params ?? [],
140382
+ typeCast
140383
+ });
140384
+ const stringifiedResult = JSON.stringify(explainResult[0]);
140385
+ const timeMatch = stringifiedResult.match(
140386
+ /actual time=([0-9.eE+-]+)\.\.([0-9.eE+-]+)/
140387
+ );
140388
+ const lastRowTime = Number(timeMatch[2]);
140389
+ const executionTime = lastRowTime;
140390
+ let startAt = 0n;
140391
+ let tcpConnectedAt = 0n;
140392
+ let tlsConnectedAt = null;
140393
+ let querySentAt = 0n;
140394
+ let firstDataAt = 0n;
140395
+ let lastDataAt = 0n;
140396
+ let bytesReceived = 0;
140397
+ const createStream = ({ config }) => {
140398
+ let stream;
140399
+ if (config.socketPath) {
140400
+ stream = import_net.default.connect(config.socketPath);
140401
+ } else {
140402
+ stream = import_net.default.connect(config.port, config.host);
140403
+ }
140404
+ if (config.enableKeepAlive) {
140405
+ stream.on("connect", () => {
140406
+ stream.setKeepAlive(true, config.keepAliveInitialDelay);
140407
+ });
140408
+ }
140409
+ stream.setNoDelay(true);
140410
+ stream.once("connect", () => {
140411
+ tcpConnectedAt = process.hrtime.bigint();
140412
+ });
140413
+ return stream;
140414
+ };
140415
+ startAt = process.hrtime.bigint();
140416
+ const newConnection = result2.url ? createConnection2({
140417
+ // debug: true,
140418
+ uri: result2.url,
140419
+ stream: createStream
140420
+ }) : createConnection2({
140421
+ ...result2.credentials,
140422
+ stream: createStream
140423
+ });
140424
+ await new Promise((resolve2, reject) => {
140425
+ newConnection.connect((err2) => {
140426
+ tlsConnectedAt = process.hrtime.bigint();
140427
+ if (err2) {
140428
+ reject(err2);
140429
+ } else {
140430
+ resolve2();
140431
+ }
140432
+ });
140433
+ });
140434
+ querySentAt = process.hrtime.bigint();
140435
+ await new Promise((resolve2, reject) => {
140436
+ const query2 = newConnection.query({
140437
+ sql,
140438
+ values: params ?? [],
140439
+ typeCast
140440
+ // rowsAsArray: true,
140441
+ });
140442
+ query2.on("error", (err2) => {
140443
+ reject(err2);
140444
+ });
140445
+ query2.on("fields", (fields) => {
140446
+ if (firstDataAt === 0n) {
140447
+ firstDataAt = process.hrtime.bigint();
140448
+ }
140449
+ bytesReceived += fields[0]._buf.length;
140450
+ });
140451
+ query2.on("end", () => {
140452
+ lastDataAt = process.hrtime.bigint();
140453
+ resolve2();
140454
+ newConnection.end();
140455
+ });
140456
+ });
140457
+ return {
140458
+ tcpHandshake: ms(startAt, tcpConnectedAt),
140459
+ tlsHandshake: tlsConnectedAt ? ms(tcpConnectedAt, tlsConnectedAt) : null,
140460
+ dbHandshake: null,
140461
+ planning: null,
140462
+ execution: executionTime,
140463
+ dataDownload: ms(firstDataAt, lastDataAt) + ms(querySentAt, firstDataAt) - executionTime,
140464
+ total: ms(startAt, lastDataAt),
140465
+ dataSize: bytesReceived
140466
+ };
140467
+ };
140468
+ const benchmarkProxy = async ({ sql, params }, repeats) => {
140469
+ const results = [];
140470
+ for (let i7 = 0; i7 < repeats; i7++) {
140471
+ const r7 = await benchmarkQuery(sql, params);
140472
+ results.push(r7);
140473
+ }
140474
+ return results;
140475
+ };
140310
140476
  return {
140311
140477
  db: { query },
140312
140478
  packageName: "mysql2",
140313
140479
  proxy,
140314
140480
  transactionProxy,
140481
+ benchmarkProxy,
140315
140482
  database: result2.database,
140316
140483
  migrate: migrateFn
140317
140484
  };
@@ -140417,6 +140584,7 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
140417
140584
  console.error(
140418
140585
  "To connect to MySQL database - please install either of 'mysql2', 'bun' or '@planetscale/database' drivers"
140419
140586
  );
140587
+ console.warn("For the 'bun' driver, run your script using: bun --bun");
140420
140588
  process.exit(1);
140421
140589
  };
140422
140590
  parseMssqlCredentials = (credentials) => {
@@ -140865,6 +141033,7 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
140865
141033
  console.log(
140866
141034
  "Please install either 'better-sqlite3', 'bun', '@libsql/client' or '@tursodatabase/database' for Drizzle Kit to connect to SQLite databases"
140867
141035
  );
141036
+ console.warn("For the 'bun' driver, run your script using: bun --bun");
140868
141037
  process.exit(1);
140869
141038
  };
140870
141039
  connectToLibSQL = async (credentials) => {
@@ -140952,7 +141121,7 @@ __export(studio_exports, {
140952
141121
  prepareServer: () => prepareServer,
140953
141122
  prepareSingleStoreSchema: () => prepareSingleStoreSchema
140954
141123
  });
140955
- var import_crypto9, import_drizzle_orm, import_relations, import_mssql_core2, import_mysql_core2, import_pg_core2, import_singlestore_core, import_sqlite_core2, import_fs4, import_node_https2, preparePgSchema, prepareMySqlSchema, prepareMsSqlSchema, prepareSQLiteSchema, prepareSingleStoreSchema, getCustomDefaults, drizzleForPostgres, drizzleForMySQL, drizzleForSQLite, drizzleForLibSQL, drizzleForSingleStore, extractRelations, init2, proxySchema, transactionProxySchema, defaultsSchema, schema5, jsonStringify, prepareServer;
141124
+ var import_crypto9, import_drizzle_orm, import_relations, import_mssql_core2, import_mysql_core2, import_pg_core2, import_singlestore_core, import_sqlite_core2, import_fs4, import_node_https2, preparePgSchema, prepareMySqlSchema, prepareMsSqlSchema, prepareSQLiteSchema, prepareSingleStoreSchema, getCustomDefaults, drizzleForPostgres, drizzleForMySQL, drizzleForSQLite, drizzleForLibSQL, drizzleForSingleStore, extractRelations, init2, proxySchema, transactionProxySchema, benchmarkProxySchema, defaultsSchema, schema5, jsonStringify, prepareServer;
140956
141125
  var init_studio = __esm({
140957
141126
  "src/cli/commands/studio.ts"() {
140958
141127
  "use strict";
@@ -141176,6 +141345,7 @@ var init_studio = __esm({
141176
141345
  packageName: db.packageName,
141177
141346
  proxy: db.proxy,
141178
141347
  transactionProxy: db.transactionProxy,
141348
+ benchmarkProxy: db.benchmarkProxy,
141179
141349
  customDefaults,
141180
141350
  schema: pgSchema2,
141181
141351
  relations,
@@ -141185,7 +141355,7 @@ var init_studio = __esm({
141185
141355
  };
141186
141356
  drizzleForMySQL = async (credentials, mysqlSchema, relations, schemaFiles, casing2) => {
141187
141357
  const { connectToMySQL: connectToMySQL2 } = await Promise.resolve().then(() => (init_connections(), connections_exports));
141188
- const { proxy, transactionProxy, database, packageName } = await connectToMySQL2(credentials);
141358
+ const { proxy, transactionProxy, benchmarkProxy, database, packageName } = await connectToMySQL2(credentials);
141189
141359
  const customDefaults = getCustomDefaults(mysqlSchema, casing2);
141190
141360
  let dbUrl;
141191
141361
  if ("url" in credentials) {
@@ -141201,6 +141371,7 @@ var init_studio = __esm({
141201
141371
  databaseName: database,
141202
141372
  proxy,
141203
141373
  transactionProxy,
141374
+ benchmarkProxy,
141204
141375
  customDefaults,
141205
141376
  schema: mysqlSchema,
141206
141377
  relations,
@@ -141370,6 +141541,23 @@ var init_studio = __esm({
141370
141541
  ]).optional()
141371
141542
  }).array()
141372
141543
  });
141544
+ benchmarkProxySchema = external_exports.object({
141545
+ type: external_exports.literal("bproxy"),
141546
+ data: external_exports.object({
141547
+ query: external_exports.object({
141548
+ sql: external_exports.string(),
141549
+ params: external_exports.array(external_exports.any()).optional(),
141550
+ method: external_exports.union([
141551
+ external_exports.literal("values"),
141552
+ external_exports.literal("get"),
141553
+ external_exports.literal("all"),
141554
+ external_exports.literal("run"),
141555
+ external_exports.literal("execute")
141556
+ ]).optional()
141557
+ }),
141558
+ repeats: external_exports.number().min(1).optional()
141559
+ })
141560
+ });
141373
141561
  defaultsSchema = external_exports.object({
141374
141562
  type: external_exports.literal("defaults"),
141375
141563
  data: external_exports.array(
@@ -141384,6 +141572,7 @@ var init_studio = __esm({
141384
141572
  init2,
141385
141573
  proxySchema,
141386
141574
  transactionProxySchema,
141575
+ benchmarkProxySchema,
141387
141576
  defaultsSchema
141388
141577
  ]);
141389
141578
  jsonStringify = (data) => {
@@ -141406,6 +141595,7 @@ var init_studio = __esm({
141406
141595
  databaseName,
141407
141596
  proxy,
141408
141597
  transactionProxy,
141598
+ benchmarkProxy,
141409
141599
  customDefaults,
141410
141600
  schema: drizzleSchema,
141411
141601
  relations,
@@ -141469,7 +141659,7 @@ var init_studio = __esm({
141469
141659
  console.warn("Error message:", error3.message);
141470
141660
  }
141471
141661
  return c6.json({
141472
- version: "6.2",
141662
+ version: "6.3",
141473
141663
  dialect: dialect6,
141474
141664
  driver: driver2,
141475
141665
  packageName,
@@ -141507,6 +141697,21 @@ var init_studio = __esm({
141507
141697
  }
141508
141698
  );
141509
141699
  }
141700
+ if (type === "bproxy") {
141701
+ if (!benchmarkProxy) {
141702
+ throw new Error("Benchmark proxy is not configured for this database.");
141703
+ }
141704
+ const result2 = await benchmarkProxy(body.data.query, body.data.repeats || 1);
141705
+ const res = jsonStringify(result2);
141706
+ return c6.body(
141707
+ res,
141708
+ {
141709
+ headers: {
141710
+ "Content-Type": "application/json"
141711
+ }
141712
+ }
141713
+ );
141714
+ }
141510
141715
  if (type === "defaults") {
141511
141716
  const columns = body.data;
141512
141717
  const result2 = columns.map((column7) => {