drizzle-kit 1.0.0-beta.2-09cddcb → 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.js CHANGED
@@ -34395,7 +34395,7 @@ var require_websocket = __commonJS({
34395
34395
  var EventEmitter = require("events");
34396
34396
  var https2 = require("https");
34397
34397
  var http3 = require("http");
34398
- var net = require("net");
34398
+ var net2 = require("net");
34399
34399
  var tls = require("tls");
34400
34400
  var { randomBytes, createHash: createHash5 } = require("crypto");
34401
34401
  var { Duplex, Readable: Readable6 } = require("stream");
@@ -35126,12 +35126,12 @@ var require_websocket = __commonJS({
35126
35126
  }
35127
35127
  function netConnect(options) {
35128
35128
  options.path = options.socketPath;
35129
- return net.connect(options);
35129
+ return net2.connect(options);
35130
35130
  }
35131
35131
  function tlsConnect(options) {
35132
35132
  options.path = void 0;
35133
35133
  if (!options.servername && options.servername !== "") {
35134
- options.servername = net.isIP(options.host) ? "" : options.host;
35134
+ options.servername = net2.isIP(options.host) ? "" : options.host;
35135
35135
  }
35136
35136
  return tls.connect(options);
35137
35137
  }
@@ -39450,7 +39450,7 @@ var init_timing = __esm({
39450
39450
  "../node_modules/.pnpm/@smithy+node-http-handler@4.4.5/node_modules/@smithy/node-http-handler/dist-es/timing.js"() {
39451
39451
  "use strict";
39452
39452
  timing = {
39453
- setTimeout: (cb, ms) => setTimeout(cb, ms),
39453
+ setTimeout: (cb, ms2) => setTimeout(cb, ms2),
39454
39454
  clearTimeout: (timeoutId) => clearTimeout(timeoutId)
39455
39455
  };
39456
39456
  }
@@ -41338,13 +41338,13 @@ var init_schema_date_utils = __esm({
41338
41338
  if (!matches) {
41339
41339
  throw new TypeError(`Invalid RFC3339 timestamp format ${value}`);
41340
41340
  }
41341
- const [, yearStr, monthStr, dayStr, hours, minutes, seconds, , ms, offsetStr] = matches;
41341
+ const [, yearStr, monthStr, dayStr, hours, minutes, seconds, , ms2, offsetStr] = matches;
41342
41342
  range(monthStr, 1, 12);
41343
41343
  range(dayStr, 1, 31);
41344
41344
  range(hours, 0, 23);
41345
41345
  range(minutes, 0, 59);
41346
41346
  range(seconds, 0, 60);
41347
- 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));
41347
+ 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));
41348
41348
  date2.setUTCFullYear(Number(yearStr));
41349
41349
  if (offsetStr.toUpperCase() != "Z") {
41350
41350
  const [, sign2, offsetH, offsetM] = /([+-])(\d\d):(\d\d)/.exec(offsetStr) || [void 0, "+", 0, 0];
@@ -61358,8 +61358,8 @@ var require_datetime2 = __commonJS({
61358
61358
  if (!(object instanceof Date)) {
61359
61359
  throw new errors_1.InvalidArgumentError(`a Date instance was expected, got "${object}"`);
61360
61360
  }
61361
- const ms = object.getTime() - TIMESHIFT;
61362
- const us = ms * 1e3;
61361
+ const ms2 = object.getTime() - TIMESHIFT;
61362
+ const us = ms2 * 1e3;
61363
61363
  buf.writeInt32(8);
61364
61364
  buf.writeInt64(us);
61365
61365
  }
@@ -61369,12 +61369,12 @@ var require_datetime2 = __commonJS({
61369
61369
  return ctx.postDecode(this, us2 + BI_TIMESHIFT_US);
61370
61370
  }
61371
61371
  const us = Number(buf.readBigInt64());
61372
- let ms = Math.round(us / 1e3);
61373
- if (Math.abs(us % 1e3) === 500 && Math.abs(ms) % 2 === 1) {
61374
- ms -= 1;
61372
+ let ms2 = Math.round(us / 1e3);
61373
+ if (Math.abs(us % 1e3) === 500 && Math.abs(ms2) % 2 === 1) {
61374
+ ms2 -= 1;
61375
61375
  }
61376
- ms += TIMESHIFT;
61377
- return new Date(ms);
61376
+ ms2 += TIMESHIFT;
61377
+ return new Date(ms2);
61378
61378
  }
61379
61379
  };
61380
61380
  exports2.DateTimeCodec = DateTimeCodec;
@@ -61395,8 +61395,8 @@ var require_datetime2 = __commonJS({
61395
61395
  if (!(object instanceof datetime_1.LocalDateTime)) {
61396
61396
  throw new errors_1.InvalidArgumentError(`a LocalDateTime instance was expected, got "${object}"`);
61397
61397
  }
61398
- const ms = BigInt(datetime_1.localDateInstances.get(object).getTime() - TIMESHIFT);
61399
- let us = ms * 1000n + BigInt(object.hour * 36e8 + object.minute * 6e7 + object.second * 1e6 + object.millisecond * 1e3 + object.microsecond);
61398
+ const ms2 = BigInt(datetime_1.localDateInstances.get(object).getTime() - TIMESHIFT);
61399
+ let us = ms2 * 1000n + BigInt(object.hour * 36e8 + object.minute * 6e7 + object.second * 1e6 + object.millisecond * 1e3 + object.microsecond);
61400
61400
  if (object.nanosecond === 500 && Math.abs(object.microsecond) % 2 === 1 || object.nanosecond > 500) {
61401
61401
  us += 1n;
61402
61402
  }
@@ -61410,13 +61410,13 @@ var require_datetime2 = __commonJS({
61410
61410
  }
61411
61411
  const bi_ms = bi_us / 1000n;
61412
61412
  let us = Number(bi_us - bi_ms * 1000n);
61413
- let ms = Number(bi_ms);
61413
+ let ms2 = Number(bi_ms);
61414
61414
  if (us < 0) {
61415
61415
  us += 1e3;
61416
- ms -= 1;
61416
+ ms2 -= 1;
61417
61417
  }
61418
- ms += TIMESHIFT;
61419
- const date2 = new Date(ms);
61418
+ ms2 += TIMESHIFT;
61419
+ const date2 = new Date(ms2);
61420
61420
  return new datetime_1.LocalDateTime(date2.getUTCFullYear(), date2.getUTCMonth() + 1, date2.getUTCDate(), date2.getUTCHours(), date2.getUTCMinutes(), date2.getUTCSeconds(), date2.getUTCMilliseconds(), us);
61421
61421
  }
61422
61422
  };
@@ -61478,13 +61478,13 @@ var require_datetime2 = __commonJS({
61478
61478
  }
61479
61479
  let us = Number(bius);
61480
61480
  let seconds = Math.floor(us / 1e6);
61481
- const ms = Math.floor(us % 1e6 / 1e3);
61482
- us = us % 1e6 - ms * 1e3;
61481
+ const ms2 = Math.floor(us % 1e6 / 1e3);
61482
+ us = us % 1e6 - ms2 * 1e3;
61483
61483
  let minutes = Math.floor(seconds / 60);
61484
61484
  seconds = Math.floor(seconds % 60);
61485
61485
  const hours = Math.floor(minutes / 60);
61486
61486
  minutes = Math.floor(minutes % 60);
61487
- return new datetime_1.LocalTime(hours, minutes, seconds, ms, us);
61487
+ return new datetime_1.LocalTime(hours, minutes, seconds, ms2, us);
61488
61488
  }
61489
61489
  };
61490
61490
  exports2.LocalTimeCodec = LocalTimeCodec;
@@ -61561,14 +61561,14 @@ var require_datetime2 = __commonJS({
61561
61561
  const biMillion = 1000000n;
61562
61562
  const biSeconds = bius / biMillion;
61563
61563
  let us = Number(bius - biSeconds * biMillion);
61564
- const ms = Math.floor(us / 1e3);
61564
+ const ms2 = Math.floor(us / 1e3);
61565
61565
  us = us % 1e3;
61566
61566
  let seconds = Number(biSeconds);
61567
61567
  let minutes = Math.floor(seconds / 60);
61568
61568
  seconds = Math.floor(seconds % 60);
61569
61569
  const hours = Math.floor(minutes / 60);
61570
61570
  minutes = Math.floor(minutes % 60);
61571
- return new datetime_1.Duration(0, 0, 0, 0, hours * sign2, minutes * sign2, seconds * sign2, ms * sign2, us * sign2);
61571
+ return new datetime_1.Duration(0, 0, 0, 0, hours * sign2, minutes * sign2, seconds * sign2, ms2 * sign2, us * sign2);
61572
61572
  }
61573
61573
  };
61574
61574
  exports2.DurationCodec = DurationCodec;
@@ -61614,7 +61614,7 @@ var require_datetime2 = __commonJS({
61614
61614
  const million = BigInt(1e6);
61615
61615
  const biSeconds = bius / million;
61616
61616
  let us = Number(bius - biSeconds * million);
61617
- const ms = Math.trunc(us / 1e3);
61617
+ const ms2 = Math.trunc(us / 1e3);
61618
61618
  us = us % 1e3;
61619
61619
  let seconds = Number(biSeconds);
61620
61620
  let minutes = Math.trunc(seconds / 60);
@@ -61625,7 +61625,7 @@ var require_datetime2 = __commonJS({
61625
61625
  days = Math.trunc(days % 7);
61626
61626
  const years = Math.trunc(months2 / 12);
61627
61627
  months2 = Math.trunc(months2 % 12);
61628
- return new datetime_1.RelativeDuration(years, months2, weeks, days, hours * sign2, minutes * sign2, seconds * sign2, ms * sign2, us * sign2);
61628
+ return new datetime_1.RelativeDuration(years, months2, weeks, days, hours * sign2, minutes * sign2, seconds * sign2, ms2 * sign2, us * sign2);
61629
61629
  }
61630
61630
  };
61631
61631
  exports2.RelativeDurationCodec = RelativeDurationCodec;
@@ -71789,41 +71789,41 @@ var require_ms = __commonJS({
71789
71789
  return void 0;
71790
71790
  }
71791
71791
  }
71792
- function fmtShort(ms) {
71793
- var msAbs = Math.abs(ms);
71792
+ function fmtShort(ms2) {
71793
+ var msAbs = Math.abs(ms2);
71794
71794
  if (msAbs >= d6) {
71795
- return Math.round(ms / d6) + "d";
71795
+ return Math.round(ms2 / d6) + "d";
71796
71796
  }
71797
71797
  if (msAbs >= h7) {
71798
- return Math.round(ms / h7) + "h";
71798
+ return Math.round(ms2 / h7) + "h";
71799
71799
  }
71800
71800
  if (msAbs >= m7) {
71801
- return Math.round(ms / m7) + "m";
71801
+ return Math.round(ms2 / m7) + "m";
71802
71802
  }
71803
71803
  if (msAbs >= s7) {
71804
- return Math.round(ms / s7) + "s";
71804
+ return Math.round(ms2 / s7) + "s";
71805
71805
  }
71806
- return ms + "ms";
71806
+ return ms2 + "ms";
71807
71807
  }
71808
- function fmtLong(ms) {
71809
- var msAbs = Math.abs(ms);
71808
+ function fmtLong(ms2) {
71809
+ var msAbs = Math.abs(ms2);
71810
71810
  if (msAbs >= d6) {
71811
- return plural2(ms, msAbs, d6, "day");
71811
+ return plural2(ms2, msAbs, d6, "day");
71812
71812
  }
71813
71813
  if (msAbs >= h7) {
71814
- return plural2(ms, msAbs, h7, "hour");
71814
+ return plural2(ms2, msAbs, h7, "hour");
71815
71815
  }
71816
71816
  if (msAbs >= m7) {
71817
- return plural2(ms, msAbs, m7, "minute");
71817
+ return plural2(ms2, msAbs, m7, "minute");
71818
71818
  }
71819
71819
  if (msAbs >= s7) {
71820
- return plural2(ms, msAbs, s7, "second");
71820
+ return plural2(ms2, msAbs, s7, "second");
71821
71821
  }
71822
- return ms + " ms";
71822
+ return ms2 + " ms";
71823
71823
  }
71824
- function plural2(ms, msAbs, n6, name) {
71824
+ function plural2(ms2, msAbs, n6, name) {
71825
71825
  var isPlural = msAbs >= n6 * 1.5;
71826
- return Math.round(ms / n6) + " " + name + (isPlural ? "s" : "");
71826
+ return Math.round(ms2 / n6) + " " + name + (isPlural ? "s" : "");
71827
71827
  }
71828
71828
  }
71829
71829
  });
@@ -71867,8 +71867,8 @@ var require_common2 = __commonJS({
71867
71867
  }
71868
71868
  const self2 = debug;
71869
71869
  const curr = Number(/* @__PURE__ */ new Date());
71870
- const ms = curr - (prevTime || curr);
71871
- self2.diff = ms;
71870
+ const ms2 = curr - (prevTime || curr);
71871
+ self2.diff = ms2;
71872
71872
  self2.prev = prevTime;
71873
71873
  self2.curr = curr;
71874
71874
  prevTime = curr;
@@ -87371,11 +87371,11 @@ var require_TokenExpiredError = __commonJS({
87371
87371
  var require_timespan = __commonJS({
87372
87372
  "../node_modules/.pnpm/jsonwebtoken@9.0.2/node_modules/jsonwebtoken/lib/timespan.js"(exports2, module2) {
87373
87373
  "use strict";
87374
- var ms = require_ms();
87374
+ var ms2 = require_ms();
87375
87375
  module2.exports = function(time2, iat) {
87376
87376
  var timestamp = iat || Math.floor(Date.now() / 1e3);
87377
87377
  if (typeof time2 === "string") {
87378
- var milliseconds = ms(time2);
87378
+ var milliseconds = ms2(time2);
87379
87379
  if (typeof milliseconds === "undefined") {
87380
87380
  return;
87381
87381
  }
@@ -101913,7 +101913,7 @@ var require_dist = __commonJS({
101913
101913
  };
101914
101914
  Object.defineProperty(exports2, "__esModule", { value: true });
101915
101915
  exports2.Agent = void 0;
101916
- var net = __importStar2(require("net"));
101916
+ var net2 = __importStar2(require("net"));
101917
101917
  var http3 = __importStar2(require("http"));
101918
101918
  var https_1 = require("https");
101919
101919
  __exportStar2(require_helpers2(), exports2);
@@ -101953,7 +101953,7 @@ var require_dist = __commonJS({
101953
101953
  if (!this.sockets[name]) {
101954
101954
  this.sockets[name] = [];
101955
101955
  }
101956
- const fakeSocket = new net.Socket({ writable: false });
101956
+ const fakeSocket = new net2.Socket({ writable: false });
101957
101957
  this.sockets[name].push(fakeSocket);
101958
101958
  this.totalSocketCount++;
101959
101959
  return fakeSocket;
@@ -102165,7 +102165,7 @@ var require_dist2 = __commonJS({
102165
102165
  };
102166
102166
  Object.defineProperty(exports2, "__esModule", { value: true });
102167
102167
  exports2.HttpsProxyAgent = void 0;
102168
- var net = __importStar2(require("net"));
102168
+ var net2 = __importStar2(require("net"));
102169
102169
  var tls = __importStar2(require("tls"));
102170
102170
  var assert_1 = __importDefault2(require("assert"));
102171
102171
  var debug_1 = __importDefault2(require_src2());
@@ -102174,7 +102174,7 @@ var require_dist2 = __commonJS({
102174
102174
  var parse_proxy_response_1 = require_parse_proxy_response();
102175
102175
  var debug = (0, debug_1.default)("https-proxy-agent");
102176
102176
  var setServernameFromNonIpHost = (options) => {
102177
- if (options.servername === void 0 && options.host && !net.isIP(options.host)) {
102177
+ if (options.servername === void 0 && options.host && !net2.isIP(options.host)) {
102178
102178
  return {
102179
102179
  ...options,
102180
102180
  servername: options.host
@@ -102214,10 +102214,10 @@ var require_dist2 = __commonJS({
102214
102214
  socket = tls.connect(setServernameFromNonIpHost(this.connectOpts));
102215
102215
  } else {
102216
102216
  debug("Creating `net.Socket`: %o", this.connectOpts);
102217
- socket = net.connect(this.connectOpts);
102217
+ socket = net2.connect(this.connectOpts);
102218
102218
  }
102219
102219
  const headers = typeof this.proxyHeaders === "function" ? this.proxyHeaders() : { ...this.proxyHeaders };
102220
- const host = net.isIPv6(opts.host) ? `[${opts.host}]` : opts.host;
102220
+ const host = net2.isIPv6(opts.host) ? `[${opts.host}]` : opts.host;
102221
102221
  let payload = `CONNECT ${host}:${opts.port} HTTP/1.1\r
102222
102222
  `;
102223
102223
  if (proxy.username || proxy.password) {
@@ -102250,7 +102250,7 @@ var require_dist2 = __commonJS({
102250
102250
  return socket;
102251
102251
  }
102252
102252
  socket.destroy();
102253
- const fakeSocket = new net.Socket({ writable: false });
102253
+ const fakeSocket = new net2.Socket({ writable: false });
102254
102254
  fakeSocket.readable = true;
102255
102255
  req.once("socket", (s7) => {
102256
102256
  debug("Replaying proxy buffer for failed request");
@@ -102315,7 +102315,7 @@ var require_dist3 = __commonJS({
102315
102315
  };
102316
102316
  Object.defineProperty(exports2, "__esModule", { value: true });
102317
102317
  exports2.HttpProxyAgent = void 0;
102318
- var net = __importStar2(require("net"));
102318
+ var net2 = __importStar2(require("net"));
102319
102319
  var tls = __importStar2(require("tls"));
102320
102320
  var debug_1 = __importDefault2(require_src2());
102321
102321
  var events_1 = require("events");
@@ -102388,7 +102388,7 @@ var require_dist3 = __commonJS({
102388
102388
  socket = tls.connect(this.connectOpts);
102389
102389
  } else {
102390
102390
  debug("Creating `net.Socket`: %o", this.connectOpts);
102391
- socket = net.connect(this.connectOpts);
102391
+ socket = net2.connect(this.connectOpts);
102392
102392
  }
102393
102393
  await (0, events_1.once)(socket, "connect");
102394
102394
  return socket;
@@ -141268,7 +141268,7 @@ var require_connection = __commonJS({
141268
141268
  var _crypto = _interopRequireDefault(require("crypto"));
141269
141269
  var _os = _interopRequireDefault(require("os"));
141270
141270
  var tls = _interopRequireWildcard(require("tls"));
141271
- var net = _interopRequireWildcard(require("net"));
141271
+ var net2 = _interopRequireWildcard(require("net"));
141272
141272
  var _dns = _interopRequireDefault(require("dns"));
141273
141273
  var _constants = _interopRequireDefault(require("constants"));
141274
141274
  var _stream = require("stream");
@@ -142317,7 +142317,7 @@ var require_connection = __commonJS({
142317
142317
  async wrapWithTls(socket, signal) {
142318
142318
  signal.throwIfAborted();
142319
142319
  const secureContext = tls.createSecureContext(this.secureContextOptions);
142320
- const serverName = !net.isIP(this.config.server) ? this.config.server : "";
142320
+ const serverName = !net2.isIP(this.config.server) ? this.config.server : "";
142321
142321
  const encryptOptions = {
142322
142322
  host: this.config.server,
142323
142323
  socket,
@@ -145239,10 +145239,11 @@ function parseMssqlUrl(url) {
145239
145239
  }
145240
145240
  };
145241
145241
  }
145242
- var normalisePGliteUrl, preparePostgresDB, prepareCockroach, prepareGelDB, parseSingleStoreCredentials, connectToSingleStore, parseMysqlCredentials, connectToMySQL, parseMssqlCredentials, connectToMsSQL, prepareSqliteParams, preparePGliteParams, connectToSQLite, connectToLibSQL;
145242
+ var import_net, ms, normalisePGliteUrl, preparePostgresDB, prepareCockroach, prepareGelDB, parseSingleStoreCredentials, connectToSingleStore, parseMysqlCredentials, connectToMySQL, parseMssqlCredentials, connectToMsSQL, prepareSqliteParams, preparePGliteParams, connectToSQLite, connectToLibSQL;
145243
145243
  var init_connections = __esm({
145244
145244
  "src/cli/connections.ts"() {
145245
145245
  "use strict";
145246
+ import_net = __toESM(require("net"));
145246
145247
  init_src();
145247
145248
  init_wrapper();
145248
145249
  init_utils();
@@ -145250,6 +145251,7 @@ var init_connections = __esm({
145250
145251
  init_when_json_met_bigint();
145251
145252
  init_utils3();
145252
145253
  init_outputs();
145254
+ ms = (a6, b6) => Number(b6 - a6) / 1e6;
145253
145255
  normalisePGliteUrl = (it) => {
145254
145256
  if (it.startsWith("file:")) {
145255
145257
  return it.substring(5);
@@ -145404,13 +145406,13 @@ var init_connections = __esm({
145404
145406
  return pg.types.getTypeParser(typeId, format2);
145405
145407
  }
145406
145408
  };
145407
- const client = "url" in credentials ? new pg.Pool({ connectionString: credentials.url, max: 1 }) : new pg.Pool({ ...credentials, ssl, max: 1 });
145408
- const db = drizzle({ client });
145409
+ const pool = "url" in credentials ? new pg.Pool({ connectionString: credentials.url, max: 1 }) : new pg.Pool({ ...credentials, ssl, max: 1 });
145410
+ const db = drizzle({ client: pool });
145409
145411
  const migrateFn = async (config) => {
145410
145412
  return migrate(db, config);
145411
145413
  };
145412
145414
  const query = async (sql, params) => {
145413
- const result2 = await client.query({
145415
+ const result2 = await pool.query({
145414
145416
  text: sql,
145415
145417
  values: params ?? [],
145416
145418
  types: types3
@@ -145420,7 +145422,7 @@ var init_connections = __esm({
145420
145422
  return result2.rows;
145421
145423
  };
145422
145424
  const proxy = async (params) => {
145423
- const result2 = await client.query({
145425
+ const result2 = await pool.query({
145424
145426
  text: params.sql,
145425
145427
  values: params.params,
145426
145428
  ...params.mode === "array" && { rowMode: "array" },
@@ -145432,7 +145434,7 @@ var init_connections = __esm({
145432
145434
  };
145433
145435
  const transactionProxy = async (queries) => {
145434
145436
  const results = [];
145435
- const tx = await client.connect();
145437
+ const tx = await pool.connect();
145436
145438
  try {
145437
145439
  await tx.query("BEGIN");
145438
145440
  for (const query2 of queries) {
@@ -145451,7 +145453,117 @@ var init_connections = __esm({
145451
145453
  }
145452
145454
  return results;
145453
145455
  };
145454
- return { packageName: "pg", query, proxy, transactionProxy, migrate: migrateFn };
145456
+ const benchmarkQuery = async (client, sql, params) => {
145457
+ const explainResult = await pool.query({
145458
+ text: `EXPLAIN ANALYZE ${sql}`,
145459
+ values: params ?? [],
145460
+ types: types3
145461
+ });
145462
+ const stringifiedResult = JSON.stringify(explainResult.rows);
145463
+ const planningMatch = stringifiedResult.match(/Planning Time:\s*([\d.]+)\s*ms/i);
145464
+ const executionMatch = stringifiedResult.match(/Execution Time:\s*([\d.]+)\s*ms/i);
145465
+ let planningTime = Number(planningMatch[1]);
145466
+ let executionTime = Number(executionMatch[1]);
145467
+ let querySentAt = 0n;
145468
+ let firstDataAt = 0n;
145469
+ let lastDataAt = 0n;
145470
+ let lastRowParsedAt = 0n;
145471
+ let queryCompletedAt = 0n;
145472
+ let bytesReceived = 0;
145473
+ let rowCount = 0;
145474
+ let parseTime = 0;
145475
+ const rowDescriptionListener = (data) => {
145476
+ if (firstDataAt === 0n) {
145477
+ firstDataAt = process.hrtime.bigint();
145478
+ }
145479
+ bytesReceived += data.length;
145480
+ };
145481
+ const originalRowListener = client.connection.listeners("dataRow")[0];
145482
+ const wrappedRowListener = (data) => {
145483
+ rowCount += 1;
145484
+ const start = process.hrtime.bigint();
145485
+ lastDataAt = start;
145486
+ originalRowListener.apply(client.connection, [data]);
145487
+ const end2 = process.hrtime.bigint();
145488
+ lastRowParsedAt = end2;
145489
+ parseTime += ms(start, end2);
145490
+ bytesReceived += data.length;
145491
+ };
145492
+ client.connection.removeAllListeners("dataRow");
145493
+ client.connection.addListener("dataRow", wrappedRowListener);
145494
+ client.connection.prependListener("rowDescription", rowDescriptionListener);
145495
+ querySentAt = process.hrtime.bigint();
145496
+ await client.query({
145497
+ text: sql,
145498
+ values: params,
145499
+ types: types3
145500
+ });
145501
+ queryCompletedAt = process.hrtime.bigint();
145502
+ client.connection.removeListener("rowDescription", rowDescriptionListener);
145503
+ client.connection.removeAllListeners("dataRow");
145504
+ client.connection.addListener("dataRow", originalRowListener);
145505
+ let querySentTime = ms(querySentAt, firstDataAt) - executionTime - planningTime;
145506
+ if (querySentTime < 0) {
145507
+ const percent = 0.1;
145508
+ const overflow = -querySentTime;
145509
+ const keepForSent = overflow * percent;
145510
+ const adjustedOverflow = overflow * (1 + percent);
145511
+ const total2 = planningTime + executionTime;
145512
+ const ratioPlanning = planningTime / total2;
145513
+ const ratioExecution = executionTime / total2;
145514
+ planningTime -= adjustedOverflow * ratioPlanning;
145515
+ executionTime -= adjustedOverflow * ratioExecution;
145516
+ querySentTime = keepForSent;
145517
+ }
145518
+ const networkLatencyBefore = querySentTime / 2;
145519
+ const networkLatencyAfter = querySentTime / 2;
145520
+ const downloadTime = ms(firstDataAt, lastDataAt) - (rowCount > 1 ? parseTime - parseTime / rowCount : 0);
145521
+ const total = ms(querySentAt, queryCompletedAt);
145522
+ const calculatedTotal = networkLatencyBefore + planningTime + executionTime + networkLatencyAfter + downloadTime + parseTime + ms(lastRowParsedAt, queryCompletedAt);
145523
+ const errorMargin = Math.abs(total - calculatedTotal);
145524
+ return {
145525
+ networkLatencyBefore,
145526
+ planning: planningTime,
145527
+ execution: executionTime,
145528
+ networkLatencyAfter,
145529
+ dataDownload: downloadTime,
145530
+ dataParse: parseTime,
145531
+ total,
145532
+ errorMargin,
145533
+ dataSize: bytesReceived
145534
+ };
145535
+ };
145536
+ const benchmarkProxy = async ({ sql, params }, repeats) => {
145537
+ let startAt = 0n;
145538
+ let tcpConnectedAt = 0n;
145539
+ let tlsConnectedAt = null;
145540
+ let dbReadyAt = 0n;
145541
+ const client = "url" in credentials ? new pg.Client({ connectionString: credentials.url }) : new pg.Client({ ...credentials, ssl });
145542
+ client.connection.once("connect", () => {
145543
+ tcpConnectedAt = process.hrtime.bigint();
145544
+ });
145545
+ client.connection.prependOnceListener("sslconnect", () => {
145546
+ tlsConnectedAt = process.hrtime.bigint();
145547
+ });
145548
+ client.connection.prependOnceListener("readyForQuery", () => {
145549
+ dbReadyAt = process.hrtime.bigint();
145550
+ });
145551
+ startAt = process.hrtime.bigint();
145552
+ await client.connect();
145553
+ const results = [];
145554
+ for (let i7 = 0; i7 < repeats; i7++) {
145555
+ const r7 = await benchmarkQuery(client, sql, params);
145556
+ results.push(r7);
145557
+ }
145558
+ await client.end();
145559
+ return {
145560
+ tcpHandshake: ms(startAt, tcpConnectedAt),
145561
+ tlsHandshake: tlsConnectedAt ? ms(tcpConnectedAt, tlsConnectedAt) : null,
145562
+ dbHandshake: ms(tlsConnectedAt ?? tcpConnectedAt, dbReadyAt),
145563
+ queries: results
145564
+ };
145565
+ };
145566
+ return { packageName: "pg", query, proxy, transactionProxy, benchmarkProxy, migrate: migrateFn };
145455
145567
  }
145456
145568
  if (await checkPackage("postgres")) {
145457
145569
  console.log(
@@ -145946,7 +146058,6 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
145946
146058
  }
145947
146059
  return next();
145948
146060
  };
145949
- await connection.connect();
145950
146061
  const query = async (sql, params) => {
145951
146062
  const res = await connection.execute({
145952
146063
  sql,
@@ -145986,11 +146097,144 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
145986
146097
  }
145987
146098
  return results;
145988
146099
  };
146100
+ const benchmarkQuery = async (newConnection, sql, params) => {
146101
+ const explainResult = await connection.query({
146102
+ sql: `EXPLAIN ANALYZE ${sql}`,
146103
+ values: params ?? [],
146104
+ typeCast
146105
+ });
146106
+ const stringifiedResult = JSON.stringify(explainResult[0]);
146107
+ const timeMatch = stringifiedResult.match(
146108
+ /actual time=([0-9.eE+-]+)\.\.([0-9.eE+-]+)/
146109
+ );
146110
+ const lastRowTime = Number(timeMatch[2]);
146111
+ const executionTime = lastRowTime;
146112
+ let querySentAt = 0n;
146113
+ let firstDataAt = 0n;
146114
+ let lastDataAt = 0n;
146115
+ let lastRowParsedAt = 0n;
146116
+ let queryCompletedAt = 0n;
146117
+ let bytesReceived = 0;
146118
+ let rowCount = 0;
146119
+ let parseTime = 0;
146120
+ querySentAt = process.hrtime.bigint();
146121
+ await new Promise((resolve2, reject) => {
146122
+ const query2 = newConnection.query({
146123
+ sql,
146124
+ values: params ?? [],
146125
+ typeCast
146126
+ });
146127
+ const originalRowHandler = query2.row;
146128
+ let packets = 0;
146129
+ const wrappedRowListener = (packet, connection2) => {
146130
+ packets += 1;
146131
+ if (firstDataAt === 0n) {
146132
+ firstDataAt = process.hrtime.bigint();
146133
+ bytesReceived += packet.start;
146134
+ }
146135
+ const start = process.hrtime.bigint();
146136
+ lastDataAt = start;
146137
+ const res = originalRowHandler.apply(query2, [packet, connection2]);
146138
+ const end2 = process.hrtime.bigint();
146139
+ lastRowParsedAt = end2;
146140
+ parseTime += ms(start, end2);
146141
+ bytesReceived += packet.length();
146142
+ if (!res || packet.isEOF()) {
146143
+ return res;
146144
+ }
146145
+ return wrappedRowListener;
146146
+ };
146147
+ query2.row = wrappedRowListener;
146148
+ query2.on("result", () => {
146149
+ rowCount += 1;
146150
+ });
146151
+ query2.on("error", (err2) => {
146152
+ reject(err2);
146153
+ });
146154
+ query2.on("end", () => {
146155
+ resolve2();
146156
+ });
146157
+ });
146158
+ queryCompletedAt = process.hrtime.bigint();
146159
+ const querySentTime = ms(querySentAt, firstDataAt) - executionTime;
146160
+ const networkLatencyBefore = querySentTime / 2;
146161
+ const networkLatencyAfter = querySentTime / 2;
146162
+ const downloadTime = ms(firstDataAt, lastDataAt) - (rowCount > 1 ? parseTime - parseTime / rowCount : 0);
146163
+ const total = ms(querySentAt, queryCompletedAt);
146164
+ const calculatedTotal = networkLatencyBefore + executionTime + networkLatencyAfter + downloadTime + parseTime + ms(lastRowParsedAt, queryCompletedAt);
146165
+ const errorMargin = Math.abs(total - calculatedTotal);
146166
+ return {
146167
+ networkLatencyBefore,
146168
+ planning: null,
146169
+ execution: executionTime,
146170
+ networkLatencyAfter,
146171
+ dataDownload: downloadTime,
146172
+ dataParse: parseTime,
146173
+ total,
146174
+ errorMargin,
146175
+ dataSize: bytesReceived
146176
+ };
146177
+ };
146178
+ const benchmarkProxy = async ({ sql, params }, repeats) => {
146179
+ const { createConnection: createConnection2 } = require("mysql2");
146180
+ let startAt = 0n;
146181
+ let tcpConnectedAt = 0n;
146182
+ let tlsConnectedAt = null;
146183
+ const createStream = ({ config }) => {
146184
+ let stream;
146185
+ if (config.socketPath) {
146186
+ stream = import_net.default.connect(config.socketPath);
146187
+ } else {
146188
+ stream = import_net.default.connect(config.port, config.host);
146189
+ }
146190
+ if (config.enableKeepAlive) {
146191
+ stream.on("connect", () => {
146192
+ stream.setKeepAlive(true, config.keepAliveInitialDelay);
146193
+ });
146194
+ }
146195
+ stream.setNoDelay(true);
146196
+ stream.once("connect", () => {
146197
+ tcpConnectedAt = process.hrtime.bigint();
146198
+ });
146199
+ return stream;
146200
+ };
146201
+ startAt = process.hrtime.bigint();
146202
+ const connection2 = result2.url ? createConnection2({
146203
+ uri: result2.url,
146204
+ stream: createStream
146205
+ }) : createConnection2({
146206
+ ...result2.credentials,
146207
+ stream: createStream
146208
+ });
146209
+ await new Promise((resolve2, reject) => {
146210
+ connection2.connect((err2) => {
146211
+ tlsConnectedAt = process.hrtime.bigint();
146212
+ if (err2) {
146213
+ reject(err2);
146214
+ } else {
146215
+ resolve2();
146216
+ }
146217
+ });
146218
+ });
146219
+ const results = [];
146220
+ for (let i7 = 0; i7 < repeats; i7++) {
146221
+ const r7 = await benchmarkQuery(connection2, sql, params);
146222
+ results.push(r7);
146223
+ }
146224
+ connection2.end();
146225
+ return {
146226
+ tcpHandshake: ms(startAt, tcpConnectedAt),
146227
+ tlsHandshake: tlsConnectedAt ? ms(tcpConnectedAt, tlsConnectedAt) : null,
146228
+ dbHandshake: null,
146229
+ queries: results
146230
+ };
146231
+ };
145989
146232
  return {
145990
146233
  db: { query },
145991
146234
  packageName: "mysql2",
145992
146235
  proxy,
145993
146236
  transactionProxy,
146237
+ benchmarkProxy,
145994
146238
  database: result2.database,
145995
146239
  migrate: migrateFn
145996
146240
  };
@@ -148544,8 +148788,8 @@ ${sql}
148544
148788
  `;
148545
148789
  return content;
148546
148790
  };
148547
- prepareSnapshotFolderName = (ms) => {
148548
- const now = ms ? new Date(ms) : /* @__PURE__ */ new Date();
148791
+ prepareSnapshotFolderName = (ms2) => {
148792
+ const now = ms2 ? new Date(ms2) : /* @__PURE__ */ new Date();
148549
148793
  return `${now.getFullYear()}${two(now.getUTCMonth() + 1)}${two(
148550
148794
  now.getUTCDate()
148551
148795
  )}${two(now.getUTCHours())}${two(now.getUTCMinutes())}${two(
@@ -152043,7 +152287,7 @@ __export(studio_exports, {
152043
152287
  prepareServer: () => prepareServer,
152044
152288
  prepareSingleStoreSchema: () => prepareSingleStoreSchema
152045
152289
  });
152046
- var import_crypto10, import_drizzle_orm3, import_relations3, import_mssql_core2, import_mysql_core2, import_pg_core3, import_singlestore_core, import_sqlite_core2, import_fs6, import_node_https2, preparePgSchema, prepareMySqlSchema, prepareMsSqlSchema, prepareSQLiteSchema, prepareSingleStoreSchema, getCustomDefaults, drizzleForPostgres, drizzleForMySQL, drizzleForSQLite, drizzleForLibSQL, drizzleForSingleStore, extractRelations, init2, proxySchema, transactionProxySchema, defaultsSchema, schema5, jsonStringify, prepareServer;
152290
+ var import_crypto10, import_drizzle_orm3, import_relations3, import_mssql_core2, import_mysql_core2, import_pg_core3, import_singlestore_core, import_sqlite_core2, import_fs6, import_node_https2, preparePgSchema, prepareMySqlSchema, prepareMsSqlSchema, prepareSQLiteSchema, prepareSingleStoreSchema, getCustomDefaults, drizzleForPostgres, drizzleForMySQL, drizzleForSQLite, drizzleForLibSQL, drizzleForSingleStore, extractRelations, init2, proxySchema, transactionProxySchema, benchmarkProxySchema, defaultsSchema, schema5, jsonStringify, prepareServer;
152047
152291
  var init_studio = __esm({
152048
152292
  "src/cli/commands/studio.ts"() {
152049
152293
  "use strict";
@@ -152267,6 +152511,7 @@ var init_studio = __esm({
152267
152511
  packageName: db.packageName,
152268
152512
  proxy: db.proxy,
152269
152513
  transactionProxy: db.transactionProxy,
152514
+ benchmarkProxy: db.benchmarkProxy,
152270
152515
  customDefaults,
152271
152516
  schema: pgSchema2,
152272
152517
  relations: relations2,
@@ -152276,7 +152521,7 @@ var init_studio = __esm({
152276
152521
  };
152277
152522
  drizzleForMySQL = async (credentials, mysqlSchema, relations2, schemaFiles, casing2) => {
152278
152523
  const { connectToMySQL: connectToMySQL2 } = await Promise.resolve().then(() => (init_connections(), connections_exports));
152279
- const { proxy, transactionProxy, database, packageName } = await connectToMySQL2(credentials);
152524
+ const { proxy, transactionProxy, benchmarkProxy, database, packageName } = await connectToMySQL2(credentials);
152280
152525
  const customDefaults = getCustomDefaults(mysqlSchema, casing2);
152281
152526
  let dbUrl;
152282
152527
  if ("url" in credentials) {
@@ -152292,6 +152537,7 @@ var init_studio = __esm({
152292
152537
  databaseName: database,
152293
152538
  proxy,
152294
152539
  transactionProxy,
152540
+ benchmarkProxy,
152295
152541
  customDefaults,
152296
152542
  schema: mysqlSchema,
152297
152543
  relations: relations2,
@@ -152461,6 +152707,23 @@ var init_studio = __esm({
152461
152707
  ]).optional()
152462
152708
  }).array()
152463
152709
  });
152710
+ benchmarkProxySchema = external_exports.object({
152711
+ type: external_exports.literal("bproxy"),
152712
+ data: external_exports.object({
152713
+ query: external_exports.object({
152714
+ sql: external_exports.string(),
152715
+ params: external_exports.array(external_exports.any()).optional(),
152716
+ method: external_exports.union([
152717
+ external_exports.literal("values"),
152718
+ external_exports.literal("get"),
152719
+ external_exports.literal("all"),
152720
+ external_exports.literal("run"),
152721
+ external_exports.literal("execute")
152722
+ ]).optional()
152723
+ }),
152724
+ repeats: external_exports.number().min(1).optional()
152725
+ })
152726
+ });
152464
152727
  defaultsSchema = external_exports.object({
152465
152728
  type: external_exports.literal("defaults"),
152466
152729
  data: external_exports.array(
@@ -152475,6 +152738,7 @@ var init_studio = __esm({
152475
152738
  init2,
152476
152739
  proxySchema,
152477
152740
  transactionProxySchema,
152741
+ benchmarkProxySchema,
152478
152742
  defaultsSchema
152479
152743
  ]);
152480
152744
  jsonStringify = (data) => {
@@ -152497,6 +152761,7 @@ var init_studio = __esm({
152497
152761
  databaseName,
152498
152762
  proxy,
152499
152763
  transactionProxy,
152764
+ benchmarkProxy,
152500
152765
  customDefaults,
152501
152766
  schema: drizzleSchema,
152502
152767
  relations: relations2,
@@ -152560,7 +152825,7 @@ var init_studio = __esm({
152560
152825
  console.warn("Error message:", error3.message);
152561
152826
  }
152562
152827
  return c6.json({
152563
- version: "6.2",
152828
+ version: "6.3",
152564
152829
  dialect: dialect6,
152565
152830
  driver: driver2,
152566
152831
  packageName,
@@ -152598,6 +152863,21 @@ var init_studio = __esm({
152598
152863
  }
152599
152864
  );
152600
152865
  }
152866
+ if (type === "bproxy") {
152867
+ if (!benchmarkProxy) {
152868
+ throw new Error("Benchmark proxy is not configured for this database.");
152869
+ }
152870
+ const result2 = await benchmarkProxy(body.data.query, body.data.repeats || 1);
152871
+ const res = jsonStringify(result2);
152872
+ return c6.body(
152873
+ res,
152874
+ {
152875
+ headers: {
152876
+ "Content-Type": "application/json"
152877
+ }
152878
+ }
152879
+ );
152880
+ }
152601
152881
  if (type === "defaults") {
152602
152882
  const columns = body.data;
152603
152883
  const result2 = columns.map((column8) => {