Git Product home page Git Product logo

sqliterg's Introduction

๐ŸŒฟ Introduction

This is a rewrite in Rust of 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. You can read more about what's changed and how to migrate here.

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).

Full docs are available here and a tutorial too.

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).

As a quick example, after launching:

sqliterg --db mydatabase.db

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

{
    "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

  • A single executable file (written in Rust);
  • Can be built either against the system's SQLite or embedding one;
  • HTTP/JSON access;
  • Directly call sqliterg 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;
  • Named or positional parameters in SQL are supported;
  • Batching of multiple value sets for a single statement;
  • 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;
  • "Macros": lists of statements that can be executed at db creation, at startup, periodically or calling a web service;
  • Backups, rotated and also runnable at db creation, at startup, periodically or calling a web service;
  • CORS mode, configurable per-db;
  • Journal Mode (e.g. WAL) can be configured;
  • Embedded web server to directly serve web pages that can access sqliterg without CORS;
  • Quite fast!
  • Comprehensive test suite;
  • Docker images, for x86_64 and arm64;
  • Binaries are provided with a bundled SQLite "inside" them, or linked against the system's installed SQLite.

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.

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.

๐Ÿฅ‡ Credits

Kindly supported by JetBrains for Open Source development.

sqliterg's People

Contributors

proofrock avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

diyism

sqliterg's Issues

Implement positional parameters for SQL

Currently, only named params are supported:

{
    "transaction": [{
            "statement": "INSERT INTO TEST_TABLE (ID, VAL, VAL2) VALUES (:id, :val, :val2)",
            "values": { "id": 1, "val": "hello", "val2": null }
    }]
}

Implement also:

{
    "transaction": [{
            "statement": "INSERT INTO TEST_TABLE (ID, VAL, VAL2) VALUES (?, ?, ?)",
            "values": [ 1, "hello", null ]
    }]
}

Mariadb?

Any chance of supporting more dbs like mariadb? Great repos!

Sort keys of objects returned by `SELECT * FROM table` by creation order instead of dictionary order

Hi!

Suppose I have this table:

CREATE TABLE `folders` (
	`id` text PRIMARY KEY NOT NULL,
	`name` text NOT NULL,
	`position` real DEFAULT 1 NOT NULL,
	`updated_at` text DEFAULT CURRENT_TIMESTAMP NOT NULL,
	`created_at` text DEFAULT CURRENT_TIMESTAMP NOT NULL
);

And this data:

INSERT INTO `folders`(id, name, position)
VALUES ('default', 'Default', 0)
ON CONFLICT(id) DO NOTHING;

SELECT * FROM folders would return:

{
  "results": [
    {
      "success": true,
      "resultSet": [
        {
          "created_at": "2024-02-04 12:23:08",
          "id": "default",
          "name": "Default",
          "position": 0.0,
          "updated_at": "2024-02-04 12:23:08"
        }
      ]
    }
  ]
}

I think it should follow creation order`, which returns:

  • id
  • name
  • position
  • updated_at
  • created_at

It is the behavior of the behavior of sqlite3 as well:

default|Default|0.0|2024-02-04 12:54:32|2024-02-04 12:54:32

Thanks!

How to run multiple `CREATE TABLE` statements in one transaction?

Hi!

I'm trying to wrap Drizzle's around sqliterg. It works well if there is only one statement involved in one sqliterg transaction. However, if there are multiple statements, only the first one gets executed. For example, I have this SQL migration file that is generated by Drizzle:

CREATE TABLE `folders` (
	...
);
--> statement-breakpoint
CREATE TABLE `snippet_tags` (
	...
);
--> statement-breakpoint
CREATE TABLE `snippets` (
	...
);

Then only CREATE TABLE folders gets executed. What do you think I should do in this case? Must I parse the SQL myself and split it to multiple transaction before passing it to sqliterg?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.