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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/api-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,77 @@ 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
+ const planningTime = Number(planningMatch[1]);
145466
+ const executionTime = Number(executionMatch[1]);
145467
+ let querySentAt = 0n;
145468
+ let firstDataAt = 0n;
145469
+ let lastDataAt = 0n;
145470
+ let bytesReceived = 0;
145471
+ client.connection.addListener("rowDescription", (data) => {
145472
+ if (firstDataAt === 0n) {
145473
+ firstDataAt = process.hrtime.bigint();
145474
+ }
145475
+ bytesReceived += data.length;
145476
+ });
145477
+ client.connection.addListener("dataRow", (data) => {
145478
+ bytesReceived += data.length;
145479
+ });
145480
+ client.connection.addListener("commandComplete", () => {
145481
+ lastDataAt = process.hrtime.bigint();
145482
+ });
145483
+ querySentAt = process.hrtime.bigint();
145484
+ await client.query(sql, params);
145485
+ client.connection.removeAllListeners("rowDescription");
145486
+ client.connection.removeAllListeners("dataRow");
145487
+ client.connection.removeAllListeners("commandComplete");
145488
+ return {
145489
+ planning: planningTime,
145490
+ execution: executionTime,
145491
+ dataDownload: ms(firstDataAt, lastDataAt) + ms(querySentAt, firstDataAt) - executionTime - planningTime,
145492
+ total: ms(querySentAt, lastDataAt),
145493
+ dataSize: bytesReceived
145494
+ };
145495
+ };
145496
+ const benchmarkProxy = async ({ sql, params }, repeats) => {
145497
+ let startAt = 0n;
145498
+ let tcpConnectedAt = 0n;
145499
+ let tlsConnectedAt = null;
145500
+ let dbReadyAt = 0n;
145501
+ const client = "url" in credentials ? new pg.Client({ connectionString: credentials.url }) : new pg.Client({ ...credentials, ssl });
145502
+ client.connection.once("connect", () => {
145503
+ tcpConnectedAt = process.hrtime.bigint();
145504
+ });
145505
+ client.connection.prependOnceListener("sslconnect", () => {
145506
+ tlsConnectedAt = process.hrtime.bigint();
145507
+ });
145508
+ client.connection.prependOnceListener("readyForQuery", () => {
145509
+ dbReadyAt = process.hrtime.bigint();
145510
+ });
145511
+ startAt = process.hrtime.bigint();
145512
+ await client.connect();
145513
+ const results = [];
145514
+ for (let i7 = 0; i7 < repeats; i7++) {
145515
+ const r7 = await benchmarkQuery(client, sql, params);
145516
+ results.push(r7);
145517
+ }
145518
+ await client.end();
145519
+ return {
145520
+ tcpHandshake: ms(startAt, tcpConnectedAt),
145521
+ tlsHandshake: tlsConnectedAt ? ms(tcpConnectedAt, tlsConnectedAt) : null,
145522
+ dbHandshake: ms(tlsConnectedAt ?? tcpConnectedAt, dbReadyAt),
145523
+ queries: results
145524
+ };
145525
+ };
145526
+ return { packageName: "pg", query, proxy, transactionProxy, benchmarkProxy, migrate: migrateFn };
145455
145527
  }
145456
145528
  if (await checkPackage("postgres")) {
145457
145529
  console.log(
@@ -145946,7 +146018,6 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
145946
146018
  }
145947
146019
  return next();
145948
146020
  };
