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-postgres.mjs CHANGED
@@ -34431,7 +34431,7 @@ var require_websocket = __commonJS({
34431
34431
  var EventEmitter = __require("events");
34432
34432
  var https2 = __require("https");
34433
34433
  var http3 = __require("http");
34434
- var net = __require("net");
34434
+ var net2 = __require("net");
34435
34435
  var tls = __require("tls");
34436
34436
  var { randomBytes, createHash: createHash5 } = __require("crypto");
34437
34437
  var { Duplex, Readable: Readable6 } = __require("stream");
@@ -35162,12 +35162,12 @@ var require_websocket = __commonJS({
35162
35162
  }
35163
35163
  function netConnect(options) {
35164
35164
  options.path = options.socketPath;
35165
- return net.connect(options);
35165
+ return net2.connect(options);
35166
35166
  }
35167
35167
  function tlsConnect(options) {
35168
35168
  options.path = void 0;
35169
35169
  if (!options.servername && options.servername !== "") {
35170
- options.servername = net.isIP(options.host) ? "" : options.host;
35170
+ options.servername = net2.isIP(options.host) ? "" : options.host;
35171
35171
  }
35172
35172
  return tls.connect(options);
35173
35173
  }
@@ -39485,7 +39485,7 @@ var init_timing = __esm({
39485
39485
  "../node_modules/.pnpm/@smithy+node-http-handler@4.4.5/node_modules/@smithy/node-http-handler/dist-es/timing.js"() {
39486
39486
  "use strict";
39487
39487
  timing = {
39488
- setTimeout: (cb, ms) => setTimeout(cb, ms),
39488
+ setTimeout: (cb, ms2) => setTimeout(cb, ms2),
39489
39489
  clearTimeout: (timeoutId) => clearTimeout(timeoutId)
39490
39490
  };
39491
39491
  }
@@ -41373,13 +41373,13 @@ var init_schema_date_utils = __esm({
41373
41373
  if (!matches) {
41374
41374
  throw new TypeError(`Invalid RFC3339 timestamp format ${value}`);
41375
41375
  }
41376
- const [, yearStr, monthStr, dayStr, hours, minutes, seconds, , ms, offsetStr] = matches;
41376
+ const [, yearStr, monthStr, dayStr, hours, minutes, seconds, , ms2, offsetStr] = matches;
41377
41377
  range(monthStr, 1, 12);
41378
41378
  range(dayStr, 1, 31);
41379
41379
  range(hours, 0, 23);
41380
41380
  range(minutes, 0, 59);
41381
41381
  range(seconds, 0, 60);
41382
- 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));
41382
+ 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));
41383
41383
  date2.setUTCFullYear(Number(yearStr));
41384
41384
  if (offsetStr.toUpperCase() != "Z") {
41385
41385
  const [, sign2, offsetH, offsetM] = /([+-])(\d\d):(\d\d)/.exec(offsetStr) || [void 0, "+", 0, 0];
@@ -61392,8 +61392,8 @@ var require_datetime2 = __commonJS({
61392
61392
  if (!(object instanceof Date)) {
61393
61393
  throw new errors_1.InvalidArgumentError(`a Date instance was expected, got "${object}"`);
61394
61394
  }
61395
- const ms = object.getTime() - TIMESHIFT;
61396
- const us = ms * 1e3;
61395
+ const ms2 = object.getTime() - TIMESHIFT;
61396
+ const us = ms2 * 1e3;
61397
61397
  buf.writeInt32(8);
61398
61398
  buf.writeInt64(us);
61399
61399
  }
@@ -61403,12 +61403,12 @@ var require_datetime2 = __commonJS({
61403
61403
  return ctx.postDecode(this, us2 + BI_TIMESHIFT_US);
61404
61404
  }
61405
61405
  const us = Number(buf.readBigInt64());
61406
- let ms = Math.round(us / 1e3);
61407
- if (Math.abs(us % 1e3) === 500 && Math.abs(ms) % 2 === 1) {
61408
- ms -= 1;
61406
+ let ms2 = Math.round(us / 1e3);
61407
+ if (Math.abs(us % 1e3) === 500 && Math.abs(ms2) % 2 === 1) {
61408
+ ms2 -= 1;
61409
61409
  }
61410
- ms += TIMESHIFT;
61411
- return new Date(ms);
61410
+ ms2 += TIMESHIFT;
61411
+ return new Date(ms2);
61412
61412
  }
61413
61413
  };
61414
61414
  exports2.DateTimeCodec = DateTimeCodec;
@@ -61429,8 +61429,8 @@ var require_datetime2 = __commonJS({
61429
61429
  if (!(object instanceof datetime_1.LocalDateTime)) {
61430
61430
  throw new errors_1.InvalidArgumentError(`a LocalDateTime instance was expected, got "${object}"`);
61431
61431
  }
61432
- const ms = BigInt(datetime_1.localDateInstances.get(object).getTime() - TIMESHIFT);
61433
- let us = ms * 1000n + BigInt(object.hour * 36e8 + object.minute * 6e7 + object.second * 1e6 + object.millisecond * 1e3 + object.microsecond);
61432
+ const ms2 = BigInt(datetime_1.localDateInstances.get(object).getTime() - TIMESHIFT);
61433
+ let us = ms2 * 1000n + BigInt(object.hour * 36e8 + object.minute * 6e7 + object.second * 1e6 + object.millisecond * 1e3 + object.microsecond);
61434
61434
  if (object.nanosecond === 500 && Math.abs(object.microsecond) % 2 === 1 || object.nanosecond > 500) {
61435
61435
  us += 1n;
61436
61436
  }
@@ -61444,13 +61444,13 @@ var require_datetime2 = __commonJS({
61444
61444
  }
61445
61445
  const bi_ms = bi_us / 1000n;
61446
61446
  let us = Number(bi_us - bi_ms * 1000n);
61447
- let ms = Number(bi_ms);
61447
+ let ms2 = Number(bi_ms);
61448
61448
  if (us < 0) {
61449
61449
  us += 1e3;
61450
- ms -= 1;
61450
+ ms2 -= 1;
61451
61451
  }
61452
- ms += TIMESHIFT;
61453
- const date2 = new Date(ms);
61452
+ ms2 += TIMESHIFT;
61453
+ const date2 = new Date(ms2);
61454
61454
  return new datetime_1.LocalDateTime(date2.getUTCFullYear(), date2.getUTCMonth() + 1, date2.getUTCDate(), date2.getUTCHours(), date2.getUTCMinutes(), date2.getUTCSeconds(), date2.getUTCMilliseconds(), us);
61455
61455
  }
61456
61456
  };
@@ -61512,13 +61512,13 @@ var require_datetime2 = __commonJS({
61512
61512
  }
61513
61513
  let us = Number(bius);
61514
61514
  let seconds = Math.floor(us / 1e6);
61515
- const ms = Math.floor(us % 1e6 / 1e3);
61516
- us = us % 1e6 - ms * 1e3;
61515
+ const ms2 = Math.floor(us % 1e6 / 1e3);
61516
+ us = us % 1e6 - ms2 * 1e3;
61517
61517
  let minutes = Math.floor(seconds / 60);
61518
61518
  seconds = Math.floor(seconds % 60);
61519
61519
  const hours = Math.floor(minutes / 60);
61520
61520
  minutes = Math.floor(minutes % 60);
61521
- return new datetime_1.LocalTime(hours, minutes, seconds, ms, us);
61521
+ return new datetime_1.LocalTime(hours, minutes, seconds, ms2, us);
61522
61522
  }
61523
61523
  };
61524
61524
  exports2.LocalTimeCodec = LocalTimeCodec;
@@ -61595,14 +61595,14 @@ var require_datetime2 = __commonJS({
61595
61595
  const biMillion = 1000000n;
61596
61596
  const biSeconds = bius / biMillion;
61597
61597
  let us = Number(bius - biSeconds * biMillion);
61598
- const ms = Math.floor(us / 1e3);
61598
+ const ms2 = Math.floor(us / 1e3);
61599
61599
  us = us % 1e3;
61600
61600
  let seconds = Number(biSeconds);
61601
61601
  let minutes = Math.floor(seconds / 60);
61602
61602
  seconds = Math.floor(seconds % 60);
61603
61603
  const hours = Math.floor(minutes / 60);
61604
61604
  minutes = Math.floor(minutes % 60);
61605
- return new datetime_1.Duration(0, 0, 0, 0, hours * sign2, minutes * sign2, seconds * sign2, ms * sign2, us * sign2);
61605
+ return new datetime_1.Duration(0, 0, 0, 0, hours * sign2, minutes * sign2, seconds * sign2, ms2 * sign2, us * sign2);
61606
61606
  }
61607
61607
  };
61608
61608
  exports2.DurationCodec = DurationCodec;
@@ -61648,7 +61648,7 @@ var require_datetime2 = __commonJS({
61648
61648
  const million = BigInt(1e6);
61649
61649
  const biSeconds = bius / million;
61650
61650
  let us = Number(bius - biSeconds * million);
61651
- const ms = Math.trunc(us / 1e3);
61651
+ const ms2 = Math.trunc(us / 1e3);
61652
61652
  us = us % 1e3;
61653
61653
  let seconds = Number(biSeconds);
61654
61654
  let minutes = Math.trunc(seconds / 60);
@@ -61659,7 +61659,7 @@ var require_datetime2 = __commonJS({
61659
61659
  days = Math.trunc(days % 7);
61660
61660
  const years = Math.trunc(months2 / 12);
61661
61661
  months2 = Math.trunc(months2 % 12);
61662
- return new datetime_1.RelativeDuration(years, months2, weeks, days, hours * sign2, minutes * sign2, seconds * sign2, ms * sign2, us * sign2);
61662
+ return new datetime_1.RelativeDuration(years, months2, weeks, days, hours * sign2, minutes * sign2, seconds * sign2, ms2 * sign2, us * sign2);
61663
61663
  }
61664
61664
  };
61665
61665
  exports2.RelativeDurationCodec = RelativeDurationCodec;
@@ -71823,41 +71823,41 @@ var require_ms = __commonJS({
71823
71823
  return void 0;
71824
71824
  }
71825
71825
  }
71826
- function fmtShort(ms) {
71827
- var msAbs = Math.abs(ms);
71826
+ function fmtShort(ms2) {
71827
+ var msAbs = Math.abs(ms2);
71828
71828
  if (msAbs >= d6) {
71829
- return Math.round(ms / d6) + "d";
71829
+ return Math.round(ms2 / d6) + "d";
71830
71830
  }
71831
71831
  if (msAbs >= h7) {
71832
- return Math.round(ms / h7) + "h";
71832
+ return Math.round(ms2 / h7) + "h";
71833
71833
  }
71834
71834
  if (msAbs >= m7) {
71835
- return Math.round(ms / m7) + "m";
71835
+ return Math.round(ms2 / m7) + "m";
71836
71836
  }
71837
71837
  if (msAbs >= s7) {
71838
- return Math.round(ms / s7) + "s";
71838
+ return Math.round(ms2 / s7) + "s";
71839
71839
  }
71840
- return ms + "ms";
71840
+ return ms2 + "ms";
71841
71841
  }
71842
- function fmtLong(ms) {
71843
- var msAbs = Math.abs(ms);
71842
+ function fmtLong(ms2) {
71843
+ var msAbs = Math.abs(ms2);
71844
71844
  if (msAbs >= d6) {
71845
- return plural2(ms, msAbs, d6, "day");
71845
+ return plural2(ms2, msAbs, d6, "day");
71846
71846
  }
71847
71847
  if (msAbs >= h7) {
71848
- return plural2(ms, msAbs, h7, "hour");
71848
+ return plural2(ms2, msAbs, h7, "hour");
71849
71849
  }
71850
71850
  if (msAbs >= m7) {
71851
- return plural2(ms, msAbs, m7, "minute");
71851
+ return plural2(ms2, msAbs, m7, "minute");
71852
71852
  }
71853
71853
  if (msAbs >= s7) {
71854
- return plural2(ms, msAbs, s7, "second");
71854
+ return plural2(ms2, msAbs, s7, "second");
71855
71855
  }
71856
- return ms + " ms";
71856
+ return ms2 + " ms";
71857
71857
  }
71858
- function plural2(ms, msAbs, n6, name) {
71858
+ function plural2(ms2, msAbs, n6, name) {
71859
71859
  var isPlural = msAbs >= n6 * 1.5;
71860
- return Math.round(ms / n6) + " " + name + (isPlural ? "s" : "");
71860
+ return Math.round(ms2 / n6) + " " + name + (isPlural ? "s" : "");
71861
71861
  }
71862
71862
  }
71863
71863
  });
@@ -71901,8 +71901,8 @@ var require_common2 = __commonJS({
71901
71901
  }
71902
71902
  const self2 = debug;
71903
71903
  const curr = Number(/* @__PURE__ */ new Date());
71904
- const ms = curr - (prevTime || curr);
71905
- self2.diff = ms;
71904
+ const ms2 = curr - (prevTime || curr);
71905
+ self2.diff = ms2;
71906
71906
  self2.prev = prevTime;
71907
71907
  self2.curr = curr;
71908
71908
  prevTime = curr;
@@ -87405,11 +87405,11 @@ var require_TokenExpiredError = __commonJS({
87405
87405
  var require_timespan = __commonJS({
87406
87406
  "../node_modules/.pnpm/jsonwebtoken@9.0.2/node_modules/jsonwebtoken/lib/timespan.js"(exports2, module) {
87407
87407
  "use strict";
87408
- var ms = require_ms();
87408
+ var ms2 = require_ms();
87409
87409
  module.exports = function(time2, iat) {
87410
87410
  var timestamp = iat || Math.floor(Date.now() / 1e3);
87411
87411
  if (typeof time2 === "string") {
87412
- var milliseconds = ms(time2);
87412
+ var milliseconds = ms2(time2);
87413
87413
  if (typeof milliseconds === "undefined") {
87414
87414
  return;
87415
87415
  }
@@ -101947,7 +101947,7 @@ var require_dist = __commonJS({
101947
101947
  };
101948
101948
  Object.defineProperty(exports2, "__esModule", { value: true });
101949
101949
  exports2.Agent = void 0;
101950
- var net = __importStar2(__require("net"));
101950
+ var net2 = __importStar2(__require("net"));
101951
101951
  var http3 = __importStar2(__require("http"));
101952
101952
  var https_1 = __require("https");
101953
101953
  __exportStar2(require_helpers2(), exports2);
@@ -101987,7 +101987,7 @@ var require_dist = __commonJS({
101987
101987
  if (!this.sockets[name]) {
101988
101988
  this.sockets[name] = [];
101989
101989
  }
101990
- const fakeSocket = new net.Socket({ writable: false });
101990
+ const fakeSocket = new net2.Socket({ writable: false });
101991
101991
  this.sockets[name].push(fakeSocket);
101992
101992
  this.totalSocketCount++;
101993
101993
  return fakeSocket;
@@ -102199,7 +102199,7 @@ var require_dist2 = __commonJS({
102199
102199
  };
102200
102200
  Object.defineProperty(exports2, "__esModule", { value: true });
102201
102201
  exports2.HttpsProxyAgent = void 0;
102202
- var net = __importStar2(__require("net"));
102202
+ var net2 = __importStar2(__require("net"));
102203
102203
  var tls = __importStar2(__require("tls"));
102204
102204
  var assert_1 = __importDefault2(__require("assert"));
102205
102205
  var debug_1 = __importDefault2(require_src2());
@@ -102208,7 +102208,7 @@ var require_dist2 = __commonJS({
102208
102208
  var parse_proxy_response_1 = require_parse_proxy_response();
102209
102209
  var debug = (0, debug_1.default)("https-proxy-agent");
102210
102210
  var setServernameFromNonIpHost = (options) => {
102211
- if (options.servername === void 0 && options.host && !net.isIP(options.host)) {
102211
+ if (options.servername === void 0 && options.host && !net2.isIP(options.host)) {
102212
102212
  return {
102213
102213
  ...options,
102214
102214
  servername: options.host
@@ -102248,10 +102248,10 @@ var require_dist2 = __commonJS({
102248
102248
  socket = tls.connect(setServernameFromNonIpHost(this.connectOpts));
102249
102249
  } else {
102250
102250
  debug("Creating `net.Socket`: %o", this.connectOpts);
102251
- socket = net.connect(this.connectOpts);
102251
+ socket = net2.connect(this.connectOpts);
102252
102252
  }
102253
102253
  const headers = typeof this.proxyHeaders === "function" ? this.proxyHeaders() : { ...this.proxyHeaders };
102254
- const host = net.isIPv6(opts.host) ? `[${opts.host}]` : opts.host;
102254
+ const host = net2.isIPv6(opts.host) ? `[${opts.host}]` : opts.host;
102255
102255
  let payload = `CONNECT ${host}:${opts.port} HTTP/1.1\r
102256
102256
  `;
102257
102257
  if (proxy.username || proxy.password) {
@@ -102284,7 +102284,7 @@ var require_dist2 = __commonJS({
102284
102284
  return socket;
102285
102285
  }
102286
102286
  socket.destroy();
102287
- const fakeSocket = new net.Socket({ writable: false });
102287
+ const fakeSocket = new net2.Socket({ writable: false });
102288
102288
  fakeSocket.readable = true;
102289
102289
  req.once("socket", (s7) => {
102290
102290
  debug("Replaying proxy buffer for failed request");
@@ -102349,7 +102349,7 @@ var require_dist3 = __commonJS({
102349
102349
  };
102350
102350
  Object.defineProperty(exports2, "__esModule", { value: true });
102351
102351
  exports2.HttpProxyAgent = void 0;
102352
- var net = __importStar2(__require("net"));
102352
+ var net2 = __importStar2(__require("net"));
102353
102353
  var tls = __importStar2(__require("tls"));
102354
102354
  var debug_1 = __importDefault2(require_src2());
102355
102355
  var events_1 = __require("events");
@@ -102422,7 +102422,7 @@ var require_dist3 = __commonJS({
102422
102422
  socket = tls.connect(this.connectOpts);
102423
102423
  } else {
102424
102424
  debug("Creating `net.Socket`: %o", this.connectOpts);
102425
- socket = net.connect(this.connectOpts);
102425
+ socket = net2.connect(this.connectOpts);
102426
102426
  }
102427
102427
  await (0, events_1.once)(socket, "connect");
102428
102428
  return socket;
@@ -141301,7 +141301,7 @@ var require_connection = __commonJS({
141301
141301
  var _crypto = _interopRequireDefault(__require("crypto"));
141302
141302
  var _os = _interopRequireDefault(__require("os"));
141303
141303
  var tls = _interopRequireWildcard(__require("tls"));
141304
- var net = _interopRequireWildcard(__require("net"));
141304
+ var net2 = _interopRequireWildcard(__require("net"));
141305
141305
  var _dns = _interopRequireDefault(__require("dns"));
141306
141306
  var _constants = _interopRequireDefault(__require("constants"));
141307
141307
  var _stream = __require("stream");
@@ -142350,7 +142350,7 @@ var require_connection = __commonJS({
142350
142350
  async wrapWithTls(socket, signal) {
142351
142351
  signal.throwIfAborted();
142352
142352
  const secureContext = tls.createSecureContext(this.secureContextOptions);
142353
- const serverName = !net.isIP(this.config.server) ? this.config.server : "";
142353
+ const serverName = !net2.isIP(this.config.server) ? this.config.server : "";
142354
142354
  const encryptOptions = {
142355
142355
  host: this.config.server,
142356
142356
  socket,
@@ -145259,6 +145259,7 @@ __export(connections_exports, {
145259
145259
  prepareGelDB: () => prepareGelDB,
145260
145260
  preparePostgresDB: () => preparePostgresDB
145261
145261
  });
145262
+ import net from "net";
145262
145263
  function parseMssqlUrl(url) {
145263
145264
  return {
145264
145265
  user: url.username,
@@ -145272,7 +145273,7 @@ function parseMssqlUrl(url) {
145272
145273
  }
145273
145274
  };
145274
145275
  }
145275
- var normalisePGliteUrl, preparePostgresDB, prepareCockroach, prepareGelDB, parseSingleStoreCredentials, connectToSingleStore, parseMysqlCredentials, connectToMySQL, parseMssqlCredentials, connectToMsSQL, prepareSqliteParams, preparePGliteParams, connectToSQLite, connectToLibSQL;
145276
+ var ms, normalisePGliteUrl, preparePostgresDB, prepareCockroach, prepareGelDB, parseSingleStoreCredentials, connectToSingleStore, parseMysqlCredentials, connectToMySQL, parseMssqlCredentials, connectToMsSQL, prepareSqliteParams, preparePGliteParams, connectToSQLite, connectToLibSQL;
145276
145277
  var init_connections = __esm({
145277
145278
  "src/cli/connections.ts"() {
145278
145279
  "use strict";
@@ -145283,6 +145284,7 @@ var init_connections = __esm({
145283
145284
  init_when_json_met_bigint();
145284
145285
  init_utils3();
145285
145286
  init_outputs();
145287
+ ms = (a6, b6) => Number(b6 - a6) / 1e6;
145286
145288
  normalisePGliteUrl = (it) => {
145287
145289
  if (it.startsWith("file:")) {
145288
145290
  return it.substring(5);
@@ -145437,13 +145439,13 @@ var init_connections = __esm({
145437
145439
  return pg.types.getTypeParser(typeId, format2);
145438
145440
  }
145439
145441
  };
145440
- const client = "url" in credentials ? new pg.Pool({ connectionString: credentials.url, max: 1 }) : new pg.Pool({ ...credentials, ssl, max: 1 });
145441
- const db = drizzle({ client });
145442
+ const pool = "url" in credentials ? new pg.Pool({ connectionString: credentials.url, max: 1 }) : new pg.Pool({ ...credentials, ssl, max: 1 });
145443
+ const db = drizzle({ client: pool });
145442
145444
  const migrateFn = async (config) => {
145443
145445
  return migrate(db, config);
145444
145446
  };
145445
145447
  const query = async (sql, params) => {
145446
- const result2 = await client.query({
145448
+ const result2 = await pool.query({
145447
145449
  text: sql,
145448
145450
  values: params ?? [],
145449
145451
  types: types3
@@ -145453,7 +145455,7 @@ var init_connections = __esm({
145453
145455
  return result2.rows;
145454
145456
  };
145455
145457
  const proxy = async (params) => {
145456
- const result2 = await client.query({
145458
+ const result2 = await pool.query({
145457
145459
  text: params.sql,
145458
145460
  values: params.params,
145459
145461
  ...params.mode === "array" && { rowMode: "array" },
@@ -145465,7 +145467,7 @@ var init_connections = __esm({
145465
145467
  };
145466
145468
  const transactionProxy = async (queries) => {
145467
145469
  const results = [];
145468
- const tx = await client.connect();
145470
+ const tx = await pool.connect();
145469
145471
  try {
145470
145472
  await tx.query("BEGIN");
145471
145473
  for (const query2 of queries) {
@@ -145484,7 +145486,72 @@ var init_connections = __esm({
145484
145486
  }
145485
145487
  return results;
145486
145488
  };
145487
- return { packageName: "pg", query, proxy, transactionProxy, migrate: migrateFn };
145489
+ const benchmarkQuery = async (sql, params) => {
145490
+ const explainResult = await pool.query({
145491
+ text: `EXPLAIN ANALYZE ${sql}`,
145492
+ values: params ?? [],
145493
+ types: types3
145494
+ });
145495
+ const stringifiedResult = JSON.stringify(explainResult.rows);
145496
+ const planningMatch = stringifiedResult.match(/Planning Time:\s*([\d.]+)\s*ms/i);
145497
+ const executionMatch = stringifiedResult.match(/Execution Time:\s*([\d.]+)\s*ms/i);
145498
+ const planningTime = Number(planningMatch[1]);
145499
+ const executionTime = Number(executionMatch[1]);
145500
+ let startAt = 0n;
145501
+ let tcpConnectedAt = 0n;
145502
+ let tlsConnectedAt = null;
145503
+ let dbReadyAt = 0n;
145504
+ let querySentAt = 0n;
145505
+ let firstDataAt = 0n;
145506
+ let lastDataAt = 0n;
145507
+ let bytesReceived = 0;
145508
+ const client = "url" in credentials ? new pg.Client({ connectionString: credentials.url }) : new pg.Client({ ...credentials, ssl });
145509
+ client.connection.once("connect", () => {
145510
+ tcpConnectedAt = process.hrtime.bigint();
145511
+ });
145512
+ client.connection.prependOnceListener("sslconnect", () => {
145513
+ tlsConnectedAt = process.hrtime.bigint();
145514
+ });
145515
+ client.connection.prependOnceListener("readyForQuery", () => {
145516
+ dbReadyAt = process.hrtime.bigint();
145517
+ });
145518
+ client.connection.addListener("rowDescription", (data) => {
145519
+ if (firstDataAt === 0n) {
145520
+ firstDataAt = process.hrtime.bigint();
145521
+ }
145522
+ bytesReceived += data.length;
145523
+ });
145524
+ client.connection.addListener("dataRow", (data) => {
145525
+ bytesReceived += data.length;
145526
+ });
145527
+ client.connection.addListener("commandComplete", () => {
145528
+ lastDataAt = process.hrtime.bigint();
145529
+ });
145530
+ startAt = process.hrtime.bigint();
145531
+ await client.connect();
145532
+ querySentAt = process.hrtime.bigint();
145533
+ await client.query(sql, params);
145534
+ await client.end();
145535
+ return {
145536
+ tcpHandshake: ms(startAt, tcpConnectedAt),
145537
+ tlsHandshake: tlsConnectedAt ? ms(tcpConnectedAt, tlsConnectedAt) : null,
145538
+ dbHandshake: ms(tlsConnectedAt ?? tcpConnectedAt, dbReadyAt),
145539
+ planning: planningTime,
145540
+ execution: executionTime,
145541
+ dataDownload: ms(firstDataAt, lastDataAt) + ms(querySentAt, firstDataAt) - executionTime - planningTime,
145542
+ total: ms(startAt, lastDataAt),
145543
+ dataSize: bytesReceived
145544
+ };
145545
+ };
145546
+ const benchmarkProxy = async ({ sql, params }, repeats) => {
145547
+ const results = [];
145548
+ for (let i7 = 0; i7 < repeats; i7++) {
145549
+ const r7 = await benchmarkQuery(sql, params);
145550
+ results.push(r7);
145551
+ }
145552
+ return results;
145553
+ };
145554
+ return { packageName: "pg", query, proxy, transactionProxy, benchmarkProxy, migrate: migrateFn };
145488
145555
  }
145489
145556
  if (await checkPackage("postgres")) {
145490
145557
  console.log(
@@ -145747,6 +145814,7 @@ var init_connections = __esm({
145747
145814
  console.error(
145748
145815
  "To connect to Postgres database - please install either of 'pg', 'postgres', 'bun', '@neondatabase/serverless' or '@vercel/postgres' drivers"
145749
145816
  );
145817
+ console.warn("For the 'bun' driver, run your script using: bun --bun");
145750
145818
  process.exit(1);
145751
145819
  };
145752
145820
  prepareCockroach = async (credentials) => {
@@ -145978,7 +146046,6 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
145978
146046
  }
145979
146047
  return next();
145980
146048
  };
145981
- await connection.connect();
145982
146049
  const query = async (sql, params) => {
145983
146050
  const res = await connection.execute({
145984
146051
  sql,
@@ -146018,11 +146085,111 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
146018
146085
  }
146019
146086
  return results;
146020
146087
  };
146088
+ const benchmarkQuery = async (sql, params) => {
146089
+ const { createConnection: createConnection2 } = await import("mysql2");
146090
+ const explainResult = await connection.query({
146091
+ sql: `EXPLAIN ANALYZE ${sql}`,
146092
+ values: params ?? [],
146093
+ typeCast
146094
+ });
146095
+ const stringifiedResult = JSON.stringify(explainResult[0]);
146096
+ const timeMatch = stringifiedResult.match(
146097
+ /actual time=([0-9.eE+-]+)\.\.([0-9.eE+-]+)/
146098
+ );
146099
+ const lastRowTime = Number(timeMatch[2]);
146100
+ const executionTime = lastRowTime;
146101
+ let startAt = 0n;
146102
+ let tcpConnectedAt = 0n;
146103
+ let tlsConnectedAt = null;
146104
+ let querySentAt = 0n;
146105
+ let firstDataAt = 0n;
146106
+ let lastDataAt = 0n;
146107
+ let bytesReceived = 0;
146108
+ const createStream = ({ config }) => {
146109
+ let stream;
146110
+ if (config.socketPath) {
146111
+ stream = net.connect(config.socketPath);
146112
+ } else {
146113
+ stream = net.connect(config.port, config.host);
146114
+ }
146115
+ if (config.enableKeepAlive) {
146116
+ stream.on("connect", () => {
146117
+ stream.setKeepAlive(true, config.keepAliveInitialDelay);
146118
+ });
146119
+ }
146120
+ stream.setNoDelay(true);
146121
+ stream.once("connect", () => {
146122
+ tcpConnectedAt = process.hrtime.bigint();
146123
+ });
146124
+ return stream;
146125
+ };
146126
+ startAt = process.hrtime.bigint();
146127
+ const newConnection = result2.url ? createConnection2({
146128
+ // debug: true,
146129
+ uri: result2.url,
146130
+ stream: createStream
146131
+ }) : createConnection2({
146132
+ ...result2.credentials,
146133
+ stream: createStream
146134
+ });
146135
+ await new Promise((resolve2, reject) => {
146136
+ newConnection.connect((err2) => {
146137
+ tlsConnectedAt = process.hrtime.bigint();
146138
+ if (err2) {
146139
+ reject(err2);
146140
+ } else {
146141
+ resolve2();
146142
+ }
146143
+ });
146144
+ });
146145
+ querySentAt = process.hrtime.bigint();
146146
+ await new Promise((resolve2, reject) => {
146147
+ const query2 = newConnection.query({
146148
+ sql,
146149
+ values: params ?? [],
146150
+ typeCast
146151
+ // rowsAsArray: true,
146152
+ });
146153
+ query2.on("error", (err2) => {
146154
+ reject(err2);
146155
+ });
146156
+ query2.on("fields", (fields) => {
146157
+ if (firstDataAt === 0n) {
146158
+ firstDataAt = process.hrtime.bigint();
146159
+ }
146160
+ bytesReceived += fields[0]._buf.length;
146161
+ });
146162
+ query2.on("end", () => {
146163
+ lastDataAt = process.hrtime.bigint();
146164
+ resolve2();
146165
+ newConnection.end();
146166
+ });
146167
+ });
146168
+ return {
146169
+ tcpHandshake: ms(startAt, tcpConnectedAt),
146170
+ tlsHandshake: tlsConnectedAt ? ms(tcpConnectedAt, tlsConnectedAt) : null,
146171
+ dbHandshake: null,
146172
+ planning: null,
146173
+ execution: executionTime,
146174
+ dataDownload: ms(firstDataAt, lastDataAt) + ms(querySentAt, firstDataAt) - executionTime,
146175
+ total: ms(startAt, lastDataAt),
146176
+ dataSize: bytesReceived
146177
+ };
146178
+ };
146179
+ const benchmarkProxy = async ({ sql, params }, repeats) => {
146180
+ const results = [];
146181
+ for (let i7 = 0; i7 < repeats; i7++) {
146182
+ const r7 = await benchmarkQuery(sql, params);
146183
+ results.push(r7);
146184
+ }
146185
+ return results;
146186
+ };
146021
146187
  return {
146022
146188
  db: { query },
146023
146189
  packageName: "mysql2",
146024
146190
  proxy,
146025
146191
  transactionProxy,
146192
+ benchmarkProxy,
146026
146193
  database: result2.database,
146027
146194
  migrate: migrateFn
146028
146195
  };
@@ -146128,6 +146295,7 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
146128
146295
  console.error(
146129
146296
  "To connect to MySQL database - please install either of 'mysql2', 'bun' or '@planetscale/database' drivers"
146130
146297
  );
146298
+ console.warn("For the 'bun' driver, run your script using: bun --bun");
146131
146299
  process.exit(1);
146132
146300
  };
146133
146301
  parseMssqlCredentials = (credentials) => {
@@ -146576,6 +146744,7 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
146576
146744
  console.log(
146577
146745
  "Please install either 'better-sqlite3', 'bun', '@libsql/client' or '@tursodatabase/database' for Drizzle Kit to connect to SQLite databases"
146578
146746
  );
146747
+ console.warn("For the 'bun' driver, run your script using: bun --bun");
146579
146748
  process.exit(1);
146580
146749
  };
146581
146750
  connectToLibSQL = async (credentials) => {
@@ -148574,8 +148743,8 @@ ${sql}
148574
148743
  `;
148575
148744
  return content;
148576
148745
  };
148577
- prepareSnapshotFolderName = (ms) => {
148578
- const now = ms ? new Date(ms) : /* @__PURE__ */ new Date();
148746
+ prepareSnapshotFolderName = (ms2) => {
148747
+ const now = ms2 ? new Date(ms2) : /* @__PURE__ */ new Date();
148579
148748
  return `${now.getFullYear()}${two(now.getUTCMonth() + 1)}${two(
148580
148749
  now.getUTCDate()
148581
148750
  )}${two(now.getUTCHours())}${two(now.getUTCMinutes())}${two(
@@ -152090,7 +152259,7 @@ import { getTableConfig as singlestoreTableConfig, SingleStoreTable } from "driz
152090
152259
  import { getTableConfig as sqliteTableConfig, SQLiteTable } from "drizzle-orm/sqlite-core";
152091
152260
  import fs10 from "fs";
152092
152261
  import { createServer } from "https";
152093
- var preparePgSchema, prepareMySqlSchema, prepareMsSqlSchema, prepareSQLiteSchema, prepareSingleStoreSchema, getCustomDefaults, drizzleForPostgres, drizzleForMySQL, drizzleForSQLite, drizzleForLibSQL, drizzleForSingleStore, extractRelations, init2, proxySchema, transactionProxySchema, defaultsSchema, schema5, jsonStringify, prepareServer;
152262
+ var preparePgSchema, prepareMySqlSchema, prepareMsSqlSchema, prepareSQLiteSchema, prepareSingleStoreSchema, getCustomDefaults, drizzleForPostgres, drizzleForMySQL, drizzleForSQLite, drizzleForLibSQL, drizzleForSingleStore, extractRelations, init2, proxySchema, transactionProxySchema, benchmarkProxySchema, defaultsSchema, schema5, jsonStringify, prepareServer;
152094
152263
  var init_studio = __esm({
152095
152264
  "src/cli/commands/studio.ts"() {
152096
152265
  "use strict";
@@ -152304,6 +152473,7 @@ var init_studio = __esm({
152304
152473
  packageName: db.packageName,
152305
152474
  proxy: db.proxy,
152306
152475
  transactionProxy: db.transactionProxy,
152476
+ benchmarkProxy: db.benchmarkProxy,
152307
152477
  customDefaults,
152308
152478
  schema: pgSchema2,
152309
152479
  relations: relations2,
@@ -152313,7 +152483,7 @@ var init_studio = __esm({
152313
152483
  };
152314
152484
  drizzleForMySQL = async (credentials, mysqlSchema, relations2, schemaFiles, casing2) => {
152315
152485
  const { connectToMySQL: connectToMySQL2 } = await Promise.resolve().then(() => (init_connections(), connections_exports));
152316
- const { proxy, transactionProxy, database, packageName } = await connectToMySQL2(credentials);
152486
+ const { proxy, transactionProxy, benchmarkProxy, database, packageName } = await connectToMySQL2(credentials);
152317
152487
  const customDefaults = getCustomDefaults(mysqlSchema, casing2);
152318
152488
  let dbUrl;
152319
152489
  if ("url" in credentials) {
@@ -152329,6 +152499,7 @@ var init_studio = __esm({
152329
152499
  databaseName: database,
152330
152500
  proxy,
152331
152501
  transactionProxy,
152502
+ benchmarkProxy,
152332
152503
  customDefaults,
152333
152504
  schema: mysqlSchema,
152334
152505
  relations: relations2,
@@ -152498,6 +152669,23 @@ var init_studio = __esm({
152498
152669
  ]).optional()
152499
152670
  }).array()
152500
152671
  });
152672
+ benchmarkProxySchema = external_exports.object({
152673
+ type: external_exports.literal("bproxy"),
152674
+ data: external_exports.object({
152675
+ query: external_exports.object({
152676
+ sql: external_exports.string(),
152677
+ params: external_exports.array(external_exports.any()).optional(),
152678
+ method: external_exports.union([
152679
+ external_exports.literal("values"),
152680
+ external_exports.literal("get"),
152681
+ external_exports.literal("all"),
152682
+ external_exports.literal("run"),
152683
+ external_exports.literal("execute")
152684
+ ]).optional()
152685
+ }),
152686
+ repeats: external_exports.number().min(1).optional()
152687
+ })
152688
+ });
152501
152689
  defaultsSchema = external_exports.object({
152502
152690
  type: external_exports.literal("defaults"),
152503
152691
  data: external_exports.array(
@@ -152512,6 +152700,7 @@ var init_studio = __esm({
152512
152700
  init2,
152513
152701
  proxySchema,
152514
152702
  transactionProxySchema,
152703
+ benchmarkProxySchema,
152515
152704
  defaultsSchema
152516
152705
  ]);
152517
152706
  jsonStringify = (data) => {
@@ -152534,6 +152723,7 @@ var init_studio = __esm({
152534
152723
  databaseName,
152535
152724
  proxy,
152536
152725
  transactionProxy,
152726
+ benchmarkProxy,
152537
152727
  customDefaults,
152538
152728
  schema: drizzleSchema,
152539
152729
  relations: relations2,
@@ -152597,7 +152787,7 @@ var init_studio = __esm({
152597
152787
  console.warn("Error message:", error3.message);
152598
152788
  }
152599
152789
  return c6.json({
152600
- version: "6.2",
152790
+ version: "6.3",
152601
152791
  dialect: dialect6,
152602
152792
  driver: driver2,
152603
152793
  packageName,
@@ -152635,6 +152825,21 @@ var init_studio = __esm({
152635
152825
  }
152636
152826
  );
152637
152827
  }
152828
+ if (type === "bproxy") {
152829
+ if (!benchmarkProxy) {
152830
+ throw new Error("Benchmark proxy is not configured for this database.");
152831
+ }
152832
+ const result2 = await benchmarkProxy(body.data.query, body.data.repeats || 1);
152833
+ const res = jsonStringify(result2);
152834
+ return c6.body(
152835
+ res,
152836
+ {
152837
+ headers: {
152838
+ "Content-Type": "application/json"
152839
+ }
152840
+ }
152841
+ );
152842
+ }
152638
152843
  if (type === "defaults") {
152639
152844
  const columns = body.data;
152640
152845
  const result2 = columns.map((column8) => {