sleela-sql
library module lib/sleela-sql
Examples
<img align="right" src="https://github.com/mearvk/SLeeLa/blob/master/images/debian/debian-logo.png" width="75" height="75" alt="SLeeLa">
SLeeLa SQL — native C/C++ engine and SLeeLa model
This package groups the SLeeLa model with the native C SQL engine and a C++17 RAII wrapper.
SqlModel.sleela: SLeeLa-side plan validation and verdicts.native/include/sleela_sql.h,native/src/sleela_sql.c: C11 engine and public API.native/src/sleela_sql_cli.c:sleela-sqlcommand-line program.cpp/include/sleela_sql.hpp,cpp/src/sleela_sql.cpp: C++17 facade over the same C API.docs/SLEELASQL.md: fluent dialect grammar.SPECIFICATION.md: supported subset, bounds, API, and limitations.samples/: classic SQL and fluent SLeeLaSQL sessions.- Portable storage I/O: POSIX directory enumeration on macOS/Linux and a MinGW-w64 CRT adapter on Windows.
Build and test
cd lib/sleela-sql
make
make test
Outputs are kept under build/: CLI, C static library, and C++ facade library. Consumers of the C++ facade must link both the C++ and C core libraries. ssql_open creates the final database directory if absent; it does not recursively create parent directories.
The SQL subset supports idempotent CREATE TABLE IF NOT EXISTS, ALTER TABLE table ADD [COLUMN] column [DEFAULT value], SELECT COUNT(*) ... [WHERE column = value], UPDATE table SET column = value [, ...] [WHERE column = value], and DELETE FROM table [WHERE column = value]. ALTER TABLE rewrites through a temporary CSV, preserves existing values, initializes old rows with the specified default (or an empty string), rejects duplicate columns, and uses the platform-specific replacement routine. UPDATE/DELETE rewrite a temporary CSV and replace the table file; on Windows a backup is used to restore the original if replacement fails. UPDATE, DELETE, and ALTER TABLE ADD COLUMN are SQL-dialect features; fluent SLeeLaSQL schema migration, update/delete, and richer predicates are not yet implemented.
C example
#include "sleela_sql.h"
ssql_db db;
ssql_open(&db, "./data");
ssql_exec(&db, "CREATE TABLE games (id, title)", NULL);
ssql_exec(&db, "INSERT INTO games VALUES (1, 'Metroid')", NULL);
C++ example
#include "sleela_sql.hpp"
sleela::sql::Database db("./data");
if (db.status() == SSQL_OK)
db.execute("from('games').select(*)", stdout);
The engine is a local CSV-backed SQL subset, not a network database server or a full MySQL implementation. Read SPECIFICATION.md before relying on it for production data. SqlModel.sleela validates planned operations but does not automatically invoke the native library; that runtime bridge remains separate integration work.
Dialects, prepared statements, and model boundary
Classic SQL and fluent SLeeLaSQL compile to the same internal statement and executor. The C API supports reusable prepared statements in either dialect with positional ? placeholders (ssql_prepare, ssql_bind, ssql_reset, ssql_run, and ssql_finalize). See docs/SLEELASQL.md for grammar and examples.
SqlModel.sleela validates planned operations using schema facts supplied by the caller: CREATE collisions, INSERT arity, and projected-column existence. It is a SLeeLa-side model/validation example, not an automatic runtime bridge to the native C engine.
Examples
See examples/ for runnable SQL examples covering table creation, inserts, SELECT/filter/count, UPDATE, DELETE, table listing/drop, the fluent SLeeLaSQL dialect, prepared statements, and ALTER TABLE ADD COLUMN migration examples.
Files 19
- cpp/include/sleela_sql.hpp
- cpp/src/sleela_sql.cpp
- docs/SLEELASQL.md
- examples/08-prepared-statements.c
- examples/README.md
- examples/slsql/04-prepared-statements.c
- examples/slsql/05-sql-equivalents.md
- examples/slsql/README.md
- Makefile
- native/include/sleela_sql.h
- native/src/sleela_sql.c
- native/src/sleela_sql_cli.c
- README.md
- ROADMAP.md
- SPECIFICATION.md
- SqlModel.sleela
- tests/test_c.c
- tests/test_cpp.cpp
- tests/test_txn.c