- Retrieve database credentials
- Install the libSQL package
- Connect to a local or remote Turso database
- Execute a query using SQL
- Sync changes to local database (optional)
Retrieve database credentials
You will need an existing database to continue. If you don’t have one, create one.Get the database URL:Get the database authentication token:Assign credentials to the environment variables inside
.env.You will want to make sure to handle database tokens securely.
Install
To use libSQL with C, you need to build the library from source:After building, make sure to link against the library when compiling your C program:
libSQL C
Build from source code
Connect
You must first initialize libSQL, create a
libsql_database_t object, and then open a libsql_connection_t to it:Embedded Replicas
Embedded Replicas
Local only
Local only
Remote only
Remote only
Execute
You can execute a SQL query against your existing database by preparing a statement and then executing it:If you need to use placeholders for values, you can do that: