libSQL JavaScript and TypeScript Reference
@libsql/client
dependency in your project:
createClient
to initialize a client that you can use to query your database:
authToken
.createClient
:
@libsql/client/web
does not support local file URLs.syncUrl
:
sync()
function allows you to sync manually the local database with the remote counterpart:
syncInterval
(seconds) property when instantiating a new libSQL client:
encryptionKey
:
20
concurrent requests. You can set this option to a higher
number to increase the concurrency limit. You can also set this option to undefined
to disable concurrency
completely:
Promise<ResultSet>
:
Property | Type | Description |
---|---|---|
rows | Array<Row> | An array of Row objects containing the row values, empty for write operations |
columns | Array<string> | An array of strings with the names of the columns in the order they appear in each Row, empty for write operations |
rowsAffected | number | The number of rows affected by a write statement, 0 otherwise |
lastInsertRowid | bigint | undefined | The ID of a newly inserted row, or undefined if there is none for the statement |
execute()
to invoke a SQL statement:
:
, @
and $
.Mode | SQLite command | Description |
---|---|---|
write | BEGIN IMMEDIATE | The transaction may execute statements that read and write data. Write transactions executed on a replica are forwarded to the primary instance, and can’t operate in parallel. |
read | BEGIN TRANSACTION READONLY | The transaction may only execute statements that read data (select). Read transactions can occur on replicas, and can operate in parallel with other read transactions. |
deferred | BEGIN DEFERRED | The transaction starts in read mode, then changes to write as soon as a write statement is executed. This mode change may fail if there is a write transaction currently executing on the primary. |
Method | Description |
---|---|
execute() | Similar to execute() except within the context of the transaction |
commit() | Commits all write statements in the transaction |
rollback() | Rolls back the entire transaction |
close() | Immediately stops the transaction |
ATTACH
attachment:
ATTACH
and create a token
with the permission to attach a database — learn
more