Files
docs/build/snippets/python/code-samples/sql-agent-run-query-js.mdx
T
2026-07-29 10:28:19 +00:00

24 lines
616 B
Plaintext

```ts
import sqlite3 from "sqlite3";
// Below are minimal tools for demonstration purposes.
async function runQuery(query: string): Promise<any[]> {
const dbPath = await resolveDbPath();
const db = new sqlite3.Database(dbPath);
return new Promise((resolve, reject) => {
db.all(query, [], (err, rows) => {
db.close();
if (err) reject(err);
else resolve(rows);
});
});
}
async function getSchema() {
const tables = await runQuery(
"SELECT sql FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%';",
);
return tables.map((row) => row.sql).join("\n\n");
}
```