database/sql to provide the usual methods you’d expect when working with databases in Go.
In this Go quickstart we will learn how to:
- Retrieve database credentials
- Install Go libSQL
- Connect to a local or remote Turso database
- Execute a query using SQL
- Sync changes to local database
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 store these as environment variables.
Connect
Now connect to your local or remote database using the libSQL connector:
Local only
Local only
Starting a new project? Consider using Turso Database for Go — it offers concurrent writes, vector search, and a modern async engine built on the next evolution of SQLite.
Remote only
Remote only
Execute
You can execute a SQL query against your existing database. Create a function to query your database that accepts the pointer to Now inside
sql.DB as an argument:func main() call queryUsers and pass in the pointer to sql.DB:Sync
If you need to sync your local database with a remote Turso Cloud database (local reads and writes with push/pull to the cloud), use Turso Sync. Turso Sync is built on the Turso Database engine and provides true local-first sync with explicit
push() and pull() operations.