dbcat 0.0.8 → 0.0.9
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/package.json +1 -1
- package/src/index.ts +11 -6
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -9,19 +9,24 @@ import { join } from "node:path";
|
|
|
9
9
|
const SQLITE_EXTENSIONS = [".db", ".sqlite", ".sqlite3", ".db3", ".s3db"];
|
|
10
10
|
const REMOTE_PROTOCOLS = ["http://", "https://", "s3://"];
|
|
11
11
|
|
|
12
|
-
export function createConnection(
|
|
12
|
+
export function createConnection(
|
|
13
|
+
input?: string,
|
|
14
|
+
options?: { readonly?: boolean }
|
|
15
|
+
): InstanceType<typeof Bun.SQL> {
|
|
16
|
+
const opts = { readonly: true, ...options };
|
|
17
|
+
|
|
13
18
|
if (!input) {
|
|
14
|
-
return new Bun.SQL();
|
|
19
|
+
return new Bun.SQL(opts);
|
|
15
20
|
}
|
|
16
21
|
|
|
17
22
|
if (
|
|
18
23
|
!input.includes("://") &&
|
|
19
24
|
SQLITE_EXTENSIONS.some((ext) => input.endsWith(ext))
|
|
20
25
|
) {
|
|
21
|
-
return new Bun.SQL(`sqlite://${input}
|
|
26
|
+
return new Bun.SQL(`sqlite://${input}`, opts);
|
|
22
27
|
}
|
|
23
28
|
|
|
24
|
-
return new Bun.SQL(input);
|
|
29
|
+
return new Bun.SQL(input, opts);
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
async function downloadToTmp(url: string): Promise<string> {
|
|
@@ -141,7 +146,7 @@ function displayQueryResult(rows: Record<string, unknown>[]) {
|
|
|
141
146
|
}
|
|
142
147
|
|
|
143
148
|
async function readStdin(): Promise<string | null> {
|
|
144
|
-
if (process.stdin.isTTY) {
|
|
149
|
+
if (process.stdin.isTTY || Bun.stdin.size === 0) {
|
|
145
150
|
return null;
|
|
146
151
|
}
|
|
147
152
|
|
|
@@ -238,7 +243,7 @@ async function main() {
|
|
|
238
243
|
|
|
239
244
|
let sql: InstanceType<typeof Bun.SQL>;
|
|
240
245
|
try {
|
|
241
|
-
sql = createConnection(connectionInput);
|
|
246
|
+
sql = createConnection(connectionInput, { readonly: Bun.stdin.size == 0 });
|
|
242
247
|
} catch (error) {
|
|
243
248
|
console.error("Failed to connect:");
|
|
244
249
|
console.error(error instanceof Error ? error.message : String(error));
|