Back to directory
proofrock avatar

ws4sqlite

Query sqlite via json+http. Read more below about its uses, features, and usage.

Clone repository

git clone https://github.com/proofrock/ws4sqlite.git

557

Stars

16

Forks

6

Watchers

ISC

License

🌱 ws4sqlite

A bit of status report. The ws4sql fork (to integrate duckdb alongside sqlite) is back on track, hopefully to be released "as soon as" the documentation is in good shape.

ws4sqlite is a server application that, applied to one or more sqlite files, allows to perform SQL queries and statements on them via REST (or better, JSON over HTTP).

Possible use cases are the ones where remote access to a sqlite db is useful/needed, for example a data layer for a remote application, possibly serverless or even called from a web page (after security considerations of course).

Client libraries are available, that will abstract the "raw" JSON-based communication. See here for Java/JVM, here for Go(lang); others will follow.

As a quick example, after launching

ws4sqlite --db mydatabase.db

It's possible to make a POST call to http://localhost:12321/mydatabase, e.g. with the following body:

// Set Content-type: application/json
{
    "resultFormat": "map", // "map" or "list"; if omitted, "map"
    "transaction": [
        {
            "statement": "INSERT INTO TEST_TABLE (ID, VAL, VAL2) VALUES (:id, :val, :val2)",
            "values": { "id": 1, "val": "hello", "val2": null }
        },
        {
            "query": "SELECT * FROM TEST_TABLE"
        }
    ]
}

Obtaining an answer of

{
    "results": [
        {
            "success": true,
            "rowsUpdated": 1
        },
        {
            "success": true,
            "resultSet": [
                { "ID": 1, "VAL": "hello", "VAL2": null }
            ]
        }
    ]
}

Features

Docs, a Tutorial, a Discord.

  • Aligned to SQLite 3.53.3;
  • A single executable file (written in Go);
  • HTTP/JSON access, with client libraries for convenience;
  • Directly call ws4sqlite on a database (as above), many options available using a YAML companion file;
  • In-memory DBs are supported;
  • Serving of multiple databases in the same server instance;
  • Batching of multiple value sets for a single statement;
  • Parameters may be passed to statements positionally (lists) or by name (maps);
  • Results of queries may be returned as key-value maps, or as values lists;
  • All queries of a call are executed in a transaction;
  • For each query/statement, specify if a failure should rollback the whole transaction, or the failure is limited to that query;
  • "Stored Statements": define SQL in the server, and call it from the client;
  • CORS mode, configurable per-db;
  • Scheduled tasks, cron-like and/or at startup, also configurable per-db;
  • Scheduled tasks can be: backup (with rotation), vacuum and/or a set of SQL statements;
  • Provide initialization statements to execute when a DB is created;
  • WAL mode enabled by default, can be disabled;
  • Quite fast!
  • Embedded web server to directly serve web pages that can access ws4sqlite without CORS;
  • Compact codebase;
  • Comprehensive test suite (make test);
  • 11 os's/arch's directly supported;
  • Docker images, for amd64, arm and arm64.

Security Features

  • Authentication can be configured
    • on the client, either using HTTP Basic Authentication or specifying the credentials in the request;
    • on the server, either by specifying credentials (also with hashed passwords) or providing a query to look them up in the db itself;
    • customizable Not Authorized error code (if 401 is not optimal)
  • A database can be opened in read-only mode (only queries will be allowed);
  • It's possible to enforce using only stored statements, to avoid some forms of SQL injection and receiving SQL from the client altogether;
  • CORS Allowed Origin can be configured and enforced;
  • It's possible to bind to a network interface, to limit access.

Design Choices

Some design choices:

  • Very thin layer over SQLite. Errors and type translation, for example, are those provided by the SQLite driver;
  • Doesn't include HTTPS, as this can be done easily (and much more securely) with a reverse proxy;
  • Doesn't support SQLite extensions, to improve portability.

Contacts and Support

Let's meet on Discord!

Credits

Many thanks and all the credits to these awesome projects:

Kindly supported by JetBrains for Open Source development

Releases

Oct 31, 2025

Version v0.16.6

Download .zip

Aligned to SQLite 3.50.4. Compiled with go 1.25.3.

#57 Not support Unicode name SQLite 3.50.4 Library updates

Docker images for amd64, arm and arm64 are here. This release is backwards compatible up...

v0.17dev7

Pre-release

Aug 6, 2025

Version v0.17dev7

Download .zip

This is not the latest release of ws4sqlite, which is here. The work takes place in the fork/ws4sql branch, and you can find the changes so far, and the steps needed to migrate a regular installation...

Aug 6, 2025

Version v0.16.5

Download .zip

The ws4sql fork (to integrate duckdb alongside sqlite) is back on track, hopefully to be released "as soon as" the documentation is in good shape._

Aligned to SQLite 3.50.3. Compiled with go 1.24.5....

v0.17dev6

Pre-release

Apr 27, 2025

[fork] ws4sql v0.17dev6

Download .zip

Intermediate release: DuckDB released a new version, and it broke the build scripts: it took me a while to sort it out. This release puts everything back on track.

This is not the latest release of w...

Apr 21, 2025

Version v0.16.4

Download .zip

A bit of status report. The ws4sql fork (to integrate duckdb alongside sqlite) is unfortunately stuck... well, I am stuck... because I cannot get the new 1.2.0 duckdb version to compile statically as...