Turso Databases can be accessed via HTTP. The API enable developers to perform SQL operations using the libSQL remote protocol, retrieve server version information, and monitor the health status.
You can use the /v2/pipeline endpoint to query a database. The endpoint accepts a series of operations to perform against a database connection. The supported operation types are:
Connections are left open until they timeout, unless you close them explicitly in the request (as shown above). Every request made on a connection bumps the timeout. You should close the connection when it’s no longer needed.
Positional query parameters, bound by their position in the parameter list, and prefixed ?. If the query uses positional parameters, the values should be provided as an array to the args field.
Named bound parameters, where the parameter is referred to by a name and is prefixed with a :, a @ or a $. If the query uses named parameters, then the named_args field of the query should be an array of objects mapping parameters to their values.
Copy
{ "requests": [ { "type": "execute", "stmt": { "sql": "SELECT * FROM users WHERE name = :name OR name = $second_name OR name = @third_name", "named_args": [ { "name": "name", "value": { "type": "text", "value": "Turso" } }, { "name": "second_name", "value": { "type": "text", "value": "Not Turso" } }, { "name": "third_name", "value": { "type": "text", "value": "Maybe Turso" } } ] } }, { "type": "close" } ]}
The name property of each named_args can match the prefix or omit the prefix. They were omitted in the example above, but both versions are valid.The type field within each arg corresponds to the column datatype and can be one of the following: null, integer, float, text, or blob.
If using the blob type, replace the value property with base64 and encode the argument into base64 before sending the request.
In JSON, the value is a String to avoid losing precision, because some
JSON implementations treat all numbers as 64-bit floats.
Sometimes, it may be desirable to perform multiple operation on the same connection, in multiple roundtrips. We can do this by not closing the connection right away:
We can see that we have received a baton back. This is because we haven’t closed the connection. We can now use this baton to perform more queries on the same connection:
Note that both transactions and connections have timeouts. Transaction have a 5 seconds window to complete, while connections get closed after 10 seconds of idle time.
Turso provides a managed multi-tenant schema system — Multi-DB Schemas. This feature allows you to create a single database that shares its schema automatically with any related child databases. Changes to the parent database automatically propogate to the related databases.The /v1/jobs endpoint lets you monitor the status of schema migrations.
Currently not available on AWS for Free, Developer and Scaler plans.