exec
The exec method runs a parameter-free DML and read script as one savepoint.
exec(
sql: string,
options?: QueryOptions,
): Promise<Results<Row>[]>| Type | Description | |
|---|---|---|
sql | string | |
options? | QueryOptions | |
| returns | Promise<Results<Row>[]> | A Promise resolving to one result per statement, in script order. |
Example
import {create} from 'tinyjoin';
const db = await create();
await db.exec(`
CREATE TABLE tasks (id TEXT PRIMARY KEY, title TEXT NOT NULL)
`);
await db.transaction(async (tx) => {
const results = await tx.exec(`
INSERT INTO tasks (id, title) VALUES ('a', 'Write docs');
INSERT INTO tasks (id, title) VALUES ('b', 'Ship release');
SELECT id FROM tasks ORDER BY id;
`);
console.log(results[2].rows);
// -> [{id: 'a'}, {id: 'b'}]
});
await db.close();