Swift Reference
libSQL Swift Reference
This is currently in technical preview. Join us in Discord to report any issues.
Installing
First begin by adding libsql
as a package dependency in XCode using this repo:
libSQL Swift
Build from source code
Or add it to your SwiftPM dependencies:
In-Memory Databases
libSQL supports connecting to in-memory databases for cases where you don’t require persistence:
Local Development
You can work locally using an SQLite file:
Embedded Replicas
You can work with embedded replicas that can sync from the remote URL and delegate writes to the remote primary database:
Manual Sync
The sync
function allows you to sync manually the local database with the remote counterpart:
Sync Interval
The syncInterval
parameter allows you to set an interval for automatic
synchronization of the database in the background:
Read Your Own Writes
The readYourWrites
parameter configures the database connection to ensure
that writes are immediately visible to subsequent read operations initiated by
the same connection. This is enabled by default, and is particularly
important in distributed systems to ensure consistency from the perspective of
the writing process.
You can disable this behavior by passing false
to the function:
Simple query
You can pass a string to query()
to invoke a SQL statement, as well as
optional arguments:
Prepared Statements
You can prepare a cached statement using prepare()
and then execute it with
query()
:
Placeholders
libSQL supports the use of positional and named placeholders within SQL statements:
Was this page helpful?