MCPcopy Index your code
hub / github.com/outerbase/studio / SqljsQueryable

Class SqljsQueryable

src/drivers/database/sqljs.ts:11–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9import { SqliteLikeBaseDriver } from "../sqlite-base-driver";
10
11class SqljsQueryable implements QueryableBaseDriver {
12 public hasRowsChanged: boolean = false;
13
14 constructor(protected db: Database) {}
15
16 async transaction(stmts: InStatement[]): Promise<DatabaseResultSet[]> {
17 const r: DatabaseResultSet[] = [];
18
19 for (const s of stmts) {
20 r.push(await this.query(s));
21 }
22
23 return r;
24 }
25
26 async query(stmt: InStatement): Promise<DatabaseResultSet> {
27 const sql = typeof stmt === "string" ? stmt : stmt.sql;
28 const bind =
29 typeof stmt === "string" ? undefined : (stmt.args as BindParams);
30
31 const startTime = Date.now();
32 const s = this.db.prepare(sql, bind);
33 const endTime = Date.now();
34
35 // Do the transform result here
36 const headerName = s.getColumnNames();
37 const headerSet = new Set();
38
39 const headers: DatabaseHeader[] = headerName.map((colName) => {
40 let renameColName = colName;
41
42 for (let i = 0; i < 20; i++) {
43 if (!headerSet.has(renameColName)) break;
44 renameColName = `__${colName}_${i}`;
45 }
46
47 return {
48 name: renameColName,
49 displayName: colName,
50 originalType: null,
51 type: undefined,
52 };
53 });
54
55 const rows: DatabaseRow[] = [];
56 while (s.step()) {
57 const r = s.get();
58 rows.push(
59 headers.reduce((a, b, idx) => {
60 a[b.name] = r[idx];
61 return a;
62 }, {} as DatabaseRow)
63 );
64 }
65
66 if (this.db.getRowsModified() > 0) {
67 this.hasRowsChanged = true;
68 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…