|
1 | | -# sqliterg |
2 | | -A SQLite remote gateway - query SQLite via HTTP |
| 1 | +# 🌿 Introduction & Credits |
3 | 2 |
|
4 | | -This is a rewrite of [ws4sqlite](https://github.com/proofrock/ws4sqlite) in Rust, for some reasons: |
| 3 | +*This is a rewrite in Rust of [ws4sqlite](https://github.com/proofrock/ws4sqlite), 30-50% faster, 10x less memory used, more flexible in respect to sqlite support. It is not a direct rewrite, more like a "sane" (I hope) [redesign](https://github.com/proofrock/sqliterg/blob/main/CHANGES_FROM_WS4SQLITE.md).* |
5 | 4 |
|
6 | | -- To see if it's faster |
7 | | -- To reduce binary size |
8 | | -- To correct some small design flaws |
9 | | -- To learn Rust 😜 |
| 5 | +**sqliterg** is a server-side 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). |
10 | 6 |
|
11 | | -But mainly, to be able to compile against an existing SQLite, not (only) embedding one. [rusqlite](https://docs.rs/rusqlite/latest/rusqlite/) has this feature, and I'd like to explore it. |
| 7 | +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). |
12 | 8 |
|
13 | | -It doesn't hurt that preliminary benchmarks seem to indicate that it's 30-50% faster and uses 1/5th of the memory. |
| 9 | +As a quick example, after launching |
14 | 10 |
|
15 | | -The code is Rust, the tests are in Go, the profiler in Java. |
| 11 | +```bash |
| 12 | +sqliterg --db mydatabase.db |
| 13 | +``` |
16 | 14 |
|
17 | | -No ETA. Don't hold your breath. |
| 15 | +It's possible to make a POST call to `http://localhost:12321/mydatabase/exec`, e.g. with the following body: |
| 16 | + |
| 17 | +```json |
| 18 | +{ |
| 19 | + "transaction": [ |
| 20 | + { |
| 21 | + "statement": "INSERT INTO TEST_TABLE (ID, VAL, VAL2) VALUES (:id, :val, :val2)", |
| 22 | + "values": { "id": 1, "val": "hello", "val2": null } |
| 23 | + }, |
| 24 | + { |
| 25 | + "query": "SELECT * FROM TEST_TABLE" |
| 26 | + } |
| 27 | + ] |
| 28 | +} |
| 29 | +``` |
| 30 | + |
| 31 | +Obtaining an answer of: |
| 32 | + |
| 33 | +```json |
| 34 | +{ |
| 35 | + "results": [ |
| 36 | + { |
| 37 | + "success": true, |
| 38 | + "rowsUpdated": 1 |
| 39 | + }, |
| 40 | + { |
| 41 | + "success": true, |
| 42 | + "resultSet": [ |
| 43 | + { "ID": 1, "VAL": "hello", "VAL2": null } |
| 44 | + ] |
| 45 | + } |
| 46 | + ] |
| 47 | +} |
| 48 | +``` |
| 49 | + |
| 50 | +# 🥇 Features |
| 51 | + |
| 52 | +- A [**single executable file**](https://germ.gitbook.io/sqliterg/documentation/installation) (written in Rust); |
| 53 | +- Can be built against the system's SQLite or embedding one (thanks to [rusqlite](https://docs.rs/rusqlite/latest/rusqlite/)); |
| 54 | +- HTTP/JSON access; |
| 55 | +- Directly call `sqliterg` on a database (as above), many options available using a YAML companion file; |
| 56 | +- [**In-memory DBs**] are supported (https://germ.gitbook.io/sqliterg/documentation/configuration-file#path); |
| 57 | +- Serving of [**multiple databases**](https://germ.gitbook.io/sqliterg/documentation/configuration-file) in the same server instance; |
| 58 | +- [**Batching**](https://germ.gitbook.io/sqliterg/documentation/requests#batch-parameter-values-for-a-statement) of multiple value sets for a single statement; |
| 59 | +- All queries of a call are executed in a [**transaction**](https://germ.gitbook.io/sqliterg/documentation/requests); |
| 60 | +- For each query/statement, specify if a failure should rollback the whole transaction, or the failure is [**limited**](https://germ.gitbook.io/sqliterg/documentation/errors#managed-errors) to that query; |
| 61 | +- "[**Stored Statements**](https://germ.gitbook.io/sqliterg/documentation/stored-statements)": define SQL in the server, and call it from the client; |
| 62 | +- "[**Macros**](https://germ.gitbook.io/sqliterg/documentation/macros)": lists of statements that can be executed at db creation, at startup, periodically or calling a web service; |
| 63 | +- **Backups**, rotated and also runnable at db creation, at startup, periodically or calling a web service; |
| 64 | +- [**CORS**](https://germ.gitbook.io/sqliterg/documentation/configuration-file#corsorigin) mode, configurable per-db; |
| 65 | +- Scheduled tasks can be: backup (with rotation), vacuum and/or a set of SQL statements; |
| 66 | +- [**Journal Mode**](https://sqlite.org/wal.html) (e.g. WAL) can be configured; |
| 67 | +- [**Embedded web server**](https://germ.gitbook.io/sqliterg/documentation/web-server) to directly serve web pages that can access sqliterg without CORS;- [Quite fast](features/performances.md)! |
| 68 | +- Comprehensive test suite (`make test`); |
| 69 | + |
| 70 | +### Security Features |
| 71 | + |
| 72 | +* [**Authentication**](https://germ.gitbook.io/sqliterg/documentation/security.md#authentication) can be configured |
| 73 | + * on the client, either using HTTP Basic Authentication or specifying the credentials in the request; |
| 74 | + * on the server, either by specifying credentials (also with hashed passwords) or providing a query to look them up in the db itself; |
| 75 | + * customizable `Not Authorized` error code (if 401 is not optimal) |
| 76 | +* A database can be opened in [**read-only mode**](https://germ.gitbook.io/sqliterg/documentation/security.md#read-only-databases) (only queries will be allowed); |
| 77 | +* It's possible to enforce using [**only stored statements**](https://germ.gitbook.io/sqliterg/documentation/security.md#stored-statements-to-prevent-sql-injection), to avoid some forms of SQL injection and receiving SQL from the client altogether; |
| 78 | +* [**CORS Allowed Origin**](https://germ.gitbook.io/sqliterg/documentation/security.md#cors-allowed-origin) can be configured and enforced; |
| 79 | +* It's possible to [**bind**](https://germ.gitbook.io/sqliterg/documentation/security.md#binding-to-a-network-interface) to a network interface, to limit access. |
| 80 | + |
| 81 | +Some design choices: |
| 82 | + |
| 83 | +* Very thin layer over SQLite. Errors and type translation, for example, are those provided by the SQLite driver; |
| 84 | +* Doesn't include HTTPS, as this can be done easily (and much more securely) with a [reverse proxy](https://germ.gitbook.io/sqliterg/documentation/security.md#use-a-reverse-proxy-if-going-on-the-internet); |
0 commit comments