- Obtain HTTP URL for a Turso database
- Create a database auth token
- Connect to a remote Turso database
- Execute a SQL using the libSQL remote protocol
1
Create HTTP Database URL
Using the Turso CLI or Platform API, fetch your database URL:
Append
/v2/pipeline
to the URL and continue.2
Create Database Auth Token
Using the Turso CLI or Platform API, create a new auth token for your database:
3
Create JSON Request Payload
We’ll be sending the query using JSON, so let’s create a JSON payload that executes a SQL statement and closes the connection immediately:
Make sure to update the
stmt.sql
to select from a table you already have.Bound parameter examples included on the Reference Page,4
Execute HTTP Request
Depending on your language, you can use a HTTP client library to send the request to the URL you created as well as the
If you need to use placeholders for values, you can do that:
Authorization
header set to the token you created, and the request body as JSON with your SQL statement.You must append to the Base URL the actual pipeline URL that accepts requests — /v2/pipeline
.Response
Response
The response will be a JSON object with a
results
array containing the results of your query that looks something like this:The
type
field within each arg corresponds to the column datatype and can be one of the following: null
, integer
, float
, text
, or blob
.In JSON, the
value
is a String
to avoid losing precision, because some
JSON implementations treat all numbers as 64-bit floats.