drizzle-kit 1.0.0-beta.2-86f844e → 1.0.0-beta.2-1be5069

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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,117 @@ 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 (client, 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
+ let planningTime = Number(planningMatch[1]);
145499
+ let executionTime = Number(executionMatch[1]);
145500
+ let querySentAt = 0n;
145501
+ let firstDataAt = 0n;
145502
+ let lastDataAt = 0n;
145503
+ let lastRowParsedAt = 0n;
145504
+ let queryCompletedAt = 0n;
145505
+ let bytesReceived = 0;
145506
+ let rowCount = 0;
145507
+ let parseTime = 0;
145508
+ const rowDescriptionListener = (data) => {
145509
+ if (firstDataAt === 0n) {
145510
+ firstDataAt = process.hrtime.bigint();
145511
+ }
145512
+ bytesReceived += data.length;
145513
+ };
145514
+ const originalRowListener = client.connection.listeners("dataRow")[0];
145515
+ const wrappedRowListener = (data) => {
145516
+ rowCount += 1;
145517
+ const start = process.hrtime.bigint();
145518
+ lastDataAt = start;
145519
+ originalRowListener.apply(client.connection, [data]);
145520
+ const end2 = process.hrtime.bigint();
145521
+ lastRowParsedAt = end2;
145522
+ parseTime += ms(start, end2);
145523
+ bytesReceived += data.length;
145524
+ };
145525
+ client.connection.removeAllListeners("dataRow");
145526
+ client.connection.addListener("dataRow", wrappedRowListener);
145527
+ client.connection.prependListener("rowDescription", rowDescriptionListener);
145528
+ querySentAt = process.hrtime.bigint();
145529
+ await client.query({
145530
+ text: sql,
145531
+ values: params,
145532
+ types: types3
145533
+ });
145534
+ queryCompletedAt = process.hrtime.bigint();
145535
+ client.connection.removeListener("rowDescription", rowDescriptionListener);
145536
+ client.connection.removeAllListeners("dataRow");
145537
+ client.connection.addListener("dataRow", originalRowListener);
145538
+ let querySentTime = ms(querySentAt, firstDataAt) - executionTime - planningTime;
145539
+ if (querySentTime < 0) {
145540
+ const percent = 0.1;
145541
+ const overflow = -querySentTime;
145542
+ const keepForSent = overflow * percent;
145543
+ const adjustedOverflow = overflow * (1 + percent);
145544
+ const total2 = planningTime + executionTime;
145545
+ const ratioPlanning = planningTime / total2;
145546
+ const ratioExecution = executionTime / total2;
145547
+ planningTime -= adjustedOverflow * ratioPlanning;
145548
+ executionTime -= adjustedOverflow * ratioExecution;
145549
+ querySentTime = keepForSent;
145550
+ }
145551
+ const networkLatencyBefore = querySentTime / 2;
145552
+ const networkLatencyAfter = querySentTime / 2;
145553
+ const downloadTime = ms(firstDataAt, lastDataAt) - (rowCount > 1 ? parseTime - parseTime / rowCount : 0);
145554
+ const total = ms(querySentAt, queryCompletedAt);
145555
+ const calculatedTotal = networkLatencyBefore + planningTime + executionTime + networkLatencyAfter + downloadTime + parseTime + ms(lastRowParsedAt, queryCompletedAt);
145556
+ const errorMargin = Math.abs(total - calculatedTotal);
145557
+ return {
145558
+ networkLatencyBefore,
145559
+ planning: planningTime,
145560
+ execution: executionTime,
145561
+ networkLatencyAfter,
145562
+ dataDownload: downloadTime,
145563
+ dataParse: parseTime,
145564
+ total,
145565
+ errorMargin,
145566
+ dataSize: bytesReceived
145567
+ };
145568
+ };
145569
+ const benchmarkProxy = async ({ sql, params }, repeats) => {
145570
+ let startAt = 0n;
145571
+ let tcpConnectedAt = 0n;
145572
+ let tlsConnectedAt = null;
145573
+ let dbReadyAt = 0n;
145574
+ const client = "url" in credentials ? new pg.Client({ connectionString: credentials.url }) : new pg.Client({ ...credentials, ssl });
145575
+ client.connection.once("connect", () => {
145576
+ tcpConnectedAt = process.hrtime.bigint();
145577
+ });
145578
+ client.connection.prependOnceListener("sslconnect", () => {
145579
+ tlsConnectedAt = process.hrtime.bigint();
145580
+ });
145581
+ client.connection.prependOnceListener("readyForQuery", () => {
145582
+ dbReadyAt = process.hrtime.bigint();
145583
+ });
145584
+ startAt = process.hrtime.bigint();
145585
+ await client.connect();
145586
+ const results = [];
145587
+ for (let i7 = 0; i7 < repeats; i7++) {
145588
+ const r7 = await benchmarkQuery(client, sql, params);
145589
+ results.push(r7);
145590
+ }
145591
+ await client.end();
145592
+ return {
145593
+ tcpHandshake: ms(startAt, tcpConnectedAt),
145594
+ tlsHandshake: tlsConnectedAt ? ms(tcpConnectedAt, tlsConnectedAt) : null,
145595
+ dbHandshake: ms(tlsConnectedAt ?? tcpConnectedAt, dbReadyAt),
145596
+ queries: results
145597
+ };
145598
+ };
145599
+ return { packageName: "pg", query, proxy, transactionProxy, benchmarkProxy, migrate: migrateFn };
145488
145600
  }
