@bytebase/dbhub 0.4.0 → 0.4.2
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/README.md +65 -1
- package/dist/index.js +49 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -98,11 +98,22 @@ docker run --rm --init \
|
|
|
98
98
|
--dsn "oracle://username:password@localhost:1521/service_name"
|
|
99
99
|
```
|
|
100
100
|
|
|
101
|
+
```bash
|
|
102
|
+
# Oracle example with thick mode for connecting to 11g or older
|
|
103
|
+
docker run --rm --init \
|
|
104
|
+
--name dbhub \
|
|
105
|
+
--publish 8080:8080 \
|
|
106
|
+
bytebase/dbhub-oracle-thick \
|
|
107
|
+
--transport sse \
|
|
108
|
+
--port 8080 \
|
|
109
|
+
--dsn "oracle://username:password@localhost:1521/service_name"
|
|
110
|
+
```
|
|
111
|
+
|
|
101
112
|
### NPM
|
|
102
113
|
|
|
103
114
|
```bash
|
|
104
115
|
# PostgreSQL example
|
|
105
|
-
npx @bytebase/dbhub --transport sse --port 8080 --dsn "postgres://user:password@localhost:5432/dbname"
|
|
116
|
+
npx @bytebase/dbhub --transport sse --port 8080 --dsn "postgres://user:password@localhost:5432/dbname?sslmode=disable"
|
|
106
117
|
```
|
|
107
118
|
|
|
108
119
|
```bash
|
|
@@ -164,6 +175,38 @@ npx @bytebase/dbhub --transport sse --port 8080 --demo
|
|
|
164
175
|
|
|
165
176
|
## Usage
|
|
166
177
|
|
|
178
|
+
### SSL Connections
|
|
179
|
+
|
|
180
|
+
You can specify the SSL mode using the `sslmode` parameter in your DSN string:
|
|
181
|
+
|
|
182
|
+
| Database | `sslmode=disable` | `sslmode=require` | Default SSL Behavior |
|
|
183
|
+
|------------|:----------------:|:----------------:|:-------------------:|
|
|
184
|
+
| PostgreSQL | ✅ | ✅ | Certificate verification |
|
|
185
|
+
| MySQL | ✅ | ✅ | Certificate verification |
|
|
186
|
+
| MariaDB | ✅ | ✅ | Certificate verification |
|
|
187
|
+
| SQL Server | ❌ | ❌ | Built-in encryption |
|
|
188
|
+
| SQLite | ❌ | ❌ | N/A (file-based) |
|
|
189
|
+
| Oracle | ❌ | ❌ | Built-in encryption |
|
|
190
|
+
|
|
191
|
+
**SSL Mode Options:**
|
|
192
|
+
|
|
193
|
+
- `sslmode=disable`: All SSL/TLS encryption is turned off. Data is transmitted in plaintext.
|
|
194
|
+
- `sslmode=require`: Connection is encrypted, but the server's certificate is not verified. This provides protection against packet sniffing but not against man-in-the-middle attacks. You may use this for trusted self-signed CA.
|
|
195
|
+
|
|
196
|
+
Without specifying `sslmode`, most databases default to certificate verification, which provides the highest level of security.
|
|
197
|
+
|
|
198
|
+
Example usage:
|
|
199
|
+
```bash
|
|
200
|
+
# Disable SSL
|
|
201
|
+
postgres://user:password@localhost:5432/dbname?sslmode=disable
|
|
202
|
+
|
|
203
|
+
# Require SSL without certificate verification
|
|
204
|
+
postgres://user:password@localhost:5432/dbname?sslmode=require
|
|
205
|
+
|
|
206
|
+
# Standard SSL with certificate verification (default)
|
|
207
|
+
postgres://user:password@localhost:5432/dbname
|
|
208
|
+
```
|
|
209
|
+
|
|
167
210
|
### Read-only Mode
|
|
168
211
|
|
|
169
212
|
You can run DBHub in read-only mode, which restricts SQL query execution to read-only operations:
|
|
@@ -221,6 +264,27 @@ DBHub supports the following database connection string formats:
|
|
|
221
264
|
| SQLite | `sqlite:///[path/to/file]` or `sqlite::memory:` | `sqlite:///path/to/database.db`, `sqlite:C:/Users/YourName/data/database.db (windows)` or `sqlite::memory:` |
|
|
222
265
|
| Oracle | `oracle://[user]:[password]@[host]:[port]/[service_name]` | `oracle://username:password@localhost:1521/service_name` |
|
|
223
266
|
|
|
267
|
+
#### Oracle
|
|
268
|
+
|
|
269
|
+
If you see the error "NJS-138: connections to this database server version are not supported by node-oracledb in Thin mode", you need to use Thick mode as described below.
|
|
270
|
+
|
|
271
|
+
##### Docker
|
|
272
|
+
|
|
273
|
+
Use `bytebase/dbhub-oracle-thick` instead of `bytebase/dbhub` docker image.
|
|
274
|
+
|
|
275
|
+
##### npx
|
|
276
|
+
|
|
277
|
+
1. Download and install [Oracle Instant Client](https://www.oracle.com/database/technologies/instant-client/downloads.html) for your platform
|
|
278
|
+
1. Set the `ORACLE_LIB_DIR` environment variable to the path of your Oracle Instant Client:
|
|
279
|
+
|
|
280
|
+
```bash
|
|
281
|
+
# Set environment variable to Oracle Instant Client directory
|
|
282
|
+
export ORACLE_LIB_DIR=/path/to/instantclient_19_8
|
|
283
|
+
|
|
284
|
+
# Then run DBHub
|
|
285
|
+
npx @bytebase/dbhub --dsn "oracle://username:password@localhost:1521/service_name"
|
|
286
|
+
```
|
|
287
|
+
|
|
224
288
|
#### SQL Server
|
|
225
289
|
|
|
226
290
|
Extra query parameters:
|
package/dist/index.js
CHANGED
|
@@ -76,7 +76,13 @@ var PostgresDSNParser = class {
|
|
|
76
76
|
};
|
|
77
77
|
url.searchParams.forEach((value, key) => {
|
|
78
78
|
if (key === "sslmode") {
|
|
79
|
-
|
|
79
|
+
if (value === "disable") {
|
|
80
|
+
config.ssl = false;
|
|
81
|
+
} else if (value === "require") {
|
|
82
|
+
config.ssl = { rejectUnauthorized: false };
|
|
83
|
+
} else {
|
|
84
|
+
config.ssl = true;
|
|
85
|
+
}
|
|
80
86
|
}
|
|
81
87
|
});
|
|
82
88
|
return config;
|
|
@@ -87,7 +93,7 @@ var PostgresDSNParser = class {
|
|
|
87
93
|
}
|
|
88
94
|
}
|
|
89
95
|
getSampleDSN() {
|
|
90
|
-
return "postgres://postgres:password@localhost:5432/postgres?sslmode=
|
|
96
|
+
return "postgres://postgres:password@localhost:5432/postgres?sslmode=require";
|
|
91
97
|
}
|
|
92
98
|
isValidDSN(dsn) {
|
|
93
99
|
try {
|
|
@@ -930,8 +936,14 @@ var MySQLDSNParser = class {
|
|
|
930
936
|
password: url.password ? decodeURIComponent(url.password) : ""
|
|
931
937
|
};
|
|
932
938
|
url.searchParams.forEach((value, key) => {
|
|
933
|
-
if (key === "
|
|
934
|
-
|
|
939
|
+
if (key === "sslmode") {
|
|
940
|
+
if (value === "disable") {
|
|
941
|
+
config.ssl = void 0;
|
|
942
|
+
} else if (value === "require") {
|
|
943
|
+
config.ssl = { rejectUnauthorized: false };
|
|
944
|
+
} else {
|
|
945
|
+
config.ssl = {};
|
|
946
|
+
}
|
|
935
947
|
}
|
|
936
948
|
});
|
|
937
949
|
return config;
|
|
@@ -942,7 +954,7 @@ var MySQLDSNParser = class {
|
|
|
942
954
|
}
|
|
943
955
|
}
|
|
944
956
|
getSampleDSN() {
|
|
945
|
-
return "mysql://root:password@localhost:3306/mysql";
|
|
957
|
+
return "mysql://root:password@localhost:3306/mysql?sslmode=require";
|
|
946
958
|
}
|
|
947
959
|
isValidDSN(dsn) {
|
|
948
960
|
try {
|
|
@@ -1280,8 +1292,14 @@ var MariadbDSNParser = class {
|
|
|
1280
1292
|
password: decodeURIComponent(url.password)
|
|
1281
1293
|
};
|
|
1282
1294
|
url.searchParams.forEach((value, key) => {
|
|
1283
|
-
if (key === "
|
|
1284
|
-
|
|
1295
|
+
if (key === "sslmode") {
|
|
1296
|
+
if (value === "disable") {
|
|
1297
|
+
config.ssl = void 0;
|
|
1298
|
+
} else if (value === "require") {
|
|
1299
|
+
config.ssl = { rejectUnauthorized: false };
|
|
1300
|
+
} else {
|
|
1301
|
+
config.ssl = {};
|
|
1302
|
+
}
|
|
1285
1303
|
}
|
|
1286
1304
|
});
|
|
1287
1305
|
return config;
|
|
@@ -1292,7 +1310,7 @@ var MariadbDSNParser = class {
|
|
|
1292
1310
|
}
|
|
1293
1311
|
}
|
|
1294
1312
|
getSampleDSN() {
|
|
1295
|
-
return "mariadb://root:password@localhost:3306/db";
|
|
1313
|
+
return "mariadb://root:password@localhost:3306/db?sslmode=require";
|
|
1296
1314
|
}
|
|
1297
1315
|
isValidDSN(dsn) {
|
|
1298
1316
|
try {
|
|
@@ -1680,6 +1698,16 @@ var OracleConnector = class {
|
|
|
1680
1698
|
}
|
|
1681
1699
|
}
|
|
1682
1700
|
};
|
|
1701
|
+
try {
|
|
1702
|
+
if (process.env.ORACLE_LIB_DIR) {
|
|
1703
|
+
oracledb.initOracleClient({ libDir: process.env.ORACLE_LIB_DIR });
|
|
1704
|
+
console.error("Oracle client initialized in Thick mode");
|
|
1705
|
+
} else {
|
|
1706
|
+
console.error("ORACLE_LIB_DIR not specified, will use Thin mode by default");
|
|
1707
|
+
}
|
|
1708
|
+
} catch (err) {
|
|
1709
|
+
console.error("Failed to initialize Oracle client:", err);
|
|
1710
|
+
}
|
|
1683
1711
|
oracledb.autoCommit = true;
|
|
1684
1712
|
}
|
|
1685
1713
|
async connect(dsn, initializationScript) {
|
|
@@ -1704,6 +1732,19 @@ var OracleConnector = class {
|
|
|
1704
1732
|
}
|
|
1705
1733
|
} catch (error) {
|
|
1706
1734
|
console.error("Failed to connect to Oracle database:", error);
|
|
1735
|
+
if (error instanceof Error && error.message.includes("NJS-138")) {
|
|
1736
|
+
const enhancedError = new Error(
|
|
1737
|
+
`${error.message}
|
|
1738
|
+
|
|
1739
|
+
This error occurs when your Oracle database version is not supported by node-oracledb in Thin mode.
|
|
1740
|
+
To resolve this, you need to use Thick mode:
|
|
1741
|
+
1. Download Oracle Instant Client from https://www.oracle.com/database/technologies/instant-client/downloads.html
|
|
1742
|
+
2. Set ORACLE_LIB_DIR environment variable to the path of your Oracle Instant Client
|
|
1743
|
+
Example: export ORACLE_LIB_DIR=/path/to/instantclient_19_8
|
|
1744
|
+
3. Restart DBHub`
|
|
1745
|
+
);
|
|
1746
|
+
throw enhancedError;
|
|
1747
|
+
}
|
|
1707
1748
|
throw error;
|
|
1708
1749
|
}
|
|
1709
1750
|
}
|