Skip to content

Repository files navigation

GlueSQL

crates.io LICENSE Rust docs.rs Chat Coverage Status

An Embeddable Multi-Model SQL Engine

GlueSQL is an embeddable, multi-model SQL database engine written in Rust. It combines SQL with the flexibility to work across different data models and storage environments. It is also available for JavaScript applications in the browser and Node.js.

Why GlueSQL?

GlueSQL is quite sticky: it brings SQL to your application's storage. Use a provided storage backend or implement a custom adapter to query existing data without moving it into a separate database. GlueSQL handles SQL parsing, planning, and execution.

  • Choose a storage backend: use in-memory storage, embedded databases, local files, or external databases.
  • Work with flexible data: query schema-defined and schemaless tables together, including MAP and LIST values.
  • Choose a query interface: write SQL or compose queries with the Rust Query Builder, both backed by the same engine.

Explore the documentation →

Installation

Rust

cargo add gluesql

JavaScript

npm install gluesql

Browser (CDN)

import { gluesql } from 'https://cdn.jsdelivr.net/npm/gluesql/gluesql.js';

For more JS library information, check out the gluesql-js repository.

Supported Reference Storages

GlueSQL provides reference storage implementations for in-memory data, embedded databases, local files, and external databases. Use the table below to choose a storage for your use case.

Use case Recommended storage
Persistent embedded database Redb
Existing MongoDB or Redis data Mongo or Redis
Temporary data, tests, and prototypes, data across threads Memory, Shared Memory
Querying CSV, JSON, or Parquet files CSV, JSON, or Parquet
Lightweight filesystem persistence File
Version-controlled data Git
Queries across multiple storage backends Composite
Browser / JS applications JavaScript: memory, local Storage, or OPFS

See the Storage documentation for setup, examples, and limitations.

SQL and Query Builder

GlueSQL supports both SQL and a Query Builder. Use SQL for familiar or dynamic queries, and use the Query Builder when composing queries in Rust or controlling execution more precisely. Both interfaces run through the same GlueSQL engine and storage backend. For more information, check out the Query Builder documentation and SQL documentation.

SQL

SELECT id, name FROM Foo WHERE name = 'Lemon' AND price > 100

Query Builder

table("Foo")
    .select()
    // Filter by name using a SQL string
    .filter("name = 'Lemon'")
    // Filter by price using Query Builder methods
    .filter(col("price").gt(100))
    .project("id, name")
    .execute(&mut glue);

Unlike ORM query builders designed to support multiple database engines by generating SQL, GlueSQL's Query Builder builds executable statement plans directly. It accepts both builder methods and SQL expressions, supports the full GlueSQL feature set, and can express execution details that SQL can only suggest through query hints.

Supporting Schema-defined and Schemaless Data with Schema Flexibility

GlueSQL supports both schema-defined (structured) and schemaless (unstructured) data. Unlike traditional SQL databases, it does not require every table to have a predefined schema. Schemaless tables can store varying fields, while MAP and LIST support semi-structured values. Schema-defined and schemaless tables can also be joined in the same query.

Schemaless SQL Example

CREATE TABLE Names (id INTEGER, name TEXT);
INSERT INTO Names VALUES (1, 'glue'), (2, 'sql');

CREATE TABLE Logs;
INSERT INTO Logs VALUES
    ('{ "id": 1, "value": 30 }'),
    ('{ "id": 2, "rate": 3.0, "list": [1, 2, 3] }'),
    ('{ "id": 3, "rate": 5.0, "value": 100 }');

SELECT * FROM Names JOIN Logs ON Names.id = Logs.id;

/*
| id | list    | name | rate | value |
|----|---------|------|------|-------|
| 1  |         | glue |      | 30    |
| 2  |[1, 2, 3]| sql  | 3    |       |
*/

Adapting GlueSQL to Your Environment: Creating Custom Storage

GlueSQL is designed to be adaptable to a wide variety of environments, including file systems, key-value databases, complex NoSQL databases, and remote APIs. To create a custom storage for GlueSQL, you only need to implement the Store and StoreMut traits provided by GlueSQL. For more information, see the custom storage development documentation.

Contributing

GlueSQL is simpler to contribute to than it may look. Its test suite and continuous integration provide guardrails that catch regressions before changes are merged, so don't hesitate to open an issue or pull request.

If you're not sure where to start, explore the test suite. The SQL fixtures are a good starting point for getting a sense of GlueSQL's overall capabilities. Try contributing a feature you'd like to use, or browse the GitHub issues for more ideas.

License

This project is licensed under the Apache License, Version 2.0. See the LICENSE file for details.

About

GlueSQL is quite sticky. It sticks to anything.

Topics

Resources

Stars

3.1k stars

Watchers

30 watching

Forks

Releases

Used by

Contributors

Languages