145489
145601
  if (await checkPackage("postgres")) {
145490
145602
  console.log(
@@ -145979,7 +146091,6 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
145979
146091
  }
145980
146092
  return next();
145981
146093
  };
145982
- await connection.connect();
145983
146094
  const query = async (sql, params) => {
145984
146095
  const res = await connection.execute({
145985
146096
  sql,
@@ -146019,11 +146130,144 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
146019
146130
  }
146020
146131
  return results;
146021
146132
  };
146133
+ const benchmarkQuery = async (newConnection, sql, params) => {
146134
+ const explainResult = await connection.query({
146135
+ sql: `EXPLAIN ANALYZE ${sql}`,
146136
+ values: params ?? [],
146137
+ typeCast
146138
+ });
146139
+ const stringifiedResult = JSON.stringify(explainResult[0]);
146140
+ const timeMatch = stringifiedResult.match(
146141
+ /actual time=([0-9.eE+-]+)\.\.([0-9.eE+-]+)/
146142
+ );
146143
+ const lastRowTime = Number(timeMatch[2]);
146144
+ const executionTime = lastRowTime;
146145
+ let querySentAt = 0n;
146146
+ let firstDataAt = 0n;
146147
+ let lastDataAt = 0n;
146148
+ let lastRowParsedAt = 0n;
146149
+ let queryCompletedAt = 0n;
146150
+ let bytesReceived = 0;
146151
+ let rowCount = 0;
146152
+ let parseTime = 0;
146153
+ querySentAt = process.hrtime.bigint();
146154
+ await new Promise((resolve2, reject) => {
146155
+ const query2 = newConnection.query({
146156
+ sql,
146157
+ values: params ?? [],
146158
+ typeCast
146159
+ });
146160
+ const originalRowHandler = query2.row;
146161
+ let packets = 0;
146162
+ const wrappedRowListener = (packet, connection2) => {
146163
+ packets += 1;
146164
+ if (firstDataAt === 0n) {
146165
+ firstDataAt = process.hrtime.bigint();
146166
+ bytesReceived += packet.start;
146167
+ }
146168
+ const start = process.hrtime.bigint();
146169
+ lastDataAt = start;
146170
+ const res = originalRowHandler.apply(query2, [packet, connection2]);
146171
+ const end2 = process.hrtime.bigint();
146172
+ lastRowParsedAt = end2;
146173
+ parseTime += ms(start, end2);
146174
+ bytesReceived += packet.length();
146175
+ if (!res || packet.isEOF()) {
146176
+ return res;
146177
+ }
146178
+ return wrappedRowListener;
146179
+ };
146180
+ query2.row = wrappedRowListener;
146181
+ query2.on("result", () => {
146182
+ rowCount += 1;
146183
+ });
146184
+ query2.on("error", (err2) => {
146185
+ reject(err2);
146186
+ });
146187
+ query2.on("end", () => {
146188
+ resolve2();
146189
+ });
146190
+ });
146191
+ queryCompletedAt = process.hrtime.bigint();
146192
+ const querySentTime = ms(querySentAt, firstDataAt) - executionTime;
146193
+ const networkLatencyBefore = querySentTime / 2;
146194
+ const networkLatencyAfter = querySentTime / 2;
146195
+ const downloadTime = ms(firstDataAt, lastDataAt) - (rowCount > 1 ? parseTime - parseTime / rowCount : 0);
146196
+ const total = ms(querySentAt, queryCompletedAt);
146197
+ const calculatedTotal = networkLatencyBefore + executionTime + networkLatencyAfter + downloadTime + parseTime + ms(lastRowParsedAt, queryCompletedAt);
146198
+ const errorMargin = Math.abs(total - calculatedTotal);
146199
+ return {
146200
+ networkLatencyBefore,
146201
+ planning: null,
146202
+ execution: executionTime,
146203
+ networkLatencyAfter,
146204
+ dataDownload: downloadTime,
146205
+ dataParse: parseTime,
146206
+ total,
146207
+ errorMargin,
146208
+ dataSize: bytesReceived
146209
+ };
146210
+ };
146211
+ const benchmarkProxy = async ({ sql, params }, repeats) => {
146212
+ const { createConnection: createConnection2 } = await import("mysql2");
146213
+ let startAt = 0n;
146214
+ let tcpConnectedAt = 0n;
146215
+ let tlsConnectedAt = null;
146216
+ const createStream = ({ config }) => {
146217
+ let stream;
146218
+ if (config.socketPath) {
146219
+ stream = net.connect(config.socketPath);
146220
+ } else {
146221
+ stream = net.connect(config.port, config.host);
146222
+ }
146223
+ if (config.enableKeepAlive) {
146224
+ stream.on("connect", () => {
146225
+ stream.setKeepAlive(true, config.keepAliveInitialDelay);
146226
+ });
146227
+ }
146228
+ stream.setNoDelay(true);
146229
+ stream.once("connect", () => {
146230
+ tcpConnectedAt = process.hrtime.bigint();
146231
+ });
146232
+ return stream;
146233
+ };
146234
+ startAt = process.hrtime.bigint();
146235
+ const connection2 = result2.url ? createConnection2({
146236
+ uri: result2.url,
146237
+ stream: createStream
146238
+ }) : createConnection2({
146239
+ ...result2.credentials,
146240
+ stream: createStream
146241
+ });
146242
+ await new Promise((resolve2, reject) => {
146243
+ connection2.connect((err2) => {
146244
+ tlsConnectedAt = process.hrtime.bigint();
146245
+ if (err2) {
146246
+ reject(err2);
146247
+ } else {
146248
+ resolve2();
146249
+ }
146250
+ });
146251
+ });
146252
+ const results = [];
146253
+ for (let i7 = 0; i7 < repeats; i7++) {
146254
+ const r7 = await benchmarkQuery(connection2, sql, params);
146255
+ results.push(r7);
146256
+ }
146257
+ connection2.end();
146258
+ return {
146259
+ tcpHandshake: ms(startAt, tcpConnectedAt),
146260
+ tlsHandshake: tlsConnectedAt ? ms(tcpConnectedAt, tlsConnectedAt) : null,
146261
+ dbHandshake: null,
146262
+ queries: results
146263
+ };
146264
+ };
146022
146265
  return {
146023
146266
  db: { query },
146024
146267
  packageName: "mysql2",
146025
146268
  proxy,
146026
146269
  transactionProxy,
146270
+ benchmarkProxy,
146027
146271
  database: result2.database,
146028
146272
  migrate: migrateFn
146029
146273
  };
@@ -148577,8 +148821,8 @@ ${sql}
148577
148821
  `;
148578
148822
  return content;
148579
148823
  };
148580
- prepareSnapshotFolderName = (ms) => {
148581
- const now = ms ? new Date(ms) : /* @__PURE__ */ new Date();
148824
+ prepareSnapshotFolderName = (ms2) => {
148825
+ const now = ms2 ? new Date(ms2) : /* @__PURE__ */ new Date();
148582
148826
  return `${now.getFullYear()}${two(now.getUTCMonth() + 1)}${two(
148583
148827
  now.getUTCDate()
148584
148828
  )}${two(now.getUTCHours())}${two(now.getUTCMinutes())}${two(
@@ -152093,7 +152337,7 @@ import { getTableConfig as singlestoreTableConfig, SingleStoreTable } from "driz
152093
152337
  import { getTableConfig as sqliteTableConfig, SQLiteTable } from "drizzle-orm/sqlite-core";
152094
152338
  import fs10 from "fs";
152095
152339
  import { createServer } from "https";
152096
- var preparePgSchema, prepareMySqlSchema, prepareMsSqlSchema, prepareSQLiteSchema, prepareSingleStoreSchema, getCustomDefaults, drizzleForPostgres, drizzleForMySQL, drizzleForSQLite, drizzleForLibSQL, drizzleForSingleStore, extractRelations, init2, proxySchema, transactionProxySchema, defaultsSchema, schema5, jsonStringify, prepareServer;
152340
+ var preparePgSchema, prepareMySqlSchema, prepareMsSqlSchema, prepareSQLiteSchema, prepareSingleStoreSchema, getCustomDefaults, drizzleForPostgres, drizzleForMySQL, drizzleForSQLite, drizzleForLibSQL, drizzleForSingleStore, extractRelations, init2, proxySchema, transactionProxySchema, benchmarkProxySchema, defaultsSchema, schema5, jsonStringify, prepareServer;
152097
152341
  var init_studio = __esm({
152098
152342
  "src/cli/commands/studio.ts"() {
152099
152343
  "use strict";
@@ -152307,6 +152551,7 @@ var init_studio = __esm({
152307
152551
  packageName: db.packageName,
152308
152552
  proxy: db.proxy,
152309
152553
  transactionProxy: db.transactionProxy,
152554
+ benchmarkProxy: db.benchmarkProxy,
152310
152555
  customDefaults,
152311
152556
  schema: pgSchema2,
152312
152557
  relations: relations2,
@@ -152316,7 +152561,7 @@ var init_studio = __esm({
152316
152561
  };
152317
152562
  drizzleForMySQL = async (credentials, mysqlSchema, relations2, schemaFiles, casing2) => {
152318
152563
  const { connectToMySQL: connectToMySQL2 } = await Promise.resolve().then(() => (init_connections(), connections_exports));
152319
- const { proxy, transactionProxy, database, packageName } = await connectToMySQL2(credentials);
152564
+ const { proxy, transactionProxy, benchmarkProxy, database, packageName } = await connectToMySQL2(credentials);
152320
152565
  const customDefaults = getCustomDefaults(mysqlSchema, casing2);
152321
152566
  let dbUrl;
152322
152567
  if ("url" in credentials) {
@@ -152332,6 +152577,7 @@ var init_studio = __esm({
152332
152577
  databaseName: database,
152333
152578
  proxy,
152334
152579
  transactionProxy,
152580
+ benchmarkProxy,
152335
152581
  customDefaults,
152336
152582
  schema: mysqlSchema,
152337
152583
  relations: relations2,
@@ -152501,6 +152747,23 @@ var init_studio = __esm({
152501
152747
  ]).optional()
152502
152748
  }).array()
152503
152749
  });
152750
+ benchmarkProxySchema = external_exports.object({
152751
+ type: external_exports.literal("bproxy"),
152752
+ data: external_exports.object({
152753
+ query: external_exports.object({
152754
+ sql: external_exports.string(),
152755
+ params: external_exports.array(external_exports.any()).optional(),
152756
+ method: external_exports.union([
152757
+ external_exports.literal("values"),
152758
+ external_exports.literal("get"),
152759
+ external_exports.literal("all"),
152760
+ external_exports.literal("run"),
152761
+ external_exports.literal("execute")
152762
+ ]).optional()
152763
+ }),
152764
+ repeats: external_exports.number().min(1).optional()
152765
+ })
152766
+ });
152504
152767
  defaultsSchema = external_exports.object({
152505
152768
  type: external_exports.literal("defaults"),
152506
152769
  data: external_exports.array(
@@ -152515,6 +152778,7 @@ var init_studio = __esm({
152515
152778
  init2,
152516
152779
  proxySchema,
152517
152780
  transactionProxySchema,
152781
+ benchmarkProxySchema,
152518
152782
  defaultsSchema
152519
152783
  ]);
152520
152784
  jsonStringify = (data) => {
@@ -152537,6 +152801,7 @@ var init_studio = __esm({
152537
152801
  databaseName,
152538
152802
  proxy,
152539
152803
  transactionProxy,
152804
+ benchmarkProxy,
152540
152805
  customDefaults,
152541
152806
  schema: drizzleSchema,
152542
152807
  relations: relations2,
@@ -152600,7 +152865,7 @@ var init_studio = __esm({
152600
152865
  console.warn("Error message:", error3.message);
152601
152866
  }
152602
152867
  return c6.json({
152603
- version: "6.2",
152868
+ version: "6.3",
152604
152869
  dialect: dialect6,
152605
152870
  driver: driver2,
152606
152871
  packageName,
@@ -152638,6 +152903,21 @@ var init_studio = __esm({
152638
152903
  }
152639
152904
  );
152640
152905
  }
152906
+ if (type === "bproxy") {
152907
+ if (!benchmarkProxy) {
152908
+ throw new Error("Benchmark proxy is not configured for this database.");
152909
+ }
152910
+ const result2 = await benchmarkProxy(body.data.query, body.data.repeats || 1);
152911
+ const res = jsonStringify(result2);
152912
+ return c6.body(
152913
+ res,
152914
+ {
152915
+ headers: {
152916
+ "Content-Type": "application/json"
152917
+ }
152918
+ }
152919
+ );
152920
+ }
152641
152921
  if (type === "defaults") {
152642
152922
  const columns = body.data;
152643
152923
  const result2 = columns.map((column8) => {