-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathshell.js
36 lines (30 loc) · 930 Bytes
/
shell.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import * as readline from "node:readline/promises";
import { stdin, stdout, argv } from "node:process";
import * as libsql from "@libsql/client";
async function main() {
const url = argv[2];
if (!url) {
console.error("Please specify database URL as command-line argument");
return;
}
const client = libsql.createClient({ url });
const rl = readline.createInterface({ input: stdin, output: stdout });
for (;;) {
const sql = await rl.question("> ");
let rs;
try {
rs = await client.execute(sql);
} catch (e) {
if (e instanceof libsql.LibsqlError) {
console.error(e);
continue;
}
throw e;
}
console.log(JSON.stringify(rs.columns));
for (const row of rs.rows) {
console.log(JSON.stringify(Array.from(row)));
}
}
}
await main();