Home /Modules/sleela-sql/README.md

README.md

lib/sleela-sql/README.md · 56 line(s) · markdown

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

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.