Skip to content

libsqlBatch

Person edited this page Nov 13, 2023 · 9 revisions

This function executes SQL queries in a batch.

Definition

async function libsqlBatch(conf: libsqlConfig, batch_steps: Array<libsqlBatchReqStep>): Promise<libsqlResult<libsqlBatchStreamResOkData, libsqlError>>

Arguments

Returns

Type

Promise<libsqlResult<libsqlBatchStreamResOkData, libsqlError>>

Reference: libsqlResult, libsqlBatchStreamResOkData, libsqlError

Examples

import { libsqlBatch } from "libsql-stateless";
//or
const { libsqlBatch } = require("libsql-stateless");

const res = await libsqlBatch(conf, [
    {stmt: {sql: "SELECT * FROM mad_cats;"}},
    {stmt: {
        sql: "SELECT madness, power_level FROM mad_cats WHERE cat_id = ? AND owner_name = ?;",
        args: [
            {
                type: "integer",
                value: "89342"
            },
            {
                type: "text",
                value: "John Smith"
            }
        ]
    }},
    {stmt: {
    sql: "INSERT INTO mad_cats VALUES (:cat_name, :power_level, :madness);", //In SQLite, the names of arguments include the prefix sign (:, @ or $).
    named_args: [
            {
                name: "cat_name",
                value: {
                    type: "text",
                    value: "Bgorthe, The Destroyer of Worlds"
                }
            },
            {
                name: "power_level",
                value: {
                    type: "integer",
                    value: "9105"
                }
            },
            {
                name: "madness",
                value: {
                    type: "float",
                    value: "32.5"
                }
            }
        ]
    }}
]);
//or
const res = await libsqlBatch(conf, [
    {stmt: {sql: "SELECT * FROM mad_cats;"}, condition: { "type": "is_autocommit" }}
]);


if (res.isOk) {
    console.log(res.val.step_results);
    console.log(res.val.step_results[0].rows);
    console.log(res.val.step_results[0].rows[0]);
}
Clone this wiki locally