TinyJoin logoTinyJoin

exec

Essential

The exec method runs one or more parameter-free statements as one implicit transaction.

exec(
  sql: string,
  options?: QueryOptions,
): Promise<Results<Row>[]>
TypeDescription
sqlstring
options?QueryOptions
returnsPromise<Results<Row>[]>

A Promise resolving to one result per statement, in script order.

Example

import {create} from 'tinyjoin';

const db = await create();
const results = await db.exec(`
  CREATE TABLE tasks (id TEXT PRIMARY KEY, title TEXT NOT NULL);
  INSERT INTO tasks (id, title) VALUES ('a', 'Write docs');
  SELECT * FROM tasks;
`);
console.log(results.length);
// -> 3
console.log(results[2].rows);
// -> [{id: 'a', title: 'Write docs'}]
await db.close();