Installing
Install the package to your project using composer:Initializing
Make sure to adduse Libsql\Database
to access the Database
object.
In-Memory Databases
libSQL supports connecting to in-memory databases for cases where you don’t require persistence:Local Development
You can work locally by passing a path as the first parameter.Remote Only
You can use a remote only database by passingurl
and authToken
.
Embedded Replicas
You can work with embedded replicas by passing apath
, url
and authToken
.
Embedded replicas can sync from the remote URL and delegate writes to the
remote primary database:
Sync Interval
Thesync_interval
function allows you to set an interval for automatic synchronization of the database in the background:
Manual Sync
Thesync
function allows you to sync manually the local database with the
remote counterpart:
Read Your Own Writes
ThereadYourWrites
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
:
Simple Query
You can acquire a connection from a database and callquery()
to invoke a
SQL statement, as well as optional arguments:
Prepared Statements
You can prepare a cached statement usingprepare()
, bind parameters, and then
query it: