drizzle-kit 1.0.0-beta.2-b782ae1 → 1.0.0-beta.2-0f918b0

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-sqlite.mjs CHANGED
@@ -28729,7 +28729,7 @@ var require_websocket = __commonJS({
28729
28729
  var EventEmitter = __require("events");
28730
28730
  var https2 = __require("https");
28731
28731
  var http3 = __require("http");
28732
- var net = __require("net");
28732
+ var net2 = __require("net");
28733
28733
  var tls = __require("tls");
28734
28734
  var { randomBytes, createHash: createHash5 } = __require("crypto");
28735
28735
  var { Duplex, Readable: Readable6 } = __require("stream");
@@ -29460,12 +29460,12 @@ var require_websocket = __commonJS({
29460
29460
  }
29461
29461
  function netConnect(options) {
29462
29462
  options.path = options.socketPath;
29463
- return net.connect(options);
29463
+ return net2.connect(options);
29464
29464
  }
29465
29465
  function tlsConnect(options) {
29466
29466
  options.path = void 0;
29467
29467
  if (!options.servername && options.servername !== "") {
29468
- options.servername = net.isIP(options.host) ? "" : options.host;
29468
+ options.servername = net2.isIP(options.host) ? "" : options.host;
29469
29469
  }
29470
29470
  return tls.connect(options);
29471
29471
  }
@@ -33783,7 +33783,7 @@ var init_timing = __esm({
33783
33783
  "../node_modules/.pnpm/@smithy+node-http-handler@4.4.5/node_modules/@smithy/node-http-handler/dist-es/timing.js"() {
33784
33784
  "use strict";
33785
33785
  timing = {
33786
- setTimeout: (cb, ms) => setTimeout(cb, ms),
33786
+ setTimeout: (cb, ms2) => setTimeout(cb, ms2),
33787
33787
  clearTimeout: (timeoutId) => clearTimeout(timeoutId)
33788
33788
  };
33789
33789
  }
@@ -35671,13 +35671,13 @@ var init_schema_date_utils = __esm({
35671
35671
  if (!matches) {
35672
35672
  throw new TypeError(`Invalid RFC3339 timestamp format ${value}`);
35673
35673
  }
35674
- const [, yearStr, monthStr, dayStr, hours, minutes, seconds, , ms, offsetStr] = matches;
35674
+ const [, yearStr, monthStr, dayStr, hours, minutes, seconds, , ms2, offsetStr] = matches;
35675
35675
  range(monthStr, 1, 12);
35676
35676
  range(dayStr, 1, 31);
35677
35677
  range(hours, 0, 23);
35678
35678
  range(minutes, 0, 59);
35679
35679
  range(seconds, 0, 60);
35680
- 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));
35680
+ 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));
35681
35681
  date2.setUTCFullYear(Number(yearStr));
35682
35682
  if (offsetStr.toUpperCase() != "Z") {
35683
35683
  const [, sign2, offsetH, offsetM] = /([+-])(\d\d):(\d\d)/.exec(offsetStr) || [void 0, "+", 0, 0];
@@ -55690,8 +55690,8 @@ var require_datetime2 = __commonJS({
55690
55690
  if (!(object instanceof Date)) {
55691
55691
  throw new errors_1.InvalidArgumentError(`a Date instance was expected, got "${object}"`);
55692
55692
  }
55693
- const ms = object.getTime() - TIMESHIFT;
55694
- const us = ms * 1e3;
55693
+ const ms2 = object.getTime() - TIMESHIFT;
55694
+ const us = ms2 * 1e3;
55695
55695
  buf.writeInt32(8);
55696
55696
  buf.writeInt64(us);
55697
55697
  }
@@ -55701,12 +55701,12 @@ var require_datetime2 = __commonJS({
55701
55701
  return ctx.postDecode(this, us2 + BI_TIMESHIFT_US);
55702
55702
  }
55703
55703
  const us = Number(buf.readBigInt64());
55704
- let ms = Math.round(us / 1e3);
55705
- if (Math.abs(us % 1e3) === 500 && Math.abs(ms) % 2 === 1) {
55706
- ms -= 1;
55704
+ let ms2 = Math.round(us / 1e3);
55705
+ if (Math.abs(us % 1e3) === 500 && Math.abs(ms2) % 2 === 1) {
55706
+ ms2 -= 1;
55707
55707
  }
55708
- ms += TIMESHIFT;
55709
- return new Date(ms);
55708
+ ms2 += TIMESHIFT;
55709
+ return new Date(ms2);
55710
55710
  }
55711
55711
  };
55712
55712
  exports2.DateTimeCodec = DateTimeCodec;
@@ -55727,8 +55727,8 @@ var require_datetime2 = __commonJS({
55727
55727
  if (!(object instanceof datetime_1.LocalDateTime)) {
55728
55728
  throw new errors_1.InvalidArgumentError(`a LocalDateTime instance was expected, got "${object}"`);
55729
55729
  }
55730
- const ms = BigInt(datetime_1.localDateInstances.get(object).getTime() - TIMESHIFT);
55731
- let us = ms * 1000n + BigInt(object.hour * 36e8 + object.minute * 6e7 + object.second * 1e6 + object.millisecond * 1e3 + object.microsecond);
55730
+ const ms2 = BigInt(datetime_1.localDateInstances.get(object).getTime() - TIMESHIFT);
55731
+ let us = ms2 * 1000n + BigInt(object.hour * 36e8 + object.minute * 6e7 + object.second * 1e6 + object.millisecond * 1e3 + object.microsecond);
55732
55732
  if (object.nanosecond === 500 && Math.abs(object.microsecond) % 2 === 1 || object.nanosecond > 500) {
55733
55733
  us += 1n;
55734
55734
  }
@@ -55742,13 +55742,13 @@ var require_datetime2 = __commonJS({
55742
55742
  }
55743
55743
  const bi_ms = bi_us / 1000n;
55744
55744
  let us = Number(bi_us - bi_ms * 1000n);
55745
- let ms = Number(bi_ms);
55745
+ let ms2 = Number(bi_ms);
55746
55746
  if (us < 0) {
55747
55747
  us += 1e3;
55748
- ms -= 1;
55748
+ ms2 -= 1;
55749
55749
  }
55750
- ms += TIMESHIFT;
55751
- const date2 = new Date(ms);
55750
+ ms2 += TIMESHIFT;
55751
+ const date2 = new Date(ms2);
55752
55752
  return new datetime_1.LocalDateTime(date2.getUTCFullYear(), date2.getUTCMonth() + 1, date2.getUTCDate(), date2.getUTCHours(), date2.getUTCMinutes(), date2.getUTCSeconds(), date2.getUTCMilliseconds(), us);
55753
55753
  }
55754
55754
  };
@@ -55810,13 +55810,13 @@ var require_datetime2 = __commonJS({
55810
55810
  }
55811
55811
  let us = Number(bius);
55812
55812
  let seconds = Math.floor(us / 1e6);
55813
- const ms = Math.floor(us % 1e6 / 1e3);
55814
- us = us % 1e6 - ms * 1e3;
55813
+ const ms2 = Math.floor(us % 1e6 / 1e3);
55814
+ us = us % 1e6 - ms2 * 1e3;
55815
55815
  let minutes = Math.floor(seconds / 60);
55816
55816
  seconds = Math.floor(seconds % 60);
55817
55817
  const hours = Math.floor(minutes / 60);
55818
55818
  minutes = Math.floor(minutes % 60);
55819
- return new datetime_1.LocalTime(hours, minutes, seconds, ms, us);
55819
+ return new datetime_1.LocalTime(hours, minutes, seconds, ms2, us);
55820
55820
  }
55821
55821
  };
55822
55822
  exports2.LocalTimeCodec = LocalTimeCodec;
@@ -55893,14 +55893,14 @@ var require_datetime2 = __commonJS({
55893
55893
  const biMillion = 1000000n;
55894
55894
  const biSeconds = bius / biMillion;
55895
55895
  let us = Number(bius - biSeconds * biMillion);
55896
- const ms = Math.floor(us / 1e3);
55896
+ const ms2 = Math.floor(us / 1e3);
55897
55897
  us = us % 1e3;
55898
55898
  let seconds = Number(biSeconds);
55899
55899
  let minutes = Math.floor(seconds / 60);
55900
55900
  seconds = Math.floor(seconds % 60);
55901
55901
  const hours = Math.floor(minutes / 60);
55902
55902
  minutes = Math.floor(minutes % 60);
55903
- return new datetime_1.Duration(0, 0, 0, 0, hours * sign2, minutes * sign2, seconds * sign2, ms * sign2, us * sign2);
55903
+ return new datetime_1.Duration(0, 0, 0, 0, hours * sign2, minutes * sign2, seconds * sign2, ms2 * sign2, us * sign2);
55904
55904
  }
55905
55905
  };
55906
55906
  exports2.DurationCodec = DurationCodec;
@@ -55946,7 +55946,7 @@ var require_datetime2 = __commonJS({
55946
55946
  const million = BigInt(1e6);
55947
55947
  const biSeconds = bius / million;
55948
55948
  let us = Number(bius - biSeconds * million);
55949
- const ms = Math.trunc(us / 1e3);
55949
+ const ms2 = Math.trunc(us / 1e3);
55950
55950
  us = us % 1e3;
55951
55951
  let seconds = Number(biSeconds);
55952
55952
  let minutes = Math.trunc(seconds / 60);
@@ -55957,7 +55957,7 @@ var require_datetime2 = __commonJS({
55957
55957
  days = Math.trunc(days % 7);
55958
55958
  const years = Math.trunc(months2 / 12);
55959
55959
  months2 = Math.trunc(months2 % 12);
55960
- return new datetime_1.RelativeDuration(years, months2, weeks, days, hours * sign2, minutes * sign2, seconds * sign2, ms * sign2, us * sign2);
55960
+ return new datetime_1.RelativeDuration(years, months2, weeks, days, hours * sign2, minutes * sign2, seconds * sign2, ms2 * sign2, us * sign2);
55961
55961
  }
55962
55962
  };
55963
55963
  exports2.RelativeDurationCodec = RelativeDurationCodec;
@@ -66121,41 +66121,41 @@ var require_ms = __commonJS({
66121
66121
  return void 0;
66122
66122
  }
66123
66123
  }
66124
- function fmtShort(ms) {
66125
- var msAbs = Math.abs(ms);
66124
+ function fmtShort(ms2) {
66125
+ var msAbs = Math.abs(ms2);
66126
66126
  if (msAbs >= d6) {
66127
- return Math.round(ms / d6) + "d";
66127
+ return Math.round(ms2 / d6) + "d";
66128
66128
  }
66129
66129
  if (msAbs >= h7) {
66130
- return Math.round(ms / h7) + "h";
66130
+ return Math.round(ms2 / h7) + "h";
66131
66131
  }
66132
66132
  if (msAbs >= m7) {
66133
- return Math.round(ms / m7) + "m";
66133
+ return Math.round(ms2 / m7) + "m";
66134
66134
  }
66135
66135
  if (msAbs >= s7) {
66136
- return Math.round(ms / s7) + "s";
66136
+ return Math.round(ms2 / s7) + "s";
66137
66137
  }
66138
- return ms + "ms";
66138
+ return ms2 + "ms";
66139
66139
  }
66140
- function fmtLong(ms) {
66141
- var msAbs = Math.abs(ms);
66140
+ function fmtLong(ms2) {
66141
+ var msAbs = Math.abs(ms2);
66142
66142
  if (msAbs >= d6) {
66143
- return plural(ms, msAbs, d6, "day");
66143
+ return plural(ms2, msAbs, d6, "day");
66144
66144
  }
66145
66145
  if (msAbs >= h7) {
66146
- return plural(ms, msAbs, h7, "hour");
66146
+ return plural(ms2, msAbs, h7, "hour");
66147
66147
  }
66148
66148
  if (msAbs >= m7) {
66149
- return plural(ms, msAbs, m7, "minute");
66149
+ return plural(ms2, msAbs, m7, "minute");
66150
66150
  }
66151
66151
  if (msAbs >= s7) {
66152
- return plural(ms, msAbs, s7, "second");
66152
+ return plural(ms2, msAbs, s7, "second");
66153
66153
  }
66154
- return ms + " ms";
66154
+ return ms2 + " ms";
66155
66155
  }
66156
- function plural(ms, msAbs, n6, name) {
66156
+ function plural(ms2, msAbs, n6, name) {
66157
66157
  var isPlural = msAbs >= n6 * 1.5;
66158
- return Math.round(ms / n6) + " " + name + (isPlural ? "s" : "");
66158
+ return Math.round(ms2 / n6) + " " + name + (isPlural ? "s" : "");
66159
66159
  }
66160
66160
  }
66161
66161
  });
@@ -66199,8 +66199,8 @@ var require_common2 = __commonJS({
66199
66199
  }
66200
66200
  const self2 = debug;
66201
66201
  const curr = Number(/* @__PURE__ */ new Date());
66202
- const ms = curr - (prevTime || curr);
66203
- self2.diff = ms;
66202
+ const ms2 = curr - (prevTime || curr);
66203
+ self2.diff = ms2;
66204
66204
  self2.prev = prevTime;
66205
66205
  self2.curr = curr;
66206
66206
  prevTime = curr;
@@ -81703,11 +81703,11 @@ var require_TokenExpiredError = __commonJS({
81703
81703
  var require_timespan = __commonJS({
81704
81704
  "../node_modules/.pnpm/jsonwebtoken@9.0.2/node_modules/jsonwebtoken/lib/timespan.js"(exports2, module) {
81705
81705
  "use strict";
81706
- var ms = require_ms();
81706
+ var ms2 = require_ms();
81707
81707
  module.exports = function(time2, iat) {
81708
81708
  var timestamp = iat || Math.floor(Date.now() / 1e3);
81709
81709
  if (typeof time2 === "string") {
81710
- var milliseconds = ms(time2);
81710
+ var milliseconds = ms2(time2);
81711
81711
  if (typeof milliseconds === "undefined") {
81712
81712
  return;
81713
81713
  }
@@ -96245,7 +96245,7 @@ var require_dist = __commonJS({
96245
96245
  };
96246
96246
  Object.defineProperty(exports2, "__esModule", { value: true });
96247
96247
  exports2.Agent = void 0;
96248
- var net = __importStar2(__require("net"));
96248
+ var net2 = __importStar2(__require("net"));
96249
96249
  var http3 = __importStar2(__require("http"));
96250
96250
  var https_1 = __require("https");
96251
96251
  __exportStar2(require_helpers2(), exports2);
@@ -96285,7 +96285,7 @@ var require_dist = __commonJS({
96285
96285
  if (!this.sockets[name]) {
96286
96286
  this.sockets[name] = [];
96287
96287
  }
96288
- const fakeSocket = new net.Socket({ writable: false });
96288
+ const fakeSocket = new net2.Socket({ writable: false });
96289
96289
  this.sockets[name].push(fakeSocket);
96290
96290
  this.totalSocketCount++;
96291
96291
  return fakeSocket;
@@ -96497,7 +96497,7 @@ var require_dist2 = __commonJS({
96497
96497
  };
96498
96498
  Object.defineProperty(exports2, "__esModule", { value: true });
96499
96499
  exports2.HttpsProxyAgent = void 0;
96500
- var net = __importStar2(__require("net"));
96500
+ var net2 = __importStar2(__require("net"));
96501
96501
  var tls = __importStar2(__require("tls"));
96502
96502
  var assert_1 = __importDefault2(__require("assert"));
96503
96503
  var debug_1 = __importDefault2(require_src2());
@@ -96506,7 +96506,7 @@ var require_dist2 = __commonJS({
96506
96506
  var parse_proxy_response_1 = require_parse_proxy_response();
96507
96507
  var debug = (0, debug_1.default)("https-proxy-agent");
96508
96508
  var setServernameFromNonIpHost = (options) => {
96509
- if (options.servername === void 0 && options.host && !net.isIP(options.host)) {
96509
+ if (options.servername === void 0 && options.host && !net2.isIP(options.host)) {
96510
96510
  return {
96511
96511
  ...options,
96512
96512
  servername: options.host
@@ -96546,10 +96546,10 @@ var require_dist2 = __commonJS({
96546
96546
  socket = tls.connect(setServernameFromNonIpHost(this.connectOpts));
96547
96547
  } else {
96548
96548
  debug("Creating `net.Socket`: %o", this.connectOpts);
96549
- socket = net.connect(this.connectOpts);
96549
+ socket = net2.connect(this.connectOpts);
96550
96550
  }
96551
96551
  const headers = typeof this.proxyHeaders === "function" ? this.proxyHeaders() : { ...this.proxyHeaders };
96552
- const host = net.isIPv6(opts.host) ? `[${opts.host}]` : opts.host;
96552
+ const host = net2.isIPv6(opts.host) ? `[${opts.host}]` : opts.host;
96553
96553
  let payload = `CONNECT ${host}:${opts.port} HTTP/1.1\r
96554
96554
  `;
96555
96555
  if (proxy.username || proxy.password) {
@@ -96582,7 +96582,7 @@ var require_dist2 = __commonJS({
96582
96582
  return socket;
96583
96583
  }
96584
96584
  socket.destroy();
96585
- const fakeSocket = new net.Socket({ writable: false });
96585
+ const fakeSocket = new net2.Socket({ writable: false });
96586
96586
  fakeSocket.readable = true;
96587
96587
  req.once("socket", (s7) => {
96588
96588
  debug("Replaying proxy buffer for failed request");
@@ -96647,7 +96647,7 @@ var require_dist3 = __commonJS({
96647
96647
  };
96648
96648
  Object.defineProperty(exports2, "__esModule", { value: true });
96649
96649
  exports2.HttpProxyAgent = void 0;
96650
- var net = __importStar2(__require("net"));
96650
+ var net2 = __importStar2(__require("net"));
96651
96651
  var tls = __importStar2(__require("tls"));
96652
96652
  var debug_1 = __importDefault2(require_src2());
96653
96653
  var events_1 = __require("events");
@@ -96720,7 +96720,7 @@ var require_dist3 = __commonJS({
96720
96720
  socket = tls.connect(this.connectOpts);
96721
96721
  } else {
96722
96722
  debug("Creating `net.Socket`: %o", this.connectOpts);
96723
- socket = net.connect(this.connectOpts);
96723
+ socket = net2.connect(this.connectOpts);
96724
96724
  }
96725
96725
  await (0, events_1.once)(socket, "connect");
96726
96726
  return socket;
@@ -135599,7 +135599,7 @@ var require_connection = __commonJS({
135599
135599
  var _crypto = _interopRequireDefault(__require("crypto"));
135600
135600
  var _os = _interopRequireDefault(__require("os"));
135601
135601
  var tls = _interopRequireWildcard(__require("tls"));
135602
- var net = _interopRequireWildcard(__require("net"));
135602
+ var net2 = _interopRequireWildcard(__require("net"));
135603
135603
  var _dns = _interopRequireDefault(__require("dns"));
135604
135604
  var _constants = _interopRequireDefault(__require("constants"));
135605
135605
  var _stream = __require("stream");
@@ -136648,7 +136648,7 @@ var require_connection = __commonJS({
136648
136648
  async wrapWithTls(socket, signal) {
136649
136649
  signal.throwIfAborted();
136650
136650
  const secureContext = tls.createSecureContext(this.secureContextOptions);
136651
- const serverName = !net.isIP(this.config.server) ? this.config.server : "";
136651
+ const serverName = !net2.isIP(this.config.server) ? this.config.server : "";
136652
136652
  const encryptOptions = {
136653
136653
  host: this.config.server,
136654
136654
  socket,
@@ -139557,6 +139557,7 @@ __export(connections_exports, {
139557
139557
  prepareGelDB: () => prepareGelDB,
139558
139558
  preparePostgresDB: () => preparePostgresDB
139559
139559
  });
139560
+ import net from "net";
139560
139561
  function parseMssqlUrl(url) {
139561
139562
  return {
139562
139563
  user: url.username,
@@ -139570,7 +139571,7 @@ function parseMssqlUrl(url) {
139570
139571
  }
139571
139572
  };
139572
139573
  }
139573
- var normalisePGliteUrl, preparePostgresDB, prepareCockroach, prepareGelDB, parseSingleStoreCredentials, connectToSingleStore, parseMysqlCredentials, connectToMySQL, parseMssqlCredentials, connectToMsSQL, prepareSqliteParams, preparePGliteParams, connectToSQLite, connectToLibSQL;
139574
+ var ms, normalisePGliteUrl, preparePostgresDB, prepareCockroach, prepareGelDB, parseSingleStoreCredentials, connectToSingleStore, parseMysqlCredentials, connectToMySQL, parseMssqlCredentials, connectToMsSQL, prepareSqliteParams, preparePGliteParams, connectToSQLite, connectToLibSQL;
139574
139575
  var init_connections = __esm({
139575
139576
  "src/cli/connections.ts"() {
139576
139577
  "use strict";
@@ -139581,6 +139582,7 @@ var init_connections = __esm({
139581
139582
  init_when_json_met_bigint();
139582
139583
  init_utils3();
139583
139584
  init_outputs();
139585
+ ms = (a6, b6) => Number(b6 - a6) / 1e6;
139584
139586
  normalisePGliteUrl = (it) => {
139585
139587
  if (it.startsWith("file:")) {
139586
139588
  return it.substring(5);
@@ -139735,13 +139737,13 @@ var init_connections = __esm({
139735
139737
  return pg.types.getTypeParser(typeId, format2);
139736
139738
  }
139737
139739
  };
139738
- const client = "url" in credentials ? new pg.Pool({ connectionString: credentials.url, max: 1 }) : new pg.Pool({ ...credentials, ssl, max: 1 });
139739
- const db = drizzle({ client });
139740
+ const pool = "url" in credentials ? new pg.Pool({ connectionString: credentials.url, max: 1 }) : new pg.Pool({ ...credentials, ssl, max: 1 });
139741
+ const db = drizzle({ client: pool });
139740
139742
  const migrateFn = async (config) => {
139741
139743
  return migrate(db, config);
139742
139744
  };
139743
139745
  const query = async (sql, params) => {
139744
- const result2 = await client.query({
139746
+ const result2 = await pool.query({
139745
139747
  text: sql,
139746
139748
  values: params ?? [],
139747
139749
  types: types3
@@ -139751,7 +139753,7 @@ var init_connections = __esm({
139751
139753
  return result2.rows;
139752
139754
  };
139753
139755
  const proxy = async (params) => {
139754
- const result2 = await client.query({
139756
+ const result2 = await pool.query({
139755
139757
  text: params.sql,
139756
139758
  values: params.params,
139757
139759
  ...params.mode === "array" && { rowMode: "array" },
@@ -139763,7 +139765,7 @@ var init_connections = __esm({
139763
139765
  };
139764
139766
  const transactionProxy = async (queries) => {
139765
139767
  const results = [];
139766
- const tx = await client.connect();
139768
+ const tx = await pool.connect();
139767
139769
  try {
139768
139770
  await tx.query("BEGIN");
139769
139771
  for (const query2 of queries) {
@@ -139782,7 +139784,77 @@ var init_connections = __esm({
139782
139784
  }
139783
139785
  return results;
139784
139786
  };
139785
- return { packageName: "pg", query, proxy, transactionProxy, migrate: migrateFn };
139787
+ const benchmarkQuery = async (client, sql, params) => {
139788
+ const explainResult = await pool.query({
139789
+ text: `EXPLAIN ANALYZE ${sql}`,
139790
+ values: params ?? [],
139791
+ types: types3
139792
+ });
139793
+ const stringifiedResult = JSON.stringify(explainResult.rows);
139794
+ const planningMatch = stringifiedResult.match(/Planning Time:\s*([\d.]+)\s*ms/i);
139795
+ const executionMatch = stringifiedResult.match(/Execution Time:\s*([\d.]+)\s*ms/i);
139796
+ const planningTime = Number(planningMatch[1]);
139797
+ const executionTime = Number(executionMatch[1]);
139798
+ let querySentAt = 0n;
139799
+ let firstDataAt = 0n;
139800
+ let lastDataAt = 0n;
139801
+ let bytesReceived = 0;
139802
+ client.connection.addListener("rowDescription", (data) => {
139803
+ if (firstDataAt === 0n) {
139804
+ firstDataAt = process.hrtime.bigint();
139805
+ }
139806
+ bytesReceived += data.length;
139807
+ });
139808
+ client.connection.addListener("dataRow", (data) => {
139809
+ bytesReceived += data.length;
139810
+ });
139811
+ client.connection.addListener("commandComplete", () => {
139812
+ lastDataAt = process.hrtime.bigint();
139813
+ });
139814
+ querySentAt = process.hrtime.bigint();
139815
+ await client.query(sql, params);
139816
+ client.connection.removeAllListeners("rowDescription");
139817
+ client.connection.removeAllListeners("dataRow");
139818
+ client.connection.removeAllListeners("commandComplete");
139819
+ return {
139820
+ planning: planningTime,
139821
+ execution: executionTime,
139822
+ dataDownload: ms(firstDataAt, lastDataAt) + ms(querySentAt, firstDataAt) - executionTime - planningTime,
139823
+ total: ms(querySentAt, lastDataAt),
139824
+ dataSize: bytesReceived
139825
+ };
139826
+ };
139827
+ const benchmarkProxy = async ({ sql, params }, repeats) => {
139828
+ let startAt = 0n;
139829
+ let tcpConnectedAt = 0n;
139830
+ let tlsConnectedAt = null;
139831
+ let dbReadyAt = 0n;
139832
+ const client = "url" in credentials ? new pg.Client({ connectionString: credentials.url }) : new pg.Client({ ...credentials, ssl });
139833
+ client.connection.once("connect", () => {
139834
+ tcpConnectedAt = process.hrtime.bigint();
139835
+ });
139836
+ client.connection.prependOnceListener("sslconnect", () => {
139837
+ tlsConnectedAt = process.hrtime.bigint();
139838
+ });
139839
+ client.connection.prependOnceListener("readyForQuery", () => {
139840
+ dbReadyAt = process.hrtime.bigint();
139841
+ });
139842
+ startAt = process.hrtime.bigint();
139843
+ await client.connect();
139844
+ const results = [];
139845
+ for (let i7 = 0; i7 < repeats; i7++) {
139846
+ const r7 = await benchmarkQuery(client, sql, params);
139847
+ results.push(r7);
139848
+ }
139849
+ await client.end();
139850
+ return {
139851
+ tcpHandshake: ms(startAt, tcpConnectedAt),
139852
+ tlsHandshake: tlsConnectedAt ? ms(tcpConnectedAt, tlsConnectedAt) : null,
139853
+ dbHandshake: ms(tlsConnectedAt ?? tcpConnectedAt, dbReadyAt),
139854
+ queries: results
139855
+ };
139856
+ };
139857
+ return { packageName: "pg", query, proxy, transactionProxy, benchmarkProxy, migrate: migrateFn };
139786
139858
  }
139787
139859
  if (await checkPackage("postgres")) {
139788
139860
  console.log(
@@ -140277,7 +140349,6 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
140277
140349
  }
140278
140350
  return next();
140279
140351
  };
140280
- await connection.connect();
140281
140352
  const query = async (sql, params) => {
140282
140353
  const res = await connection.execute({
140283
140354
  sql,
@@ -140317,11 +140388,112 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
140317
140388
  }
140318
140389
  return results;
140319
140390
  };
140391
+ const benchmarkQuery = async (newConnection, sql, params) => {
140392
+ const explainResult = await connection.query({
140393
+ sql: `EXPLAIN ANALYZE ${sql}`,
140394
+ values: params ?? [],
140395
+ typeCast
140396
+ });
140397
+ const stringifiedResult = JSON.stringify(explainResult[0]);
140398
+ const timeMatch = stringifiedResult.match(
140399
+ /actual time=([0-9.eE+-]+)\.\.([0-9.eE+-]+)/
140400
+ );
140401
+ const lastRowTime = Number(timeMatch[2]);
140402
+ const executionTime = lastRowTime;
140403
+ let querySentAt = 0n;
140404
+ let firstDataAt = 0n;
140405
+ let lastDataAt = 0n;
140406
+ let bytesReceived = 0;
140407
+ querySentAt = process.hrtime.bigint();
140408
+ await new Promise((resolve2, reject) => {
140409
+ const query2 = newConnection.query({
140410
+ sql,
140411
+ values: params ?? [],
140412
+ typeCast
140413
+ // rowsAsArray: true,
140414
+ });
140415
+ query2.on("error", (err2) => {
140416
+ reject(err2);
140417
+ });
140418
+ query2.on("fields", (fields) => {
140419
+ if (firstDataAt === 0n) {
140420
+ firstDataAt = process.hrtime.bigint();
140421
+ }
140422
+ bytesReceived += fields[0]._buf.length;
140423
+ });
140424
+ query2.on("end", () => {
140425
+ lastDataAt = process.hrtime.bigint();
140426
+ resolve2();
140427
+ });
140428
+ });
140429
+ return {
140430
+ planning: null,
140431
+ execution: executionTime,
140432
+ dataDownload: ms(firstDataAt, lastDataAt) + ms(querySentAt, firstDataAt) - executionTime,
140433
+ total: ms(querySentAt, lastDataAt),
140434
+ dataSize: bytesReceived
140435
+ };
140436
+ };
140437
+ const benchmarkProxy = async ({ sql, params }, repeats) => {
140438
+ const { createConnection: createConnection2 } = await import("mysql2");
140439
+ let startAt = 0n;
140440
+ let tcpConnectedAt = 0n;
140441
+ let tlsConnectedAt = null;
140442
+ const createStream = ({ config }) => {
140443
+ let stream;
140444
+ if (config.socketPath) {
140445
+ stream = net.connect(config.socketPath);
140446
+ } else {
140447
+ stream = net.connect(config.port, config.host);
140448
+ }
140449
+ if (config.enableKeepAlive) {
140450
+ stream.on("connect", () => {
140451
+ stream.setKeepAlive(true, config.keepAliveInitialDelay);
140452
+ });
140453
+ }
140454
+ stream.setNoDelay(true);
140455
+ stream.once("connect", () => {
140456
+ tcpConnectedAt = process.hrtime.bigint();
140457
+ });
140458
+ return stream;
140459
+ };
140460
+ startAt = process.hrtime.bigint();
140461
+ const connection2 = result2.url ? createConnection2({
140462
+ uri: result2.url,
140463
+ stream: createStream
140464
+ }) : createConnection2({
140465
+ ...result2.credentials,
140466
+ stream: createStream
140467
+ });
140468
+ await new Promise((resolve2, reject) => {
140469
+ connection2.connect((err2) => {
140470
+ tlsConnectedAt = process.hrtime.bigint();
140471
+ if (err2) {
140472
+ reject(err2);
140473
+ } else {
140474
+ resolve2();
140475
+ }
140476
+ });
140477
+ });
140478
+ const results = [];
140479
+ for (let i7 = 0; i7 < repeats; i7++) {
140480
+ const r7 = await benchmarkQuery(connection2, sql, params);
140481
+ results.push(r7);
140482
+ }
140483
+ connection2.end();
140484
+ return {
140485
+ tcpHandshake: ms(startAt, tcpConnectedAt),
140486
+ tlsHandshake: tlsConnectedAt ? ms(tcpConnectedAt, tlsConnectedAt) : null,
140487
+ dbHandshake: null,
140488
+ queries: results
140489
+ };
140490
+ };
140320
140491
  return {
140321
140492
  db: { query },
140322
140493
  packageName: "mysql2",
140323
140494
  proxy,
140324
140495
  transactionProxy,
140496
+ benchmarkProxy,
140325
140497
  database: result2.database,
140326
140498
  migrate: migrateFn
140327
140499
  };
@@ -140981,7 +141153,7 @@ import { getTableConfig as singlestoreTableConfig, SingleStoreTable } from "driz
140981
141153
  import { getTableConfig as sqliteTableConfig, SQLiteTable } from "drizzle-orm/sqlite-core";
140982
141154
  import fs9 from "fs";
140983
141155
  import { createServer } from "https";
140984
- var preparePgSchema, prepareMySqlSchema, prepareMsSqlSchema, prepareSQLiteSchema, prepareSingleStoreSchema, getCustomDefaults, drizzleForPostgres, drizzleForMySQL, drizzleForSQLite, drizzleForLibSQL, drizzleForSingleStore, extractRelations, init2, proxySchema, transactionProxySchema, defaultsSchema, schema5, jsonStringify, prepareServer;
141156
+ var preparePgSchema, prepareMySqlSchema, prepareMsSqlSchema, prepareSQLiteSchema, prepareSingleStoreSchema, getCustomDefaults, drizzleForPostgres, drizzleForMySQL, drizzleForSQLite, drizzleForLibSQL, drizzleForSingleStore, extractRelations, init2, proxySchema, transactionProxySchema, benchmarkProxySchema, defaultsSchema, schema5, jsonStringify, prepareServer;
140985
141157
  var init_studio = __esm({
140986
141158
  "src/cli/commands/studio.ts"() {
140987
141159
  "use strict";
@@ -141195,6 +141367,7 @@ var init_studio = __esm({
141195
141367
  packageName: db.packageName,
141196
141368
  proxy: db.proxy,
141197
141369
  transactionProxy: db.transactionProxy,
141370
+ benchmarkProxy: db.benchmarkProxy,
141198
141371
  customDefaults,
141199
141372
  schema: pgSchema2,
141200
141373
  relations,
@@ -141204,7 +141377,7 @@ var init_studio = __esm({
141204
141377
  };
141205
141378
  drizzleForMySQL = async (credentials, mysqlSchema, relations, schemaFiles, casing2) => {
141206
141379
  const { connectToMySQL: connectToMySQL2 } = await Promise.resolve().then(() => (init_connections(), connections_exports));
141207
- const { proxy, transactionProxy, database, packageName } = await connectToMySQL2(credentials);
141380
+ const { proxy, transactionProxy, benchmarkProxy, database, packageName } = await connectToMySQL2(credentials);
141208
141381
  const customDefaults = getCustomDefaults(mysqlSchema, casing2);
141209
141382
  let dbUrl;
141210
141383
  if ("url" in credentials) {
@@ -141220,6 +141393,7 @@ var init_studio = __esm({
141220
141393
  databaseName: database,
141221
141394
  proxy,
141222
141395
  transactionProxy,
141396
+ benchmarkProxy,
141223
141397
  customDefaults,
141224
141398
  schema: mysqlSchema,
141225
141399
  relations,
@@ -141389,6 +141563,23 @@ var init_studio = __esm({
141389
141563
  ]).optional()
141390
141564
  }).array()
141391
141565
  });
141566
+ benchmarkProxySchema = external_exports.object({
141567
+ type: external_exports.literal("bproxy"),
141568
+ data: external_exports.object({
141569
+ query: external_exports.object({
141570
+ sql: external_exports.string(),
141571
+ params: external_exports.array(external_exports.any()).optional(),
141572
+ method: external_exports.union([
141573
+ external_exports.literal("values"),
141574
+ external_exports.literal("get"),
141575
+ external_exports.literal("all"),
141576
+ external_exports.literal("run"),
141577
+ external_exports.literal("execute")
141578
+ ]).optional()
141579
+ }),
141580
+ repeats: external_exports.number().min(1).optional()
141581
+ })
141582
+ });
141392
141583
  defaultsSchema = external_exports.object({
141393
141584
  type: external_exports.literal("defaults"),
141394
141585
  data: external_exports.array(
@@ -141403,6 +141594,7 @@ var init_studio = __esm({
141403
141594
  init2,
141404
141595
  proxySchema,
141405
141596
  transactionProxySchema,
141597
+ benchmarkProxySchema,
141406
141598
  defaultsSchema
141407
141599
  ]);
141408
141600
  jsonStringify = (data) => {
@@ -141425,6 +141617,7 @@ var init_studio = __esm({
141425
141617
  databaseName,
141426
141618
  proxy,
141427
141619
  transactionProxy,
141620
+ benchmarkProxy,
141428
141621
  customDefaults,
141429
141622
  schema: drizzleSchema,
141430
141623
  relations,
@@ -141488,7 +141681,7 @@ var init_studio = __esm({
141488
141681
  console.warn("Error message:", error3.message);
141489
141682
  }
141490
141683
  return c6.json({
141491
- version: "6.2",
141684
+ version: "6.3",
141492
141685
  dialect: dialect6,
141493
141686
  driver: driver2,
141494
141687
  packageName,
@@ -141526,6 +141719,21 @@ var init_studio = __esm({
141526
141719
  }
141527
141720
  );
141528
141721
  }
141722
+ if (type === "bproxy") {
141723
+ if (!benchmarkProxy) {
141724
+ throw new Error("Benchmark proxy is not configured for this database.");
141725
+ }
141726
+ const result2 = await benchmarkProxy(body.data.query, body.data.repeats || 1);
141727
+ const res = jsonStringify(result2);
141728
+ return c6.body(
141729
+ res,
141730
+ {
141731
+ headers: {
141732
+ "Content-Type": "application/json"
141733
+ }
141734
+ }
141735
+ );
141736
+ }
141529
141737
  if (type === "defaults") {
141530
141738
  const columns = body.data;
141531
141739
  const result2 = columns.map((column7) => {