diff --git a/.github/workflows/pr-images.yml b/.github/workflows/pr-images.yml index 971fe359..41b5668b 100644 --- a/.github/workflows/pr-images.yml +++ b/.github/workflows/pr-images.yml @@ -1,4 +1,4 @@ -name: Create and publish sqld binaried and Docker image +name: Create and publish libsql-server binaried and Docker image on: pull_request: diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 089afebf..3a188e9a 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,4 +1,4 @@ -name: Create and publish sqld binaried and Docker image +name: Create and publish libsql-server binaried and Docker image on: push: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c01c2ba7..f8a43dcd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -159,7 +159,7 @@ jobs: steps: - uses: actions/checkout@v3 with: - repository: "libsql/homebrew-sqld" + repository: "libsql/homebrew-libsql" token: ${{ secrets.HOMEBREW_TAP_TOKEN }} # So we have access to the formula - name: Fetch local artifacts diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index b22fe907..476a1500 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -108,7 +108,7 @@ jobs: submodules: recursive - name: Test openssl shell: bash {0} - run: cargo tree -p sqld -i openssl; [ $? = 101 ] + run: cargo tree -p libsql-server -i openssl; [ $? = 101 ] docker: runs-on: ubuntu-latest @@ -126,4 +126,4 @@ jobs: uses: docker/build-push-action@v3 with: context: . - tags: sqld:unstable + tags: libsql-server:unstable diff --git a/Cargo.lock b/Cargo.lock index ca2aa06e..34ff7d4c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -776,8 +776,8 @@ dependencies = [ "chrono", "crc", "futures", + "libsql-bindings", "rand", - "sqld-libsql-bindings", "tokio", "tokio-util", "tracing", @@ -2382,6 +2382,16 @@ dependencies = [ "libc", ] +[[package]] +name = "libsql-bindings" +version = "0.1.0" +dependencies = [ + "anyhow", + "once_cell", + "rusqlite", + "tracing", +] + [[package]] name = "libsql-client" version = "0.6.7" @@ -2397,6 +2407,85 @@ dependencies = [ "url", ] +[[package]] +name = "libsql-server" +version = "0.20.3" +dependencies = [ + "anyhow", + "arbitrary", + "async-lock", + "async-trait", + "aws-config", + "aws-sdk-s3", + "axum", + "axum-extra", + "base64 0.21.4", + "bincode", + "bottomless", + "bytemuck", + "bytes 1.5.0", + "bytesize", + "chrono", + "clap", + "console-subscriber", + "crc", + "crossbeam", + "enclose", + "env_logger", + "fallible-iterator 0.3.0", + "futures", + "futures-core", + "hmac", + "hyper", + "hyper-rustls 0.24.1 (git+https://github.com/rustls/hyper-rustls.git?rev=163b3f5)", + "hyper-tungstenite", + "insta", + "itertools 0.10.5", + "jsonwebtoken", + "libsql-bindings", + "libsql-client", + "memmap", + "mimalloc", + "nix", + "once_cell", + "parking_lot", + "pin-project-lite", + "priority-queue", + "proptest", + "prost", + "prost-build", + "protobuf-src", + "rand", + "regex", + "reqwest", + "rusqlite", + "rustls 0.21.7", + "rustls-pemfile", + "semver", + "serde", + "serde_json", + "sha2", + "sha256", + "sqlite3-parser", + "tempfile", + "thiserror", + "tokio", + "tokio-stream", + "tokio-tungstenite", + "tokio-util", + "tonic", + "tonic-build", + "tonic-web", + "tower", + "tower-http 0.3.5", + "tracing", + "tracing-panic", + "tracing-subscriber", + "url", + "uuid", + "vergen", +] + [[package]] name = "libsql-wasmtime-bindings" version = "0.2.2" @@ -3764,95 +3853,6 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" -[[package]] -name = "sqld" -version = "0.20.3" -dependencies = [ - "anyhow", - "arbitrary", - "async-lock", - "async-trait", - "aws-config", - "aws-sdk-s3", - "axum", - "axum-extra", - "base64 0.21.4", - "bincode", - "bottomless", - "bytemuck", - "bytes 1.5.0", - "bytesize", - "chrono", - "clap", - "console-subscriber", - "crc", - "crossbeam", - "enclose", - "env_logger", - "fallible-iterator 0.3.0", - "futures", - "futures-core", - "hmac", - "hyper", - "hyper-rustls 0.24.1 (git+https://github.com/rustls/hyper-rustls.git?rev=163b3f5)", - "hyper-tungstenite", - "insta", - "itertools 0.10.5", - "jsonwebtoken", - "libsql-client", - "memmap", - "mimalloc", - "nix", - "once_cell", - "parking_lot", - "pin-project-lite", - "priority-queue", - "proptest", - "prost", - "prost-build", - "protobuf-src", - "rand", - "regex", - "reqwest", - "rusqlite", - "rustls 0.21.7", - "rustls-pemfile", - "semver", - "serde", - "serde_json", - "sha2", - "sha256", - "sqld-libsql-bindings", - "sqlite3-parser", - "tempfile", - "thiserror", - "tokio", - "tokio-stream", - "tokio-tungstenite", - "tokio-util", - "tonic", - "tonic-build", - "tonic-web", - "tower", - "tower-http 0.3.5", - "tracing", - "tracing-panic", - "tracing-subscriber", - "url", - "uuid", - "vergen", -] - -[[package]] -name = "sqld-libsql-bindings" -version = "0.1.0" -dependencies = [ - "anyhow", - "once_cell", - "rusqlite", - "tracing", -] - [[package]] name = "sqlite3-parser" version = "0.11.0" diff --git a/Cargo.toml b/Cargo.toml index 53ec3579..f7f63213 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,8 +3,8 @@ members = [ "bottomless", "bottomless-cli", - "sqld", - "sqld-libsql-bindings", + "libsql-server", + "libsql-bindings", "testing/end-to-end", ] diff --git a/Dockerfile b/Dockerfile index 07841bce..fb5818fc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -# build sqld +# build libsql-server FROM rust:slim-bullseye AS chef RUN apt update \ && apt install -y libclang-dev clang \ @@ -23,18 +23,18 @@ FROM chef AS builder COPY --from=planner /recipe.json recipe.json RUN cargo chef cook --release --recipe-path recipe.json COPY . . -RUN cargo build -p sqld --release +RUN cargo build -p libsql-server --release # runtime FROM debian:bullseye-slim -COPY --from=builder /target/release/sqld /bin/sqld -RUN groupadd --system --gid 666 sqld -RUN adduser --system --home /var/lib/sqld --uid 666 --gid 666 sqld +COPY --from=builder /target/release/libsql-server /bin/libsql-server +RUN groupadd --system --gid 666 libsql-server +RUN adduser --system --home /var/lib/libsql-server --uid 666 --gid 666 libsql-server RUN apt-get update && apt-get install -y ca-certificates COPY docker-entrypoint.sh /usr/local/bin ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] -VOLUME [ "/var/lib/sqld" ] -WORKDIR /var/lib/sqld -USER sqld +VOLUME [ "/var/lib/libsql-server" ] +WORKDIR /var/lib/libsql-server +USER libsql-server EXPOSE 5001 8080 -CMD ["/bin/sqld"] +CMD ["/bin/libsql-server"] diff --git a/Dockerfile.dev b/Dockerfile.dev index 02c4e0d7..ab31f36b 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -1,4 +1,4 @@ -# build sqld +# build libsql-server FROM rust:slim-bullseye as builder RUN apt update @@ -9,31 +9,31 @@ RUN apt install -y libclang-dev clang \ RUN apt clean RUN update-ca-certificates -WORKDIR /sqld +WORKDIR /libsql-server COPY . . RUN --mount=type=cache,target=/usr/local/cargo/registry \ --mount=type=cache,target=/usr/local/cargo/git \ - --mount=type=cache,target=/sqld/target \ - cargo build -p sqld --release && \ - cp target/release/sqld /sqld/bin + --mount=type=cache,target=/libsql-server/target \ + cargo build -p libsql-server --release && \ + cp target/release/libsql-server /libsql-server/bin # runtime FROM debian:bullseye-slim RUN apt update -COPY --from=builder /sqld/bin /bin/sqld +COPY --from=builder /libsql-server/bin /bin/libsql-server COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt COPY docker-entrypoint.sh /usr/local/bin -VOLUME [ "/var/lib/sqld" ] +VOLUME [ "/var/lib/libsql-server" ] -RUN groupadd --system --gid 666 sqld -RUN adduser --system --home /var/lib/sqld --uid 666 --gid 666 sqld -USER sqld -WORKDIR /var/lib/sqld +RUN groupadd --system --gid 666 libsql-server +RUN adduser --system --home /var/lib/libsql-server --uid 666 --gid 666 libsql-server +USER libsql-server +WORKDIR /var/lib/libsql-server EXPOSE 5001 8080 ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] -CMD ["/bin/sqld"] +CMD ["/bin/libsql-server"] diff --git a/LICENSE.md b/LICENSE.md index fd1a31ee..7059e521 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ MIT License -Copyright 2023 the sqld authors +Copyright 2023 the libsql-server authors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/README.md b/README.md index 5f86e636..ff31c8b3 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ -# `sqld` - a server mode for libSQL +# `Libsql-server` - a server mode for libSQL -The `sqld` ("SQL daemon") project is a server mode for +The `libsql-server` project is a server mode for [libSQL](https://github.com/libsql/libsql/). 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 +it's _possible_, it might be really inconvenient. We created `libsql-server` for this use case. ## Features @@ -21,12 +21,12 @@ case. ## Build and run -Follow the [instructions](./docs/BUILD-RUN.md) to build and run `sqld` +Follow the [instructions](./docs/BUILD-RUN.md) to build and run `libsql-server` using Homebrew, Docker, or your own Rust toolchain. ## Client libraries -The following client libraries enable your app to query `sqld` programmatically: +The following client libraries enable your app to query `libsql-server` programmatically: * [TypeScript and JavaScript](https://github.com/libsql/libsql-client-ts) * [Rust](https://github.com/libsql/libsql-client-rs) @@ -60,16 +60,16 @@ extension directory ## Integration with S3 bottomless replication -`sqld` is integrated with [bottomless replication subproject]. With bottomless +`libsql-server` 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. -In order to enable automatic replication to S3 storage, compile `sqld` with `-F bottomless` flag -and run `sqld` with `--enable-bottomless-replication` parameter: +In order to enable automatic replication to S3 storage, compile `libsql-server` with `-F bottomless` flag +and run `libsql-server` with `--enable-bottomless-replication` parameter: ```bash -sqld --http-listen-addr=127.0.0.1:8000 --enable-bottomless-replication +libsql-server --http-listen-addr=127.0.0.1:8000 --enable-bottomless-replication ``` [bottomless replication subproject]: ./bottomless @@ -110,4 +110,4 @@ This project is licensed under the MIT license. ### Contribution -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. +Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in `libsql-server` by you, shall be licensed as MIT, without any additional terms or conditions. diff --git a/bottomless/Cargo.toml b/bottomless/Cargo.toml index 312eda77..d87c854b 100644 --- a/bottomless/Cargo.toml +++ b/bottomless/Cargo.toml @@ -16,7 +16,7 @@ aws-sdk-s3 = { version = "0.28" } bytes = "1" crc = "3.0.0" futures = { version = "0.3.25" } -sqld-libsql-bindings = { version = "0", path = "../sqld-libsql-bindings" } +libsql-bindings = { version = "0", path = "../libsql-bindings" } tokio = { version = "1.22.2", features = ["rt-multi-thread", "net", "io-std", "io-util", "time", "macros", "sync", "fs"] } tokio-util = "0.7" tracing = "0.1.37" diff --git a/bottomless/src/ffi.rs b/bottomless/src/ffi.rs index e8dd2239..6228516f 100644 --- a/bottomless/src/ffi.rs +++ b/bottomless/src/ffi.rs @@ -1,4 +1,4 @@ -pub use sqld_libsql_bindings::ffi::{ +pub use libsql_bindings::ffi::{ libsql_wal_methods, sqlite3, sqlite3_file, sqlite3_vfs, PageHdrIter, PgHdr, Wal, WalIndexHdr, SQLITE_CANTOPEN, SQLITE_CHECKPOINT_TRUNCATE, SQLITE_IOERR_WRITE, SQLITE_OK, }; diff --git a/docs/BUILD-RUN.md b/docs/BUILD-RUN.md index 243bb41d..7c69becf 100644 --- a/docs/BUILD-RUN.md +++ b/docs/BUILD-RUN.md @@ -1,6 +1,6 @@ -# Build and run sqld +# Build and run libsql-server -There are four ways to build and run sqld: +There are four ways to build and run libsql-server: - [Download a prebuilt binary](#download-a-prebuilt-binary) - [Using Homebrew](#build-and-install-with-homebrew) @@ -8,78 +8,78 @@ There are four ways to build and run sqld: - [From source using Docker/Podman](#build-from-source-using-docker--podman) - [From source using Rust](#build-from-source-using-rust) -## Running sqld +## Running libsql-server You can simply run launch the executable with no command line arguments to run -an instance of sqld. By default, sqld listens on 127.0.0.1 port 8080 and +an instance of libsql-server. By default, libsql-server listens on 127.0.0.1 port 8080 and persists database data in a directory `./data.sqld`. Use the `--help` flag to discover how to change its runtime behavior. -## Query sqld +## Query libsql-server -You can query sqld using one of the provided [client +You can query libsql-server using one of the provided [client libraries](../#client-libraries). You can also use the sqlite3 CLI to query the SQLite 3 compatible database file -managed by sqld. +managed by libsql-server. ```bash sqlite3 ./data.sqld/data ``` -Be sure to stop sqld before using `sqlite3` like this. +Be sure to stop libsql-server before using `sqlite3` like this. ## Download a prebuilt binary -The [sqld releases page] for this repository lists released versions of sqld +The [libsql-server releases page] for this repository lists released versions of libsql-server along with downloads for macOS and Linux. ## Build and install with Homebrew -The sqld formulae for Homebrew works with macOS, Linux (including WSL). +The libsql-server formulae for Homebrew works with macOS, Linux (including WSL). -### 1. Add the tap `libsql/sqld` to Homebrew +### 1. Add the tap `libsql/libsql-server` to Homebrew ```bash -brew tap libsql/sqld +brew tap libsql/libsql-server ``` -### 2. Install the formulae `sqld` +### 2. Install the formulae `libsql-server` ```bash -brew install sqld +brew install libsql-server ``` -This builds and installs the binary `sqld` into `$HOMEBREW_PREFIX/bin/sqld`, +This builds and installs the binary `libsql-server` into `$HOMEBREW_PREFIX/bin/libsql-server`, which should be in your PATH. -### 3. Verify that `sqld` works +### 3. Verify that `libsql-server` works ```bash -sqld --help +libsql-server --help ``` ## Using a prebuilt Docker image -The sqld release process publishes a Docker image to the GitHub Container -Registry. The URL is https://ghcr.io/libsql/sqld. You can run the latest image locally +The libsql-server release process publishes a Docker image to the GitHub Container +Registry. The URL is https://ghcr.io/libsql/libsql-server. You can run the latest image locally on port 8080 with the following: ```bash -docker run -p 8080:8080 -d ghcr.io/libsql/sqld:latest +docker run -p 8080:8080 -d ghcr.io/libsql/libsql-server:latest ``` -Or you can run a specific version using one of the [sqld container release +Or you can run a specific version using one of the [libsql-server container release tags] in the following form for version X.Y.Z: ```bash -docker run -p 8080:8080 -d ghcr.io/libsql/sqld:vX.Y.Z +docker run -p 8080:8080 -d ghcr.io/libsql/libsql-server:vX.Y.Z ``` ## Build from source using Docker / Podman -To build sqld with Docker, you must have a Docker [installed] and running on +To build libsql-server with Docker, you must have a Docker [installed] and running on your machine with its CLI in your shell PATH. [installed]: https://docs.docker.com/get-docker/ @@ -87,72 +87,72 @@ your machine with its CLI in your shell PATH. ### 1. Clone this repo Clone this repo using your preferred mechanism. You may want to use one of the -[sqld release tags]. +[libsql-server release tags]. -Change to the `sqld` directory. +Change to the `libsql-server` directory. ### 2. Build with Docker -Run the following to build a Docker image named "libsql/sqld" tagged with +Run the following to build a Docker image named "libsql/libsql-server" tagged with version "latest". ```bash -docker build -t libsql/sqld:latest . +docker build -t libsql/libsql-server:latest . ``` ### 3. Verify the build -Check that sqld built successfully using its --help flag: +Check that libsql-server built successfully using its --help flag: ```bash docker container run \ --rm \ -i \ - libsql/sqld \ - /bin/sqld --help + libsql/libsql-server \ + /bin/libsql-server --help ``` ### 4. Create a data volume -The following will create a volume named `sqld-data` that sqld uses to persist +The following will create a volume named `libsql-data` that libsql-server uses to persist database files. ```bash -docker volume create sqld-data +docker volume create libsql-data ``` -### 5. Run sqld in a container +### 5. Run libsql-server in a container The following uses the built image to create and run a new container named -`sqld`, attaching the `sqld-data` volume to it, and exposing its port 8080 +`libsql-server`, attaching the `libsql-data` volume to it, and exposing its port 8080 locally: ```bash docker container run \ -d \ - --name sqld \ - -v sqld-data:/var/lib/sqld \ + --name libsql-server \ + -v libsql-data:/var/lib/libsql-server\ -p 127.0.0.1:8080:8080 \ - libsql/sqld:latest + libsql/libsql-server:latest ``` -8080 is the default port for the sqld HTTP service that handles client queries. +8080 is the default port for the libsql-server HTTP service that handles client queries. With this container running, you can use the URL `http://127.0.0.1:8080` or `ws://127.0.0.1:8080` to configure one of the libSQL client SDKs for local development. -### 6. Configure sqld with environment variables +### 6. Configure libsql-server with environment variables -In the sqld output using `--help` from step 3, you saw the names of command line +In the libsql-server output using `--help` from step 3, you saw the names of command line flags along with the names of environment variables (look for "env:") used to -configure the way sqld works. +configure the way libsql-server works. ## Build from source using Rust To build from source, you must have a Rust development environment installed and available in your PATH. -Currently we only support building sqld on macOS and Linux (including WSL). We +Currently we only support building libsql-server on macOS and Linux (including WSL). We are working native Windows build instructions. ### 1. Setup @@ -166,9 +166,9 @@ Install dependencies: ### 2. Clone this repo Clone this repo using your preferred mechanism. You may want to use one of the -[sqld release tags]. +[libsql-server release tags]. -Change to the `sqld` directory. +Change to the `libsql-server` directory. Install git submodules: @@ -182,28 +182,28 @@ git submodule update --init --force --recursive --depth 1 cargo build ``` -The sqld binary will be in `./target/debug/sqld`. +The libsql-server binary will be in `./target/debug/libsql-server`. ### 4. Verify the build -Check that sqld built successfully using its --help flag: +Check that libsql-server built successfully using its --help flag: ```bash -./target/debug/sqld --help +./target/debug/libsql-server --help ``` -### 5. Run sqld with all defaults +### 5. Run libsql-server with all defaults -The following starts sqld, taking the following defaults: +The following starts libsql-server, taking the following defaults: - Local files stored in the directory `./data.sqld` - Client HTTP requests on 127.0.0.1:8080 ```bash -./target/debug/sqld +./target/debug/libsql-server ``` -8080 is the default port for the sqld HTTP service that handles client queries. +8080 is the default port for the libsql-server HTTP service that handles client queries. With this container running, you can use the URL `http://127.0.0.1:8080` or `ws://127.0.0.1:8080` to configure one of the libSQL client SDKs for local development. @@ -213,8 +213,6 @@ development. ```console make test ``` - - -[sqld releases page]: https://github.com/libsql/sqld/releases -[sqld container release tags]: https://github.com/libsql/sqld/pkgs/container/sqld -[sqld release tags]: https://github.com/libsql/sqld/releases +[libsql-server releases page]: https://github.com/libsql/libsql-server/releases +[libsql-server container release tags]: https://github.com/libsql/libsql-server/pkgs/container/libsql-server +[libsql-server release tags]: https://github.com/libsql/libsql-server/releases diff --git a/docs/CONSISTENCY_MODEL.md b/docs/CONSISTENCY_MODEL.md index 711c731e..35efa828 100644 --- a/docs/CONSISTENCY_MODEL.md +++ b/docs/CONSISTENCY_MODEL.md @@ -1,17 +1,17 @@ -# Sqld consistency model +# Libsql-server consistency model ## Building on top of sqlite -sqlite offers a strictly serializable consistency model. Since sqld is built on top of it, it inherits some of its properties. +sqlite offers a strictly serializable consistency model. Since libsql-server is built on top of it, it inherits some of its properties. ## Transactional consistency -Any transaction in sqld is equivalent to sqlite transaction. When a transaction is opened, on the primary or replicas alike, the view that the transaction get is "frozen" is time. any write performed by a transaction is at the same time immediately visible to itself, as well as completely isolated from any other ongoing transactions. Therefore, sqld offers serializable transactions +Any transaction in libsql-server is equivalent to sqlite transaction. When a transaction is opened, on the primary or replicas alike, the view that the transaction get is "frozen" is time. any write performed by a transaction is at the same time immediately visible to itself, as well as completely isolated from any other ongoing transactions. Therefore, libsql-server offers serializable transactions ## Real-time guarantees -All operations occurring on the primary are linearizable. However, there is no guarantee that changes made to the primary are immediately visible to all replicas. Sqld guarantees that a process (connection) will always see its write. Given that the primary is linearizable, it means that a process is guaranteed to see all writes that happened on the primary up until (at least) the last write performed by the process. This is not true for two distinct processes on the same replica, however, that can potentially read two different points in time. For example, a read for process A on the replica might return immediately returning some state, while a read on process B issued at the same time would need to wait to sync with the primary. +All operations occurring on the primary are linearizable. However, there is no guarantee that changes made to the primary are immediately visible to all replicas. libsql-server guarantees that a process (connection) will always see its write. Given that the primary is linearizable, it means that a process is guaranteed to see all writes that happened on the primary up until (at least) the last write performed by the process. This is not true for two distinct processes on the same replica, however, that can potentially read two different points in time. For example, a read for process A on the replica might return immediately returning some state, while a read on process B issued at the same time would need to wait to sync with the primary. Note that reads on a replica are monotonical: once a value has been witnessed, only a value at least as recent can be witnessed on any subsequent read. -There are no global ordering guarantees provided by sqld: any two instances needn't be in sync at any time. +There are no global ordering guarantees provided by libsql-server: any two instances needn't be in sync at any time. diff --git a/docs/HTTP_V1_SPEC.md b/docs/HTTP_V1_SPEC.md index 8fc69399..9bbe9347 100644 --- a/docs/HTTP_V1_SPEC.md +++ b/docs/HTTP_V1_SPEC.md @@ -1,4 +1,4 @@ -# The sqld HTTP API v1 specification ("Hrana over HTTP") +# The libsql-server HTTP API v1 specification ("Hrana over HTTP") Version 1 of the HTTP API ("Hrana over HTTP") is designed to complement the WebSocket-based Hrana protocol for use cases that don't require stateful diff --git a/docs/HTTP_V2_SPEC.md b/docs/HTTP_V2_SPEC.md index a210b935..83000dee 100644 --- a/docs/HTTP_V2_SPEC.md +++ b/docs/HTTP_V2_SPEC.md @@ -1,4 +1,4 @@ -# The sqld HTTP API v2 specification ("Hrana over HTTP") +# The libsql-server HTTP API v2 specification ("Hrana over HTTP") Version 2 of the HTTP API ("Hrana over HTTP") exposes stateful streams from Hrana over HTTP. It provides functionality equivalent to Hrana and it is useful diff --git a/docs/USER_GUIDE.md b/docs/USER_GUIDE.md index 21a666d7..92d07564 100644 --- a/docs/USER_GUIDE.md +++ b/docs/USER_GUIDE.md @@ -63,7 +63,7 @@ The script generates the following files: To start a `sqld` server in primary mode, run: ```console -sqld \ +libsql-server \ --http-listen-addr 127.0.0.1:8081 \ --grpc-listen-addr 127.0.0.1:5001 \ --grpc-tls \ @@ -72,14 +72,14 @@ sqld \ --grpc-key-file server_key.pem ``` -You now have a `sqld` primary server listening to SQL over HTTP at `127.0.0.1:8081` and gRPC with TLS at `127.0.0.1:5001`. +You now have a `libsql-server` primary server listening to SQL over HTTP at `127.0.0.1:8081` and gRPC with TLS at `127.0.0.1:5001`. ### Launching a replica server -To start a a `sqld` server in replica mode, run: +To start a a `libsql-server` server in replica mode, run: ```console -sqld \ +libsql-server \ --http-listen-addr 127.0.0.1:8082 \ --primary-grpc-url https://127.0.0.1:5001 \ --primary-grpc-tls \ @@ -171,7 +171,7 @@ sqld --snapshot-exec ./snapshot.sh --max-log-duration 5 When you write to the `sqld` database, you will eventually see log line such as: ```console -2023-08-11T08:21:04.183564Z INFO sqld::replication::snapshot: snapshot `e126f594-90f4-45be-9350-bc8a01160de9-0-2.snap` successfully created +2023-08-11T08:21:04.183564Z INFO libsql-server::replication::snapshot: snapshot `e126f594-90f4-45be-9350-bc8a01160de9-0-2.snap` successfully created Generated incremental snapshot data.sqld/dbs/default/snapshots/e126f594-90f4-45be-9350-bc8a01160de9-0-2.snap ``` diff --git a/docs/http_api.md b/docs/http_api.md index f87c48ca..8b6ac80f 100644 --- a/docs/http_api.md +++ b/docs/http_api.md @@ -1,6 +1,6 @@ -# SQLD HTTP API +# Libsql-server HTTP API -This is the documentation for the sqld HTTP API. +This is the documentation for the libsql-server HTTP API. ## Usage diff --git a/sqld-libsql-bindings/Cargo.toml b/libsql-bindings/Cargo.toml similarity index 90% rename from sqld-libsql-bindings/Cargo.toml rename to libsql-bindings/Cargo.toml index a278ba64..720b9147 100644 --- a/sqld-libsql-bindings/Cargo.toml +++ b/libsql-bindings/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "sqld-libsql-bindings" +name = "libsql-bindings" version = "0.1.0" edition = "2021" diff --git a/sqld-libsql-bindings/src/ffi/mod.rs b/libsql-bindings/src/ffi/mod.rs similarity index 100% rename from sqld-libsql-bindings/src/ffi/mod.rs rename to libsql-bindings/src/ffi/mod.rs diff --git a/sqld-libsql-bindings/src/ffi/types.rs b/libsql-bindings/src/ffi/types.rs similarity index 100% rename from sqld-libsql-bindings/src/ffi/types.rs rename to libsql-bindings/src/ffi/types.rs diff --git a/sqld-libsql-bindings/src/lib.rs b/libsql-bindings/src/lib.rs similarity index 100% rename from sqld-libsql-bindings/src/lib.rs rename to libsql-bindings/src/lib.rs diff --git a/sqld-libsql-bindings/src/wal_hook.rs b/libsql-bindings/src/wal_hook.rs similarity index 100% rename from sqld-libsql-bindings/src/wal_hook.rs rename to libsql-bindings/src/wal_hook.rs diff --git a/sqld/Cargo.toml b/libsql-server/Cargo.toml similarity index 94% rename from sqld/Cargo.toml rename to libsql-server/Cargo.toml index 16cabbdb..9609bb7e 100644 --- a/sqld/Cargo.toml +++ b/libsql-server/Cargo.toml @@ -1,8 +1,8 @@ [package] -name = "sqld" +name = "libsql-server" version = "0.20.3" edition = "2021" -default-run = "sqld" +default-run = "libsql-server" [dependencies] anyhow = "1.0.66" @@ -47,7 +47,7 @@ serde = { version = "1.0.149", features = ["derive", "rc"] } serde_json = { version = "1.0.91", features = ["preserve_order"] } sha2 = "0.10" sha256 = "1.1.3" -sqld-libsql-bindings = { version = "0", path = "../sqld-libsql-bindings" } +libsql-bindings = { version = "0", path = "../libsql-bindings" } sqlite3-parser = { version = "0.11.0", default-features = false, features = [ "YYNOERRORRECOVERY" ] } tempfile = "3.3.0" thiserror = "1.0.38" @@ -89,7 +89,7 @@ tonic-build = "0.10" vergen = { version = "8", features = ["build", "git", "gitcl"] } [features] -unix-excl-vfs = ["sqld-libsql-bindings/unix-excl-vfs"] +unix-excl-vfs = ["libsql-bindings/unix-excl-vfs"] debug-tools = ["console-subscriber", "rusqlite/trace", "tokio/tracing"] diff --git a/sqld/build.rs b/libsql-server/build.rs similarity index 100% rename from sqld/build.rs rename to libsql-server/build.rs diff --git a/sqld/proto/proxy.proto b/libsql-server/proto/proxy.proto similarity index 100% rename from sqld/proto/proxy.proto rename to libsql-server/proto/proxy.proto diff --git a/sqld/proto/replication_log.proto b/libsql-server/proto/replication_log.proto similarity index 100% rename from sqld/proto/replication_log.proto rename to libsql-server/proto/replication_log.proto diff --git a/sqld/src/auth.rs b/libsql-server/src/auth.rs similarity index 100% rename from sqld/src/auth.rs rename to libsql-server/src/auth.rs diff --git a/sqld/src/config.rs b/libsql-server/src/config.rs similarity index 100% rename from sqld/src/config.rs rename to libsql-server/src/config.rs diff --git a/sqld/src/connection/config.rs b/libsql-server/src/connection/config.rs similarity index 100% rename from sqld/src/connection/config.rs rename to libsql-server/src/connection/config.rs diff --git a/sqld/src/connection/dump/exporter.rs b/libsql-server/src/connection/dump/exporter.rs similarity index 100% rename from sqld/src/connection/dump/exporter.rs rename to libsql-server/src/connection/dump/exporter.rs diff --git a/sqld/src/connection/dump/mod.rs b/libsql-server/src/connection/dump/mod.rs similarity index 100% rename from sqld/src/connection/dump/mod.rs rename to libsql-server/src/connection/dump/mod.rs diff --git a/sqld/src/connection/libsql.rs b/libsql-server/src/connection/libsql.rs similarity index 98% rename from sqld/src/connection/libsql.rs rename to libsql-server/src/connection/libsql.rs index 07b70311..bb3a2ad4 100644 --- a/sqld/src/connection/libsql.rs +++ b/libsql-server/src/connection/libsql.rs @@ -3,8 +3,8 @@ use std::sync::Arc; use std::time::{Duration, Instant}; use crossbeam::channel::RecvTimeoutError; +use libsql_bindings::wal_hook::WalMethodsHook; use rusqlite::{ErrorCode, OpenFlags, StatementStatus}; -use sqld_libsql_bindings::wal_hook::WalMethodsHook; use tokio::sync::{oneshot, watch}; use tracing::warn; @@ -154,7 +154,7 @@ pub fn open_db<'a, W>( hook_ctx: &'a mut W::Context, flags: Option, auto_checkpoint: u32, -) -> Result, rusqlite::Error> +) -> Result, rusqlite::Error> where W: WalHook, { @@ -164,7 +164,7 @@ where | OpenFlags::SQLITE_OPEN_URI | OpenFlags::SQLITE_OPEN_NO_MUTEX, ); - sqld_libsql_bindings::Connection::open(path, flags, wal_methods, hook_ctx, auto_checkpoint) + libsql_bindings::Connection::open(path, flags, wal_methods, hook_ctx, auto_checkpoint) } impl LibSqlConnection { @@ -247,7 +247,7 @@ impl LibSqlConnection { struct Connection<'a> { timeout_deadline: Option, - conn: sqld_libsql_bindings::Connection<'a>, + conn: libsql_bindings::Connection<'a>, timed_out: bool, stats: Arc, config_store: Arc, @@ -626,7 +626,7 @@ mod test { fn setup_test_conn(ctx: &mut ()) -> Connection { let mut conn = Connection { timeout_deadline: None, - conn: sqld_libsql_bindings::Connection::test(ctx), + conn: libsql_bindings::Connection::test(ctx), timed_out: false, stats: Arc::new(Stats::default()), config_store: Arc::new(DatabaseConfigStore::new_test()), diff --git a/sqld/src/connection/mod.rs b/libsql-server/src/connection/mod.rs similarity index 100% rename from sqld/src/connection/mod.rs rename to libsql-server/src/connection/mod.rs diff --git a/sqld/src/connection/program.rs b/libsql-server/src/connection/program.rs similarity index 100% rename from sqld/src/connection/program.rs rename to libsql-server/src/connection/program.rs diff --git a/sqld/src/connection/write_proxy.rs b/libsql-server/src/connection/write_proxy.rs similarity index 99% rename from sqld/src/connection/write_proxy.rs rename to libsql-server/src/connection/write_proxy.rs index b14ae822..e984e9bf 100644 --- a/sqld/src/connection/write_proxy.rs +++ b/libsql-server/src/connection/write_proxy.rs @@ -1,9 +1,9 @@ use std::path::PathBuf; use std::sync::Arc; +use libsql_bindings::wal_hook::TRANSPARENT_METHODS; use parking_lot::Mutex as PMutex; use rusqlite::types::ValueRef; -use sqld_libsql_bindings::wal_hook::TRANSPARENT_METHODS; use tokio::sync::{watch, Mutex}; use tonic::metadata::BinaryMetadataValue; use tonic::transport::Channel; diff --git a/sqld/src/database.rs b/libsql-server/src/database.rs similarity index 100% rename from sqld/src/database.rs rename to libsql-server/src/database.rs diff --git a/sqld/src/error.rs b/libsql-server/src/error.rs similarity index 100% rename from sqld/src/error.rs rename to libsql-server/src/error.rs diff --git a/sqld/src/h2c.rs b/libsql-server/src/h2c.rs similarity index 100% rename from sqld/src/h2c.rs rename to libsql-server/src/h2c.rs diff --git a/sqld/src/heartbeat.rs b/libsql-server/src/heartbeat.rs similarity index 100% rename from sqld/src/heartbeat.rs rename to libsql-server/src/heartbeat.rs diff --git a/sqld/src/hrana/batch.rs b/libsql-server/src/hrana/batch.rs similarity index 92% rename from sqld/src/hrana/batch.rs rename to libsql-server/src/hrana/batch.rs index 9ee32a39..0823ac6c 100644 --- a/sqld/src/hrana/batch.rs +++ b/libsql-server/src/hrana/batch.rs @@ -5,7 +5,7 @@ use std::sync::Arc; use crate::auth::Authenticated; use crate::connection::program::{Cond, Program, Step}; use crate::connection::Connection; -use crate::error::Error as SqldError; +use crate::error::Error; use crate::hrana::stmt::StmtError; use crate::query::{Params, Query}; use crate::query_analysis::Statement; @@ -165,21 +165,21 @@ pub async fn execute_sequence( }) } -fn catch_batch_error(sqld_error: SqldError) -> anyhow::Error { +fn catch_batch_error(sqld_error: Error) -> anyhow::Error { match batch_error_from_sqld_error(sqld_error) { Ok(batch_error) => anyhow!(batch_error), Err(sqld_error) => anyhow!(sqld_error), } } -pub fn batch_error_from_sqld_error(sqld_error: SqldError) -> Result { - Ok(match sqld_error { - SqldError::LibSqlTxTimeout => BatchError::TransactionTimeout, - SqldError::LibSqlTxBusy => BatchError::TransactionBusy, - SqldError::BuilderError(QueryResultBuilderError::ResponseTooLarge(_)) => { +pub fn batch_error_from_sqld_error(error: Error) -> crate::Result { + Ok(match error { + Error::LibSqlTxTimeout => BatchError::TransactionTimeout, + Error::LibSqlTxBusy => BatchError::TransactionBusy, + Error::BuilderError(QueryResultBuilderError::ResponseTooLarge(_)) => { BatchError::ResponseTooLarge } - sqld_error => return Err(sqld_error), + error => return Err(error), }) } diff --git a/sqld/src/hrana/cursor.rs b/libsql-server/src/hrana/cursor.rs similarity index 100% rename from sqld/src/hrana/cursor.rs rename to libsql-server/src/hrana/cursor.rs diff --git a/sqld/src/hrana/http/mod.rs b/libsql-server/src/hrana/http/mod.rs similarity index 100% rename from sqld/src/hrana/http/mod.rs rename to libsql-server/src/hrana/http/mod.rs diff --git a/sqld/src/hrana/http/proto.rs b/libsql-server/src/hrana/http/proto.rs similarity index 100% rename from sqld/src/hrana/http/proto.rs rename to libsql-server/src/hrana/http/proto.rs diff --git a/sqld/src/hrana/http/protobuf.rs b/libsql-server/src/hrana/http/protobuf.rs similarity index 100% rename from sqld/src/hrana/http/protobuf.rs rename to libsql-server/src/hrana/http/protobuf.rs diff --git a/sqld/src/hrana/http/request.rs b/libsql-server/src/hrana/http/request.rs similarity index 100% rename from sqld/src/hrana/http/request.rs rename to libsql-server/src/hrana/http/request.rs diff --git a/sqld/src/hrana/http/stream.rs b/libsql-server/src/hrana/http/stream.rs similarity index 100% rename from sqld/src/hrana/http/stream.rs rename to libsql-server/src/hrana/http/stream.rs diff --git a/sqld/src/hrana/mod.rs b/libsql-server/src/hrana/mod.rs similarity index 100% rename from sqld/src/hrana/mod.rs rename to libsql-server/src/hrana/mod.rs diff --git a/sqld/src/hrana/proto.rs b/libsql-server/src/hrana/proto.rs similarity index 100% rename from sqld/src/hrana/proto.rs rename to libsql-server/src/hrana/proto.rs diff --git a/sqld/src/hrana/protobuf.rs b/libsql-server/src/hrana/protobuf.rs similarity index 100% rename from sqld/src/hrana/protobuf.rs rename to libsql-server/src/hrana/protobuf.rs diff --git a/sqld/src/hrana/result_builder.rs b/libsql-server/src/hrana/result_builder.rs similarity index 100% rename from sqld/src/hrana/result_builder.rs rename to libsql-server/src/hrana/result_builder.rs diff --git a/sqld/src/hrana/stmt.rs b/libsql-server/src/hrana/stmt.rs similarity index 92% rename from sqld/src/hrana/stmt.rs rename to libsql-server/src/hrana/stmt.rs index 13892150..29b9953b 100644 --- a/sqld/src/hrana/stmt.rs +++ b/libsql-server/src/hrana/stmt.rs @@ -6,7 +6,7 @@ use super::{proto, ProtocolError, Version}; use crate::auth::Authenticated; use crate::connection::program::DescribeResponse; use crate::connection::Connection; -use crate::error::Error as SqldError; +use crate::error::Error; use crate::hrana; use crate::query::{Params, Query, Value}; use crate::query_analysis::Statement; @@ -196,24 +196,24 @@ fn proto_describe_result_from_describe_response( } } -fn catch_stmt_error(sqld_error: SqldError) -> anyhow::Error { +fn catch_stmt_error(sqld_error: Error) -> anyhow::Error { match stmt_error_from_sqld_error(sqld_error) { Ok(stmt_error) => anyhow!(stmt_error), Err(sqld_error) => anyhow!(sqld_error), } } -pub fn stmt_error_from_sqld_error(sqld_error: SqldError) -> Result { - Ok(match sqld_error { - SqldError::LibSqlInvalidQueryParams(source) => StmtError::ArgsInvalid { source }, - SqldError::LibSqlTxTimeout => StmtError::TransactionTimeout, - SqldError::LibSqlTxBusy => StmtError::TransactionBusy, - SqldError::BuilderError(QueryResultBuilderError::ResponseTooLarge(_)) => { +pub fn stmt_error_from_sqld_error(error: Error) -> crate::Result { + Ok(match error { + Error::LibSqlInvalidQueryParams(source) => StmtError::ArgsInvalid { source }, + Error::LibSqlTxTimeout => StmtError::TransactionTimeout, + Error::LibSqlTxBusy => StmtError::TransactionBusy, + Error::BuilderError(QueryResultBuilderError::ResponseTooLarge(_)) => { StmtError::ResponseTooLarge } - SqldError::Blocked(reason) => StmtError::Blocked { reason }, - SqldError::RpcQueryError(e) => StmtError::Proxy(e.message), - SqldError::RusqliteError(rusqlite_error) => match rusqlite_error { + Error::Blocked(reason) => StmtError::Blocked { reason }, + Error::RpcQueryError(e) => StmtError::Proxy(e.message), + Error::RusqliteError(rusqlite_error) => match rusqlite_error { rusqlite::Error::SqliteFailure(sqlite_error, Some(message)) => StmtError::SqliteError { source: sqlite_error, message, @@ -232,9 +232,9 @@ pub fn stmt_error_from_sqld_error(sqld_error: SqldError) -> Result return Err(SqldError::RusqliteError(rusqlite_error)), + rusqlite_error => return Err(Error::RusqliteError(rusqlite_error)), }, - sqld_error => return Err(sqld_error), + e => return Err(e), }) } diff --git a/sqld/src/hrana/ws/conn.rs b/libsql-server/src/hrana/ws/conn.rs similarity index 99% rename from sqld/src/hrana/ws/conn.rs rename to libsql-server/src/hrana/ws/conn.rs index 0188959b..5bf52d73 100644 --- a/sqld/src/hrana/ws/conn.rs +++ b/libsql-server/src/hrana/ws/conn.rs @@ -154,7 +154,7 @@ async fn handle_ws( close( &mut conn, CloseCode::Normal, - "Thank you for using sqld".into(), + "Thank you for using libsql-server".into(), ) .await; Ok(()) diff --git a/sqld/src/hrana/ws/handshake.rs b/libsql-server/src/hrana/ws/handshake.rs similarity index 100% rename from sqld/src/hrana/ws/handshake.rs rename to libsql-server/src/hrana/ws/handshake.rs diff --git a/sqld/src/hrana/ws/mod.rs b/libsql-server/src/hrana/ws/mod.rs similarity index 100% rename from sqld/src/hrana/ws/mod.rs rename to libsql-server/src/hrana/ws/mod.rs diff --git a/sqld/src/hrana/ws/proto.rs b/libsql-server/src/hrana/ws/proto.rs similarity index 100% rename from sqld/src/hrana/ws/proto.rs rename to libsql-server/src/hrana/ws/proto.rs diff --git a/sqld/src/hrana/ws/protobuf.rs b/libsql-server/src/hrana/ws/protobuf.rs similarity index 100% rename from sqld/src/hrana/ws/protobuf.rs rename to libsql-server/src/hrana/ws/protobuf.rs diff --git a/sqld/src/hrana/ws/session.rs b/libsql-server/src/hrana/ws/session.rs similarity index 100% rename from sqld/src/hrana/ws/session.rs rename to libsql-server/src/hrana/ws/session.rs diff --git a/sqld/src/http/admin/mod.rs b/libsql-server/src/http/admin/mod.rs similarity index 99% rename from sqld/src/http/admin/mod.rs rename to libsql-server/src/http/admin/mod.rs index f192da1b..b92bb34a 100644 --- a/sqld/src/http/admin/mod.rs +++ b/libsql-server/src/http/admin/mod.rs @@ -52,7 +52,7 @@ where } async fn handle_get_index() -> &'static str { - "Welcome to the sqld admin API" + "Welcome to the libsql-server admin API" } async fn handle_get_config( diff --git a/sqld/src/http/admin/stats.rs b/libsql-server/src/http/admin/stats.rs similarity index 100% rename from sqld/src/http/admin/stats.rs rename to libsql-server/src/http/admin/stats.rs diff --git a/sqld/src/http/mod.rs b/libsql-server/src/http/mod.rs similarity index 100% rename from sqld/src/http/mod.rs rename to libsql-server/src/http/mod.rs diff --git a/sqld/src/http/user/console.html b/libsql-server/src/http/user/console.html similarity index 100% rename from sqld/src/http/user/console.html rename to libsql-server/src/http/user/console.html diff --git a/sqld/src/http/user/db_factory.rs b/libsql-server/src/http/user/db_factory.rs similarity index 100% rename from sqld/src/http/user/db_factory.rs rename to libsql-server/src/http/user/db_factory.rs diff --git a/sqld/src/http/user/dump.rs b/libsql-server/src/http/user/dump.rs similarity index 100% rename from sqld/src/http/user/dump.rs rename to libsql-server/src/http/user/dump.rs diff --git a/sqld/src/http/user/hrana_over_http_1.rs b/libsql-server/src/http/user/hrana_over_http_1.rs similarity index 100% rename from sqld/src/http/user/hrana_over_http_1.rs rename to libsql-server/src/http/user/hrana_over_http_1.rs diff --git a/sqld/src/http/user/mod.rs b/libsql-server/src/http/user/mod.rs similarity index 100% rename from sqld/src/http/user/mod.rs rename to libsql-server/src/http/user/mod.rs diff --git a/sqld/src/http/user/result_builder.rs b/libsql-server/src/http/user/result_builder.rs similarity index 100% rename from sqld/src/http/user/result_builder.rs rename to libsql-server/src/http/user/result_builder.rs diff --git a/libsql-server/src/http/user/snapshots/libsql_server__http__user__types__test__parse_http_query.snap b/libsql-server/src/http/user/snapshots/libsql_server__http__user__types__test__parse_http_query.snap new file mode 100644 index 00000000..f3c407d8 --- /dev/null +++ b/libsql-server/src/http/user/snapshots/libsql_server__http__user__types__test__parse_http_query.snap @@ -0,0 +1,37 @@ +--- +source: libsql-server/src/http/user/types.rs +expression: found +--- +{ + "statements": [ + { + "q": "select * from test", + "params": { + "Positional": [] + } + }, + { + "q": "select ?", + "params": { + "Positional": [ + { + "Integer": 12 + }, + { + "Integer": 1 + } + ] + } + }, + { + "q": "select ?", + "params": { + "Named": { + ":foo": { + "Text": "bar" + } + } + } + } + ] +} diff --git a/libsql-server/src/http/user/snapshots/libsql_server__http__user__types__test__parse_named_params.snap b/libsql-server/src/http/user/snapshots/libsql_server__http__user__types__test__parse_named_params.snap new file mode 100644 index 00000000..e92cd211 --- /dev/null +++ b/libsql-server/src/http/user/snapshots/libsql_server__http__user__types__test__parse_named_params.snap @@ -0,0 +1,31 @@ +--- +source: libsql-server/src/http/user/types.rs +expression: found +--- +{ + "Named": { + "$real": { + "Real": 1.23 + }, + ":blob": { + "Blob": [ + 104, + 101, + 108, + 108, + 111, + 10 + ] + }, + ":bool": { + "Integer": 0 + }, + ":int": { + "Integer": 1 + }, + ":null": "Null", + ":str": { + "Text": "hello" + } + } +} diff --git a/libsql-server/src/http/user/snapshots/libsql_server__http__user__types__test__parse_positional_params.snap b/libsql-server/src/http/user/snapshots/libsql_server__http__user__types__test__parse_positional_params.snap new file mode 100644 index 00000000..d5d068cf --- /dev/null +++ b/libsql-server/src/http/user/snapshots/libsql_server__http__user__types__test__parse_positional_params.snap @@ -0,0 +1,28 @@ +--- +source: libsql-server/src/http/user/types.rs +expression: found +--- +{ + "Positional": [ + { + "Integer": 1 + }, + { + "Text": "hello" + }, + { + "Real": 12.1 + }, + { + "Blob": [ + 104, + 101, + 108, + 108, + 111, + 10 + ] + }, + "Null" + ] +} diff --git a/sqld/src/http/user/snapshots/sqld__http__user__types__test__parse_http_query.snap b/libsql-server/src/http/user/snapshots/sqld__http__user__types__test__parse_http_query.snap similarity index 100% rename from sqld/src/http/user/snapshots/sqld__http__user__types__test__parse_http_query.snap rename to libsql-server/src/http/user/snapshots/sqld__http__user__types__test__parse_http_query.snap diff --git a/sqld/src/http/user/snapshots/sqld__http__user__types__test__parse_named_params.snap b/libsql-server/src/http/user/snapshots/sqld__http__user__types__test__parse_named_params.snap similarity index 100% rename from sqld/src/http/user/snapshots/sqld__http__user__types__test__parse_named_params.snap rename to libsql-server/src/http/user/snapshots/sqld__http__user__types__test__parse_named_params.snap diff --git a/sqld/src/http/user/snapshots/sqld__http__user__types__test__parse_positional_params.snap b/libsql-server/src/http/user/snapshots/sqld__http__user__types__test__parse_positional_params.snap similarity index 100% rename from sqld/src/http/user/snapshots/sqld__http__user__types__test__parse_positional_params.snap rename to libsql-server/src/http/user/snapshots/sqld__http__user__types__test__parse_positional_params.snap diff --git a/sqld/src/http/user/types.rs b/libsql-server/src/http/user/types.rs similarity index 100% rename from sqld/src/http/user/types.rs rename to libsql-server/src/http/user/types.rs diff --git a/sqld/src/lib.rs b/libsql-server/src/lib.rs similarity index 98% rename from sqld/src/lib.rs rename to libsql-server/src/lib.rs index ebd9c6b5..07347231 100644 --- a/sqld/src/lib.rs +++ b/libsql-server/src/lib.rs @@ -37,7 +37,7 @@ use crate::migration::maybe_migrate; use crate::net::Accept; use crate::net::AddrIncoming; use crate::stats::Stats; -pub use sqld_libsql_bindings as libsql; +pub use libsql_bindings as libsql; pub mod config; pub mod connection; @@ -228,17 +228,13 @@ where if let Some(soft_limit_mb) = self.db_config.soft_heap_limit_mb { tracing::warn!("Setting soft heap limit to {soft_limit_mb}MiB"); unsafe { - sqld_libsql_bindings::ffi::sqlite3_soft_heap_limit64( - soft_limit_mb as i64 * 1024 * 1024, - ) + libsql_bindings::ffi::sqlite3_soft_heap_limit64(soft_limit_mb as i64 * 1024 * 1024) }; } if let Some(hard_limit_mb) = self.db_config.hard_heap_limit_mb { tracing::warn!("Setting hard heap limit to {hard_limit_mb}MiB"); unsafe { - sqld_libsql_bindings::ffi::sqlite3_hard_heap_limit64( - hard_limit_mb as i64 * 1024 * 1024, - ) + libsql_bindings::ffi::sqlite3_hard_heap_limit64(hard_limit_mb as i64 * 1024 * 1024) }; } } diff --git a/sqld/src/main.rs b/libsql-server/src/main.rs similarity index 95% rename from sqld/src/main.rs rename to libsql-server/src/main.rs index 437d1381..141d6c5d 100644 --- a/sqld/src/main.rs +++ b/libsql-server/src/main.rs @@ -16,18 +16,18 @@ use tracing_subscriber::prelude::__tracing_subscriber_SubscriberExt; use tracing_subscriber::util::SubscriberInitExt; use tracing_subscriber::Layer; -use sqld::config::{ +use libsql_server::config::{ AdminApiConfig, DbConfig, HeartbeatConfig, RpcClientConfig, RpcServerConfig, TlsConfig, UserApiConfig, }; -use sqld::net::AddrIncoming; -use sqld::Server; -use sqld::{connection::dump::exporter::export_dump, version::Version}; +use libsql_server::net::AddrIncoming; +use libsql_server::Server; +use libsql_server::{connection::dump::exporter::export_dump, version::Version}; #[global_allocator] static GLOBAL: MiMalloc = MiMalloc; -/// SQL daemon +/// Libsql-server #[derive(Debug, Parser)] #[command(name = "sqld")] #[command(about = "SQL daemon", version = Version::default(), long_about = None)] @@ -210,15 +210,18 @@ impl Cli { // no welcome :'( if self.no_welcome { return } - eprintln!(r#" _ _ "#); - eprintln!(r#" ___ __ _| | __| |"#); - eprintln!(r#"/ __|/ _` | |/ _` |"#); - eprintln!(r#"\__ \ (_| | | (_| |"#); - eprintln!(r#"|___/\__, |_|\__,_|"#); - eprintln!(r#" |_| "#); + + eprintln!(r#" _ _ _ _ "#); + eprintln!(r#"| (_) | | | "#); + eprintln!(r#"| |_| |__ ___ __ _| |______ ___ ___ _ ____ _____ _ __ "#); + eprintln!(r#"| | | '_ \/ __|/ _` | |______/ __|/ _ \ '__\ \ / / _ \ '__|"#); + eprintln!(r#"| | | |_) \__ \ (_| | | \__ \ __/ | \ V / __/ | "#); + eprintln!(r#"|_|_|_.__/|___/\__, |_| |___/\___|_| \_/ \___|_| "#); + eprintln!(r#" | | "#); + eprintln!(r#" |_| "#); eprintln!(); - eprintln!("Welcome to sqld!"); + eprintln!("Welcome to libsql-server!"); eprintln!(); eprintln!("version: {}", env!("CARGO_PKG_VERSION")); if env!("VERGEN_GIT_SHA") != "VERGEN_IDEMPOTENT_OUTPUT" { diff --git a/sqld/src/migration.rs b/libsql-server/src/migration.rs similarity index 100% rename from sqld/src/migration.rs rename to libsql-server/src/migration.rs diff --git a/sqld/src/namespace/fork.rs b/libsql-server/src/namespace/fork.rs similarity index 100% rename from sqld/src/namespace/fork.rs rename to libsql-server/src/namespace/fork.rs diff --git a/sqld/src/namespace/mod.rs b/libsql-server/src/namespace/mod.rs similarity index 99% rename from sqld/src/namespace/mod.rs rename to libsql-server/src/namespace/mod.rs index 79807df5..8af03300 100644 --- a/sqld/src/namespace/mod.rs +++ b/libsql-server/src/namespace/mod.rs @@ -13,8 +13,8 @@ use chrono::NaiveDateTime; use enclose::enclose; use futures_core::Stream; use hyper::Uri; +use libsql_bindings::wal_hook::TRANSPARENT_METHODS; use rusqlite::ErrorCode; -use sqld_libsql_bindings::wal_hook::TRANSPARENT_METHODS; use tokio::io::AsyncBufReadExt; use tokio::sync::watch; use tokio::task::{block_in_place, JoinSet}; diff --git a/sqld/src/net.rs b/libsql-server/src/net.rs similarity index 100% rename from sqld/src/net.rs rename to libsql-server/src/net.rs diff --git a/sqld/src/query.rs b/libsql-server/src/query.rs similarity index 100% rename from sqld/src/query.rs rename to libsql-server/src/query.rs diff --git a/sqld/src/query_analysis.rs b/libsql-server/src/query_analysis.rs similarity index 99% rename from sqld/src/query_analysis.rs rename to libsql-server/src/query_analysis.rs index 2b75a4b4..4eb11e8f 100644 --- a/sqld/src/query_analysis.rs +++ b/libsql-server/src/query_analysis.rs @@ -94,7 +94,7 @@ impl StmtKind { Cmd::Stmt(Stmt::Select { .. }) => Some(Self::Read), Cmd::Stmt(Stmt::Pragma(name, body)) => Self::pragma_kind(name, body.as_ref()), // Creating regular views is OK, temporary views are bound to a connection - // and thus disallowed in sqld. + // and thus disallowed in libsql-server. Cmd::Stmt(Stmt::CreateView { temporary: false, .. }) => Some(Self::Write), diff --git a/sqld/src/query_result_builder.rs b/libsql-server/src/query_result_builder.rs similarity index 100% rename from sqld/src/query_result_builder.rs rename to libsql-server/src/query_result_builder.rs diff --git a/sqld/src/replication/frame.rs b/libsql-server/src/replication/frame.rs similarity index 100% rename from sqld/src/replication/frame.rs rename to libsql-server/src/replication/frame.rs diff --git a/sqld/src/replication/mod.rs b/libsql-server/src/replication/mod.rs similarity index 100% rename from sqld/src/replication/mod.rs rename to libsql-server/src/replication/mod.rs diff --git a/sqld/src/replication/primary/frame_stream.rs b/libsql-server/src/replication/primary/frame_stream.rs similarity index 100% rename from sqld/src/replication/primary/frame_stream.rs rename to libsql-server/src/replication/primary/frame_stream.rs diff --git a/sqld/src/replication/primary/logger.rs b/libsql-server/src/replication/primary/logger.rs similarity index 99% rename from sqld/src/replication/primary/logger.rs rename to libsql-server/src/replication/primary/logger.rs index 51c09a5b..4a1d5bd8 100644 --- a/sqld/src/replication/primary/logger.rs +++ b/libsql-server/src/replication/primary/logger.rs @@ -9,9 +9,9 @@ use std::sync::Arc; use anyhow::{bail, ensure}; use bytemuck::{bytes_of, pod_read_unaligned, Pod, Zeroable}; use bytes::{Bytes, BytesMut}; +use libsql_bindings::init_static_wal_method; use parking_lot::RwLock; use rusqlite::ffi::SQLITE_BUSY; -use sqld_libsql_bindings::init_static_wal_method; use tokio::sync::watch; use tokio::time::{Duration, Instant}; use uuid::Uuid; @@ -375,7 +375,7 @@ impl LogFile { start_checksum: 0, db_id: db_id.as_u128(), frame_count: 0, - sqld_version: Version::current().0, + libsql_server_version: Version::current().0, } } else { Self::read_header(&file)? @@ -692,8 +692,8 @@ pub struct LogFileHeader { pub version: u32, /// page size: 4096 pub page_size: i32, - /// sqld version when creating this log - pub sqld_version: [u16; 4], + /// libsql-server version when creating this log + pub libsql_server_version: [u16; 4], } impl LogFileHeader { @@ -707,7 +707,7 @@ impl LogFileHeader { } fn sqld_version(&self) -> Version { - Version(self.sqld_version) + Version(self.libsql_server_version) } } @@ -765,7 +765,7 @@ impl ReplicationLogger { tracing::info!("Replication log is dirty, recovering from database file."); true } else if header.version < 2 || header.sqld_version() != Version::current() { - tracing::info!("replication log version not compatible with current sqld version, recovering from database file."); + tracing::info!("replication log version not compatible with current libsql-server version, recovering from database file."); true } else if fresh && data_path.exists() { tracing::info!("replication log not found, recovering from database file."); diff --git a/sqld/src/replication/primary/mod.rs b/libsql-server/src/replication/primary/mod.rs similarity index 100% rename from sqld/src/replication/primary/mod.rs rename to libsql-server/src/replication/primary/mod.rs diff --git a/sqld/src/replication/replica/error.rs b/libsql-server/src/replication/replica/error.rs similarity index 100% rename from sqld/src/replication/replica/error.rs rename to libsql-server/src/replication/replica/error.rs diff --git a/sqld/src/replication/replica/hook.rs b/libsql-server/src/replication/replica/hook.rs similarity index 97% rename from sqld/src/replication/replica/hook.rs rename to libsql-server/src/replication/replica/hook.rs index 9f6481ab..a7965735 100644 --- a/sqld/src/replication/replica/hook.rs +++ b/libsql-server/src/replication/replica/hook.rs @@ -1,10 +1,10 @@ use std::ffi::{c_int, CStr}; use std::marker::PhantomData; +use libsql_bindings::ffi::Wal; +use libsql_bindings::init_static_wal_method; +use libsql_bindings::{ffi::types::XWalFrameFn, wal_hook::WalHook}; use rusqlite::ffi::{PgHdr, SQLITE_ERROR}; -use sqld_libsql_bindings::ffi::Wal; -use sqld_libsql_bindings::init_static_wal_method; -use sqld_libsql_bindings::{ffi::types::XWalFrameFn, wal_hook::WalHook}; use crate::replication::frame::{Frame, FrameBorrowed}; use crate::replication::{FrameNo, WAL_PAGE_SIZE}; diff --git a/sqld/src/replication/replica/injector.rs b/libsql-server/src/replication/replica/injector.rs similarity index 93% rename from sqld/src/replication/replica/injector.rs rename to libsql-server/src/replication/replica/injector.rs index 9d32223d..4dbad352 100644 --- a/sqld/src/replication/replica/injector.rs +++ b/libsql-server/src/replication/replica/injector.rs @@ -8,12 +8,12 @@ use crate::replication::replica::hook::{SQLITE_CONTINUE_REPLICATION, SQLITE_EXIT use super::hook::{InjectorHookCtx, INJECTOR_METHODS}; pub struct FrameInjector<'a> { - conn: sqld_libsql_bindings::Connection<'a>, + conn: libsql_bindings::Connection<'a>, } impl<'a> FrameInjector<'a> { pub fn new(db_path: &Path, hook_ctx: &'a mut InjectorHookCtx) -> anyhow::Result { - let conn = sqld_libsql_bindings::Connection::open( + let conn = libsql_bindings::Connection::open( db_path, OpenFlags::SQLITE_OPEN_READ_WRITE | OpenFlags::SQLITE_OPEN_CREATE diff --git a/sqld/src/replication/replica/meta.rs b/libsql-server/src/replication/replica/meta.rs similarity index 100% rename from sqld/src/replication/replica/meta.rs rename to libsql-server/src/replication/replica/meta.rs diff --git a/sqld/src/replication/replica/mod.rs b/libsql-server/src/replication/replica/mod.rs similarity index 100% rename from sqld/src/replication/replica/mod.rs rename to libsql-server/src/replication/replica/mod.rs diff --git a/sqld/src/replication/replica/replicator.rs b/libsql-server/src/replication/replica/replicator.rs similarity index 100% rename from sqld/src/replication/replica/replicator.rs rename to libsql-server/src/replication/replica/replicator.rs diff --git a/sqld/src/replication/replica/snapshot.rs b/libsql-server/src/replication/replica/snapshot.rs similarity index 100% rename from sqld/src/replication/replica/snapshot.rs rename to libsql-server/src/replication/replica/snapshot.rs diff --git a/sqld/src/replication/snapshot.rs b/libsql-server/src/replication/snapshot.rs similarity index 100% rename from sqld/src/replication/snapshot.rs rename to libsql-server/src/replication/snapshot.rs diff --git a/sqld/src/rpc/mod.rs b/libsql-server/src/rpc/mod.rs similarity index 100% rename from sqld/src/rpc/mod.rs rename to libsql-server/src/rpc/mod.rs diff --git a/sqld/src/rpc/proxy.rs b/libsql-server/src/rpc/proxy.rs similarity index 96% rename from sqld/src/rpc/proxy.rs rename to libsql-server/src/rpc/proxy.rs index ae91f9ca..2436e284 100644 --- a/sqld/src/rpc/proxy.rs +++ b/libsql-server/src/rpc/proxy.rs @@ -28,13 +28,13 @@ pub mod rpc { use anyhow::Context; use crate::query_analysis::Statement; - use crate::{connection, error::Error as SqldError}; + use crate::{connection, error::Error as CrateError}; use self::{error::ErrorCode, execute_results::State}; tonic::include_proto!("proxy"); - impl From for Error { - fn from(other: SqldError) -> Self { + impl From for Error { + fn from(other: CrateError) -> Self { Error { message: other.to_string(), code: ErrorCode::from(other).into(), @@ -42,12 +42,12 @@ pub mod rpc { } } - impl From for ErrorCode { - fn from(other: SqldError) -> Self { + impl From for ErrorCode { + fn from(other: CrateError) -> Self { match other { - SqldError::LibSqlInvalidQueryParams(_) => ErrorCode::SqlError, - SqldError::LibSqlTxTimeout => ErrorCode::TxTimeout, - SqldError::LibSqlTxBusy => ErrorCode::TxBusy, + CrateError::LibSqlInvalidQueryParams(_) => ErrorCode::SqlError, + CrateError::LibSqlTxTimeout => ErrorCode::TxTimeout, + CrateError::LibSqlTxBusy => ErrorCode::TxBusy, _ => ErrorCode::Internal, } } @@ -74,11 +74,11 @@ pub mod rpc { } impl TryFrom for query::Params { - type Error = SqldError; + type Error = CrateError; fn try_from(value: crate::query::Params) -> Result { match value { crate::query::Params::Named(params) => { - let iter = params.into_iter().map(|(k, v)| -> Result<_, SqldError> { + let iter = params.into_iter().map(|(k, v)| -> Result<_, CrateError> { let v = Value { data: bincode::serialize(&v)?, }; @@ -95,7 +95,7 @@ pub mod rpc { data: bincode::serialize(&v)?, }) }) - .collect::, SqldError>>()?; + .collect::, CrateError>>()?; Ok(Self::Positional(Positional { values })) } } @@ -103,7 +103,7 @@ pub mod rpc { } impl TryFrom for crate::query::Params { - type Error = SqldError; + type Error = CrateError; fn try_from(value: query::Params) -> Result { match value { @@ -112,7 +112,7 @@ pub mod rpc { .values .into_iter() .map(|v| bincode::deserialize(&v.data).map_err(|e| e.into())) - .collect::, SqldError>>()?; + .collect::, CrateError>>()?; Ok(Self::Positional(params)) } query::Params::Named(named) => { diff --git a/sqld/src/rpc/replica_proxy.rs b/libsql-server/src/rpc/replica_proxy.rs similarity index 100% rename from sqld/src/rpc/replica_proxy.rs rename to libsql-server/src/rpc/replica_proxy.rs diff --git a/sqld/src/rpc/replication_log.rs b/libsql-server/src/rpc/replication_log.rs similarity index 100% rename from sqld/src/rpc/replication_log.rs rename to libsql-server/src/rpc/replication_log.rs diff --git a/sqld/src/rpc/replication_log_proxy.rs b/libsql-server/src/rpc/replication_log_proxy.rs similarity index 100% rename from sqld/src/rpc/replication_log_proxy.rs rename to libsql-server/src/rpc/replication_log_proxy.rs diff --git a/sqld/src/stats.rs b/libsql-server/src/stats.rs similarity index 100% rename from sqld/src/stats.rs rename to libsql-server/src/stats.rs diff --git a/sqld/src/test/bottomless.rs b/libsql-server/src/test/bottomless.rs similarity index 100% rename from sqld/src/test/bottomless.rs rename to libsql-server/src/test/bottomless.rs diff --git a/sqld/src/test/mod.rs b/libsql-server/src/test/mod.rs similarity index 100% rename from sqld/src/test/mod.rs rename to libsql-server/src/test/mod.rs diff --git a/sqld/src/utils/mod.rs b/libsql-server/src/utils/mod.rs similarity index 100% rename from sqld/src/utils/mod.rs rename to libsql-server/src/utils/mod.rs diff --git a/sqld/src/utils/services/idle_shutdown.rs b/libsql-server/src/utils/services/idle_shutdown.rs similarity index 100% rename from sqld/src/utils/services/idle_shutdown.rs rename to libsql-server/src/utils/services/idle_shutdown.rs diff --git a/sqld/src/utils/services/mod.rs b/libsql-server/src/utils/services/mod.rs similarity index 100% rename from sqld/src/utils/services/mod.rs rename to libsql-server/src/utils/services/mod.rs diff --git a/sqld/src/version.rs b/libsql-server/src/version.rs similarity index 100% rename from sqld/src/version.rs rename to libsql-server/src/version.rs