Skip to content
  • Auto
  • Light
  • Dark
Get Started

Batch

Batch
client.sqlite.batch(SqliteBatchParamsbody, RequestOptionsoptions?): columnsarraycolumnTypesarrayrowsarrayrowsAffectednumberlastInsertRowidunionSqliteBatchResponse
post/v1/sqlite/batch

Execute a batch of SQLite statements and return results for all of them

Parameters
bodystatementsarraymodeunionSqliteBatchParams
Hide ParametersShow Parameters
statementsarray
Array<string | argsunionsqlstringParameterizedQuery>
Hide ParametersShow Parameters
string
ParameterizedQuery

A parameterized SQL query. See https://docs.turso.tech/sdk/ts/reference#batch-transactions for reference

Hide ParametersShow Parameters
argsunion
Array<unknown> | Record<string, unknown>

List of arguments to be used in the given statement

Hide ParametersShow Parameters
Array<unknown>
Record<string, unknown>
sqlstring

SQL statement, with ? placeholders for arguments

modeunion
optional
"write" | "read" | "deferred"
Hide ParametersShow Parameters
"write"
"read"
"deferred"
Returns
SqliteBatchResponsealias
Array<columnsarraycolumnTypesarrayrowsarrayrowsAffectednumberlastInsertRowidunionResultSet>

Array of results from the statements executed

Hide ParametersShow Parameters
columnsarray
Array<string>

Names of columns.

Names of columns can be defined using the AS keyword in SQL:

SELECT author AS author, COUNT(*) AS count FROM books GROUP BY author
columnTypesarray
Array<string>

Types of columns.

The types are currently shown for types declared in a SQL table. For column types of function calls, for example, an empty string is returned.

rowsarray
Array<Array<unknown>>

Rows produced by the statement.

rowsAffectednumber

Number of rows that were affected by an UPDATE, INSERT or DELETE operation.

This value is not specified for other SQL statements.

lastInsertRowidunion
optional
string | number | null

ROWID of the last inserted row.

This value is not specified if the SQL statement was not an INSERT or if the table was not a ROWID table.

Hide ParametersShow Parameters
string
number
import ValTown from '@valtown/sdk';

const client = new ValTown({
  bearerToken: 'My Bearer Token',
});

const resultSets = await client.sqlite.batch({ statements: ['SELECT 1;'], mode: 'read' });

console.log(resultSets);
200 Example
[
  {
    "columns": [
      "string"
    ],
    "columnTypes": [
      "string"
    ],
    "rows": [
      [
        {}
      ]
    ],
    "rowsAffected": 0,
    "lastInsertRowid": "string"
  }
]