Home /Modules/sleela-sql/SPECIFICATION.md

SPECIFICATION.md

lib/sleela-sql/SPECIFICATION.md · 63 line(s) · markdown

SLeeLa SQL Native Specification

Status: bounded local-file SQL engine, not a general-purpose SQL server. Implementation: C11 core with optional C++17 RAII facade. Storage: one CSV file per table; header row contains column names.

1. Architecture

Classic SQL and fluent SLeeLaSQL are front ends to one parser/compiler and one executor. Both lower to the same opaque ssql_stmt representation. The SLeeLa source model in SqlModel.sleela is a separate validation/reporting layer; it does not call the C engine automatically.

2. Supported statement subset

OperationSQL syntaxSemantics
CreateCREATE TABLE [IF NOT EXISTS] t (c1, c2, ...)Creates t.csv with a header; optional clause makes existing-table creation idempotent
AlterALTER TABLE t ADD [COLUMN] c [DEFAULT value]Rewrites table with a new column; existing rows receive the default or an empty string; duplicate names are rejected
DropDROP TABLE t; DROP TABLE IF EXISTS tRemoves table file
InsertINSERT INTO t VALUES (v1, ...)Appends one positional row
UpdateUPDATE t SET c = v [, ...] [WHERE c = v]Rewrites matching rows; omitted WHERE updates all rows
DeleteDELETE FROM t [WHERE c = v]Removes matching rows; omitted WHERE deletes all rows
SelectSELECT * FROM t [WHERE c = v]; SELECT COUNT(*) FROM t [WHERE c = v]Reads projected rows or counts matching rows; one equality predicate
ListSHOW TABLESEmits CSV table names

Fluent equivalents: table('t').create(c1, c2), from('t').drop(), from('t').drop(ifExists), into('t').insert(v1, v2), from('t').select(*), from('t').select(count(*)), from('t').select(c1).where(c == v), and tables().

This is a subset. It is not MySQL/PostgreSQL/SQLite wire-protocol compatible. ALTER TABLE ADD COLUMN, UPDATE, and DELETE are currently SQL-dialect-only; UPDATE/DELETE support a single equality predicate. Compound predicates, joins, general aggregate functions beyond COUNT(*), indexes, schema types, constraints, subqueries, ordering, grouping, and explicit multi-statement transactions are not implemented.

3. Prepared statements

4. Status codes

SSQL_OK, SSQL_ERR_IO, SSQL_ERR_SYNTAX, SSQL_ERR_NOTABLE, SSQL_ERR_EXISTS, SSQL_ERR_NOCOL, SSQL_ERR_ARITY, SSQL_ERR_ARG, SSQL_ERR_BIND, SSQL_ERR_OOM, SSQL_ERR_DUPCOL.

5. Bounds and persistence

6. C and C++ contracts

The C API is the core ABI. Include native/include/sleela_sql.h, link the C library, and compile as C11. The C++17 facade in cpp/include/sleela_sql.hpp wraps that API through sleela::sql::Database and move-only sleela::sql::Statement; it does not fork SQL semantics.

7. Portable file I/O

8. Build and verification

From lib/sleela-sql, run make and make test. CI builds and runs the C11 core and C++17 facade on Linux, macOS, and Windows (MinGW-w64).