Turso Quickstart (Android)
Get started with Turso and Android using the libSQL client in a few simple steps.
This is currently in technical preview. Join us in Discord to report any issues.
This will only work with the Android Gradle Plugin for now. Fully Kotlin support is coming.
In this Kotlin quickstart we will learn how to:
- Retrieve database credentials
- Add libSQL as a dependency in your Android Gradle project
- 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
.
Install
Add libsql as a implementation dependency in Gradle:
This will only work with the Android Gradle Plugin for now.
Connect
You must first create a Database
object and then open a Connection
to it:
Execute
You can execute a SQL query against your existing database by calling execute()
:
If you need to use placeholders for values, you can do that:
Sync (Embedded Replicas only)
When using embedded replicas you should call sync()
on the database type to
sync your local database with the primary database, unless you are using
syncInterval
(though there is no issue with calling sync
with
syncInterval
enabled):
Was this page helpful?