execute
The execute method binds a complete parameter list and runs the statement.
execute(
params?: JsonValue[],
options?: QueryOptions,
): Promise<Results<RowType>>| Type | Description | |
|---|---|---|
params? | JsonValue[] | JSON-compatible values for |
options? | QueryOptions | Result-shape options. |
| returns | Promise<Results<RowType>> | A Promise resolving to the statement results. |
Example
import {create} from 'tinyjoin';
const db = await create();
await db.exec(`
CREATE TABLE tasks (id TEXT PRIMARY KEY, title TEXT NOT NULL)
`);
const insert = await db.prepare(
'INSERT INTO tasks (id, title) VALUES ($1, $2)',
);
await insert.execute(['a', 'Write docs']);
await insert.execute(['b', 'Ship release']);
const {rows} = await db.query('SELECT title FROM tasks ORDER BY id');
console.log(rows);
// -> [{title: 'Write docs'}, {title: 'Ship release'}]
await insert.close();
await db.close();