2023-01-03 22:15:49 +02:00
# `sqld` - a server mode for libSQL
2022-11-12 17:38:59 +02:00
2023-05-17 09:25:42 -04:00
The `sqld` ("SQL daemon") project is a server mode for
[libSQL ](https://github.com/libsql/libsql/ ).
2022-11-13 10:41:10 +02:00
2023-05-17 09:25:42 -04:00
Embedded SQL databases such as libSQL and SQLite are great for a lot of use
cases, but sometimes you really do want to consume your database as a server.
For example, with apps running on serverless infrastructure, fitting a database
engine might be difficult given the limited size of the hardware. And even when
it's _possible_ , it might be really inconvenient. We created `sqld` for this use
case.
2023-03-10 09:01:03 +02:00
2023-01-03 22:15:49 +02:00
## Features
2022-11-13 10:41:10 +02:00
2023-05-17 09:25:42 -04:00
* SQLite dialect layered on top of HTTP.
* SQLite-compatible API that you can drop-in with `LD_PRELOAD` in your
application to switch from local database to a remote database.
2023-01-06 13:44:44 +02:00
* Read replica support.
2023-05-17 09:25:42 -04:00
* Integration with [mvSQLite ](https://github.com/losfair/mvsqlite ) for high
availability and fault tolerance.
2023-01-05 10:01:01 +02:00
2023-05-17 09:25:42 -04:00
## Build and run
2022-11-12 17:38:59 +02:00
2023-11-20 16:56:35 -05:00
Follow the [instructions ](../docs/BUILD-RUN.md ) to build and run `sqld`
2023-05-17 09:25:42 -04:00
using Homebrew, Docker, or your own Rust toolchain.
2022-12-14 13:20:59 +02:00
2023-11-30 17:39:58 -05:00
## Tests
Run the command below to run all tests for `libsql` and `libsql-server` .
```
cargo xtask test
```
2023-05-17 09:25:42 -04:00
## Client libraries
2023-01-20 19:26:07 -05:00
2023-05-17 09:25:42 -04:00
The following client libraries enable your app to query `sqld` programmatically:
2023-01-20 19:26:07 -05:00
2023-05-17 09:25:42 -04:00
* [TypeScript and JavaScript ](https://github.com/libsql/libsql-client-ts )
* [Rust ](https://github.com/libsql/libsql-client-rs )
* [Go ](https://github.com/libsql/libsql-client-go )
* [Python ](https://github.com/libsql/libsql-client-py )
2023-01-20 19:26:07 -05:00
2023-05-17 09:25:42 -04:00
## SQLite extensions support
2023-04-27 16:10:25 -04:00
2023-05-17 09:25:42 -04:00
Extensions must be preloaded at startup. To do that, add all of your extensions
to a directory, and add a file called `trusted.lst` with the `sha256sum` of each
file to that directory. For example:
2023-04-27 16:10:25 -04:00
```console
$ cat trusted.lst
04cd193d2547ff99d672fbfc6dcd7e0b220869a1ab867a9bb325f7374d168533 vector0.so
74f9029cbf6e31b155c097a273e08517eb4e56f2300dede65c801407b01eb248 vss0.so
5bbbe0f80dd7721162157f852bd5f364348eb504f9799ae521f832d44c13a3a1 crypto.so
731a8cbe150351fed02944a00ca586fc60d8f3814e4f83efbe60fcef62d4332b fuzzy.so
1dbe9e4e58c4b994a119f1b507d07eb7a4311a80b96482c979b3bc0defd485fb math.so
511bf71b0621977bd9575d71e90adf6d02967008e460066a33aed8720957fecb stats.so
ae7fff8412e4e66e7f22b9af620bd24074bc9c77da6746221a9aba9d2b38d6a6 text.so
9ed6e7f4738c2223e194c7a80525d87f323df269c04d155a769d733e0ab3b4d0 unicode.so
19106ded4fd3fd4986a5111433d062a73bcf9557e07fa6d9154e088523e02bb0 uuid.so
```
Extensions will be loaded in the order they appear on that file, so if there are
dependencies between extensions make sure they are listed in the proper order.
2023-05-17 09:25:42 -04:00
Then start the server with the `--extensions-path` option pointing at the
extension directory
2023-04-27 16:10:25 -04:00
2023-05-17 09:25:42 -04:00
## Integration with S3 bottomless replication
2023-04-27 16:10:25 -04:00
2023-05-17 09:25:42 -04:00
`sqld` is integrated with [bottomless replication subproject]. With bottomless
replication, the database state is continuously backed up to S3-compatible
storage. Each backup session is called a "generation" and consists of the main
database file snapshot and replicates [SQLite WAL] pages.
2023-02-07 10:40:39 +01:00
2023-07-05 13:24:28 +02:00
In order to enable automatic replication to S3 storage, compile `sqld` with `-F bottomless` flag
and run `sqld` with `--enable-bottomless-replication` parameter:
2023-02-07 10:40:39 +01:00
2023-05-17 09:25:42 -04:00
```bash
2023-02-07 10:40:39 +01:00
sqld --http-listen-addr=127.0.0.1:8000 --enable-bottomless-replication
```
2023-05-17 09:25:42 -04:00
[bottomless replication subproject]: ./bottomless
[SQLite WAL]: https://www.sqlite.org/wal.html
### Configuration
Replication needs to be able to access an S3-compatible bucket. The following
environment variables can be used to configure the replication:
```bash
2023-02-07 10:40:39 +01:00
LIBSQL_BOTTOMLESS_BUCKET=my-bucket # Default bucket name: bottomless
LIBSQL_BOTTOMLESS_ENDPOINT='http://localhost:9000' # address can be overridden for local testing, e.g. with Minio
2023-09-05 16:23:14 +02:00
LIBSQL_BOTTOMLESS_AWS_SECRET_ACCESS_KEY= # regular AWS variables are used
LIBSQL_BOTTOMLESS_AWS_ACCESS_KEY_ID= # ... to set up auth, regions, etc.
LIBSQL_BOTTOMLESS_AWS_REGION= # .
2023-02-07 10:40:39 +01:00
```
2023-05-17 09:25:42 -04:00
### bottomless-cli
2023-01-20 19:26:07 -05:00
2023-05-17 09:25:42 -04:00
Replicated snapshots can be inspected and managed with the official command-line
interface.
2023-01-20 19:26:07 -05:00
2023-05-17 09:25:42 -04:00
The tool can be installed via `cargo` :
2022-12-14 13:20:59 +02:00
2023-05-17 09:25:42 -04:00
```bash
RUSTFLAGS='--cfg uuid_unstable' cargo install bottomless-cli
2022-12-14 13:20:59 +02:00
```
2023-05-17 09:25:42 -04:00
For usage examples and description, refer to the [bottomless-cli
documentation].
2022-12-14 13:20:59 +02:00
2023-05-17 09:25:42 -04:00
[bottomless-cli documentation]: ./bottomless#cli
2023-01-03 22:15:49 +02:00
## License
This project is licensed under the MIT license.
### Contribution
2023-01-03 22:29:55 +02:00
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in `sqld` by you, shall be licensed as MIT, without any additional terms or conditions.