145949
- await connection.connect();
145950
146021
  const query = async (sql, params) => {
145951
146022
  const res = await connection.execute({
145952
146023
  sql,
@@ -145986,11 +146057,112 @@ To link your project, please refer https://docs.geldata.com/reference/cli/gel_in
145986
146057
  }
145987
146058
  return results;
145988
146059
  };
146060
+ const benchmarkQuery = async (newConnection, sql, params) => {
146061
+ const explainResult = await connection.query({
146062
+ sql: `EXPLAIN ANALYZE ${sql}`,
146063
+ values: params ?? [],
146064
+ typeCast
146065
+ });
146066
+ const stringifiedResult = JSON.stringify(explainResult[0]);
146067
+ const timeMatch = stringifiedResult.match(
146068
+ /actual time=([0-9.eE+-]+)\.\.([0-9.eE+-]+)/
146069
+ );
146070
+ const lastRowTime = Number(timeMatch[2]);
146071
+ const executionTime = lastRowTime;
146072
+ let querySentAt = 0n;
146073
+ let firstDataAt = 0n;
146074
+ let lastDataAt = 0n;
146075
+ let bytesReceived = 0;
146076
+ querySentAt = process.hrtime.bigint();
146077
+ await new Promise((resolve2, reject) => {
146078
+ const query2 = newConnection.query({
146079
+ sql,
146080
+ values: params ?? [],
146081
+ typeCast
146082
+ // rowsAsArray: true,
146083
+ });
146084
+ query2.on("error", (err2) => {
146085
+ reject(err2);
146086
+ });
146087
+ query2.on("fields", (fields) => {
146088
+ if (firstDataAt === 0n) {
146089
+ firstDataAt = process.hrtime.bigint();
146090
+ }
146091
+ bytesReceived += fields[0]._buf.length;
146092
+ });
146093
+ query2.on("end", () => {
146094
+ lastDataAt = process.hrtime.bigint();
146095
+ resolve2();
146096
+ });
146097
+ });
146098
+ return {
146099
+ planning: null,
146100
+ execution: executionTime,
146101
+ dataDownload: ms(firstDataAt, lastDataAt) + ms(querySentAt, firstDataAt) - executionTime,
146102
+ total: ms(querySentAt, lastDataAt),
146103
+ dataSize: bytesReceived
146104
+ };
146105
+ };
146106
+ const benchmarkProxy = async ({ sql, params }, repeats) => {
146107
+ const { createConnection: createConnection2 } = require("mysql2");
146108
+ let startAt = 0n;
146109
+ let tcpConnectedAt = 0n;
146110
+ let tlsConnectedAt = null;
146111
+ const createStream = ({ config }) => {
146112
+ let stream;
146113
+ if (config.socketPath) {
146114
+ stream = import_net.default.connect(config.socketPath);
146115
+ } else {
146116
+ stream = import_net.default.connect(config.port, config.host);
146117
+ }
146118
+ if (config.enableKeepAlive) {
146119
+ stream.on("connect", () => {
146120
+ stream.setKeepAlive(true, config.keepAliveInitialDelay);
146121
+ });
146122
+ }
146123
+ stream.setNoDelay(true);
146124
+ stream.once("connect", () => {
146125
+ tcpConnectedAt = process.hrtime.bigint();
146126
+ });
146127
+ return stream;
146128
+ };
146129
+ startAt = process.hrtime.bigint();
146130
+ const connection2 = result2.url ? createConnection2({
146131
+ uri: result2.url,
146132
+ stream: createStream
146133
+ }) : createConnection2({
146134
+ ...result2.credentials,
146135
+ stream: createStream
146136
+ });
146137
+ await new Promise((resolve2, reject) => {
146138
+ connection2.connect((err2) => {
146139
+ tlsConnectedAt = process.hrtime.bigint();
146140
+ if (err2) {
146141
+ reject(err2);
146142
+ } else {
146143
+ resolve2();
146144
+ }
146145
+ });
146146
+ });
146147
+ const results = [];
146148
+ for (let i7 = 0; i7 < repeats; i7++) {
146149
+ const r7 = await benchmarkQuery(connection2, sql, params);
146150
+ results.push(r7);
146151
+ }
146152
+ connection2.end();
146153
+ return {
146154
+ tcpHandshake: ms(startAt, tcpConnectedAt),
146155
+ tlsHandshake: tlsConnectedAt ? ms(tcpConnectedAt, tlsConnectedAt) : null,
146156
+ dbHandshake: null,
146157
+ queries: results
146158
+ };
146159
+ };
145989
146160
  return {
145990
146161
  db: { query },
145991
146162
  packageName: "mysql2",
145992
146163
  proxy,
145993
146164
  transactionProxy,
146165
+ benchmarkProxy,
145994
146166
  database: result2.database,
145995
146167
  migrate: migrateFn
145996
146168
  };
@@ -148544,8 +148716,8 @@ ${sql}
148544
148716
  `;
148545
148717
  return content;
148546
148718
  };
148547
- prepareSnapshotFolderName = (ms) => {
148548
- const now = ms ? new Date(ms) : /* @__PURE__ */ new Date();
148719
+ prepareSnapshotFolderName = (ms2) => {
148720
+ const now = ms2 ? new Date(ms2) : /* @__PURE__ */ new Date();
148549
148721
  return `${now.getFullYear()}${two(now.getUTCMonth() + 1)}${two(
148550
148722
  now.getUTCDate()
148551
148723
  )}${two(now.getUTCHours())}${two(now.getUTCMinutes())}${two(
@@ -152043,7 +152215,7 @@ __export(studio_exports, {
152043
152215
  prepareServer: () => prepareServer,
152044
152216
  prepareSingleStoreSchema: () => prepareSingleStoreSchema
152045
152217
  });
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;
152218
+ 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
152219
  var init_studio = __esm({
152048
152220
  "src/cli/commands/studio.ts"() {
152049
152221
  "use strict";
@@ -152267,6 +152439,7 @@ var init_studio = __esm({
152267
152439
  packageName: db.packageName,
152268
152440
  proxy: db.proxy,
152269
152441
  transactionProxy: db.transactionProxy,
152442
+ benchmarkProxy: db.benchmarkProxy,
152270
152443
  customDefaults,
152271
152444
  schema: pgSchema2,
152272
152445
  relations: relations2,
@@ -152276,7 +152449,7 @@ var init_studio = __esm({
152276
152449
  };
152277
152450
  drizzleForMySQL = async (credentials, mysqlSchema, relations2, schemaFiles, casing2) => {
152278
152451
  const { connectToMySQL: connectToMySQL2 } = await Promise.resolve().then(() => (init_connections(), connections_exports));
152279
- const { proxy, transactionProxy, database, packageName } = await connectToMySQL2(credentials);
152452
+ const { proxy, transactionProxy, benchmarkProxy, database, packageName } = await connectToMySQL2(credentials);
152280
152453
  const customDefaults = getCustomDefaults(mysqlSchema, casing2);
152281
152454
  let dbUrl;
152282
152455
  if ("url" in credentials) {
@@ -152292,6 +152465,7 @@ var init_studio = __esm({
152292
152465
  databaseName: database,
152293
152466
  proxy,
152294
152467
  transactionProxy,
152468
+ benchmarkProxy,
152295
152469
  customDefaults,
152296
152470
  schema: mysqlSchema,
152297
152471
  relations: relations2,
@@ -152461,6 +152635,23 @@ var init_studio = __esm({
152461
152635
  ]).optional()
152462
152636
  }).array()
152463
152637
  });
152638
+ benchmarkProxySchema = external_exports.object({
152639
+ type: external_exports.literal("bproxy"),
152640
+ data: external_exports.object({
152641
+ query: external_exports.object({
152642
+ sql: external_exports.string(),
152643
+ params: external_exports.array(external_exports.any()).optional(),
152644
+ method: external_exports.union([
152645
+ external_exports.literal("values"),
152646
+ external_exports.literal("get"),
152647
+ external_exports.literal("all"),
152648
+ external_exports.literal("run"),
152649
+ external_exports.literal("execute")
152650
+ ]).optional()
152651
+ }),
152652
+ repeats: external_exports.number().min(1).optional()
152653
+ })
152654
+ });
152464
152655
  defaultsSchema = external_exports.object({
152465
152656
  type: external_exports.literal("defaults"),
152466
152657
  data: external_exports.array(
@@ -152475,6 +152666,7 @@ var init_studio = __esm({
152475
152666
  init2,
152476
152667
  proxySchema,
152477
152668
  transactionProxySchema,
152669
+ benchmarkProxySchema,
152478
152670
  defaultsSchema
152479
152671
  ]);
152480
152672
  jsonStringify = (data) => {
@@ -152497,6 +152689,7 @@ var init_studio = __esm({
152497
152689
  databaseName,
152498
152690
  proxy,
152499
152691
  transactionProxy,
152692
+ benchmarkProxy,
152500
152693
  customDefaults,
152501
152694
  schema: drizzleSchema,
152502
152695
  relations: relations2,
@@ -152560,7 +152753,7 @@ var init_studio = __esm({
152560
152753
  console.warn("Error message:", error3.message);
152561
152754
  }
152562
152755
  return c6.json({
152563
- version: "6.2",
152756
+ version: "6.3",
152564
152757
  dialect: dialect6,
152565
152758
  driver: driver2,
152566
152759
  packageName,
@@ -152598,6 +152791,21 @@ var init_studio = __esm({
152598
152791
  }
152599
152792
  );
152600
152793
  }
152794
+ if (type === "bproxy") {
152795
+ if (!benchmarkProxy) {
152796
+ throw new Error("Benchmark proxy is not configured for this database.");
152797
+ }
152798
+ const result2 = await benchmarkProxy(body.data.query, body.data.repeats || 1);
152799
+ const res = jsonStringify(result2);
152800
+ return c6.body(
152801
+ res,
152802
+ {
152803
+ headers: {
152804
+ "Content-Type": "application/json"
152805
+ }
152806
+ }
152807
+ );
152808
+ }
152601
152809
  if (type === "defaults") {
152602
152810
  const columns = body.data;
152603
152811
  const result2 = columns.map((column8) => {