@bytebase/dbhub 1.2.1 → 1.2.3

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.
@@ -1496,6 +1496,20 @@ function validateSourceConfig(source, configPath) {
1496
1496
  );
1497
1497
  }
1498
1498
  }
1499
+ function resolveSqliteDatabasePath(database, configPath) {
1500
+ if (database === ":memory:") {
1501
+ return database;
1502
+ }
1503
+ const expanded = expandHomeDir(database);
1504
+ const absolute = path2.isAbsolute(expanded) ? expanded : path2.resolve(path2.dirname(configPath), expanded);
1505
+ return absolute.replace(/\\/g, "/");
1506
+ }
1507
+ function buildSqliteDSN(database) {
1508
+ if (database === ":memory:") {
1509
+ return "sqlite:///:memory:";
1510
+ }
1511
+ return `sqlite://${database.startsWith("/") ? database : `/${database}`}`;
1512
+ }
1499
1513
  function processSourceConfigs(sources, configPath) {
1500
1514
  return sources.map((source) => {
1501
1515
  const processed = { ...source };
@@ -1506,7 +1520,7 @@ function processSourceConfigs(sources, configPath) {
1506
1520
  processed.sslrootcert = expandHomeDir(processed.sslrootcert);
1507
1521
  }
1508
1522
  if (processed.type === "sqlite" && processed.database) {
1509
- processed.database = expandHomeDir(processed.database);
1523
+ processed.database = resolveSqliteDatabasePath(processed.database, configPath);
1510
1524
  }
1511
1525
  if (processed.dsn && processed.dsn.startsWith("sqlite:///~")) {
1512
1526
  processed.dsn = `sqlite:///${expandHomeDir(processed.dsn.substring(11))}`;
@@ -1629,7 +1643,7 @@ function buildDSNFromSource(source) {
1629
1643
  `Source '${source.id}': 'database' field is required for SQLite`
1630
1644
  );
1631
1645
  }
1632
- return `sqlite:///${source.database}`;
1646
+ return buildSqliteDSN(source.database);
1633
1647
  }
1634
1648
  const isAwsIamPasswordless = source.aws_iam_auth === true && ["postgres", "mysql", "mariadb"].includes(source.type);
1635
1649
  const passwordRequired = source.authentication !== "azure-active-directory-access-token" && !isAwsIamPasswordless;
package/dist/index.js CHANGED
@@ -18,7 +18,7 @@ import {
18
18
  resolveSourceConfigs,
19
19
  resolveTomlConfigPath,
20
20
  resolveTransport
21
- } from "./chunk-2DFLBX4D.js";
21
+ } from "./chunk-F5TPYAVO.js";
22
22
  import {
23
23
  allowedKeywords,
24
24
  getFirstKeyword,
@@ -1913,7 +1913,7 @@ See documentation for more details on configuring database connections.
1913
1913
  const sources = sourceConfigsData.sources;
1914
1914
  console.error(`Configuration source: ${sourceConfigsData.source}`);
1915
1915
  await connectorManager.connectWithSources(sources);
1916
- const { initializeToolRegistry: initializeToolRegistry2 } = await import("./registry-D2QVU6AG.js");
1916
+ const { initializeToolRegistry: initializeToolRegistry2 } = await import("./registry-6ABK3M6V.js");
1917
1917
  initializeToolRegistry2({
1918
1918
  sources: sourceConfigsData.sources,
1919
1919
  tools: sourceConfigsData.tools
@@ -2068,7 +2068,7 @@ See documentation for more details on configuring database connections.
2068
2068
 
2069
2069
  // src/index.ts
2070
2070
  var connectorModules = [
2071
- { load: () => import("./postgres-2FHS64EO.js"), name: "PostgreSQL", driver: "pg" },
2071
+ { load: () => import("./postgres-OVI2PNIJ.js"), name: "PostgreSQL", driver: "pg" },
2072
2072
  { load: () => import("./sqlserver-WNVSBFJ3.js"), name: "SQL Server", driver: "mssql" },
2073
2073
  { load: () => import("./sqlite-ASYMU5BI.js"), name: "SQLite", driver: "node:sqlite" },
2074
2074
  { load: () => import("./mysql-GXDUNLJ6.js"), name: "MySQL", driver: "mysql2" },
@@ -19,7 +19,7 @@ import {
19
19
  import fs from "fs";
20
20
  import os from "os";
21
21
  import path from "path";
22
- import pg from "pg";
22
+ import pg2 from "pg";
23
23
 
24
24
  // src/connectors/postgres/failed-to-read-certificate.ts
25
25
  var FailedToReadCertificate = class extends Error {
@@ -29,8 +29,35 @@ var FailedToReadCertificate = class extends Error {
29
29
  }
30
30
  };
31
31
 
32
+ // src/connectors/postgres/type-parsers.ts
33
+ import pg from "pg";
34
+ var VERBATIM_DATE_TIME_OIDS = /* @__PURE__ */ new Set([
35
+ 1082,
36
+ // date
37
+ 1114,
38
+ // timestamp without time zone
39
+ 1184,
40
+ // timestamp with time zone
41
+ 1182,
42
+ // date[]
43
+ 1115,
44
+ // timestamp[]
45
+ 1185
46
+ // timestamptz[]
47
+ ]);
48
+ var passthrough = (value) => value;
49
+ var postgresTypeParsers = {
50
+ getTypeParser(oid, format) {
51
+ if (VERBATIM_DATE_TIME_OIDS.has(oid) && (format === void 0 || format === "text")) {
52
+ return passthrough;
53
+ }
54
+ return pg.types.getTypeParser(oid, format);
55
+ }
56
+ };
57
+
32
58
  // src/connectors/postgres/index.ts
33
- var { Pool } = pg;
59
+ var { Pool } = pg2;
60
+ var POSTGRES_CLIENT_QUERY_TIMEOUT_GRACE_MS = 5e3;
34
61
  var PostgresDSNParser = class {
35
62
  async parse(dsn, config) {
36
63
  const connectionTimeoutSeconds = config?.connectionTimeoutSeconds;
@@ -90,7 +117,9 @@ Expected: ${expectedFormat}`
90
117
  poolConfig.connectionTimeoutMillis = connectionTimeoutSeconds * 1e3;
91
118
  }
92
119
  if (queryTimeoutSeconds !== void 0) {
93
- poolConfig.query_timeout = queryTimeoutSeconds * 1e3;
120
+ const queryTimeoutMs = queryTimeoutSeconds * 1e3;
121
+ poolConfig.statement_timeout = queryTimeoutMs;
122
+ poolConfig.query_timeout = queryTimeoutMs + POSTGRES_CLIENT_QUERY_TIMEOUT_GRACE_MS;
94
123
  }
95
124
  return poolConfig;
96
125
  } catch (error) {
@@ -136,6 +165,7 @@ var PostgresConnector = class _PostgresConnector {
136
165
  this.defaultSchema = "public";
137
166
  try {
138
167
  const poolConfig = await this.dsnParser.parse(dsn, config);
168
+ poolConfig.types = postgresTypeParsers;
139
169
  if (config?.readonly) {
140
170
  poolConfig.options = (poolConfig.options || "") + " -c default_transaction_read_only=on";
141
171
  }