Skip to content

hermanccw/bqn-sqlite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bqn-sqlite

bqn-sqlite is a small SQLite-like database implemented in BQN. It stores tables as BQN data structures, accepts a practical subset of SQL, and persists databases by writing a replayable SQL dump.

Run

The ./bqn-sqlite launcher prefers a native BQN runtime named bqn or cbqn. If neither is installed, it falls back to the bundled JS BQN runtime in .research/BQN/bqn.js, which needs Node.js.

./bqn-sqlite demo.bqnsql "CREATE TABLE people (id INTEGER, name TEXT, age REAL);"
./bqn-sqlite demo.bqnsql "INSERT INTO people VALUES (1, 'Ada', 37);"
./bqn-sqlite demo.bqnsql "SELECT * FROM people;"

Equivalent direct BQN invocation:

bqn src/cli.bqn demo.bqnsql "SELECT * FROM people;"

Fallback JS BQN invocation:

node .research/BQN/bqn.js src/cli.bqn demo.bqnsql "SELECT * FROM people;"

Supported SQL

  • CREATE TABLE name (column [type], ...)
  • INSERT INTO name VALUES (...)
  • INSERT INTO name (column, ...) VALUES (...)
  • SELECT * FROM name
  • SELECT column, ... FROM name
  • WHERE predicates using =, !=, <>, <, <=, >, >=
  • ORDER BY column
  • UPDATE name SET column=value [, ...] [WHERE ...]
  • DELETE FROM name [WHERE ...]
  • DROP TABLE name
  • .tables
  • .schema

Values may be numbers, single-quoted strings, double-quoted strings, or bare strings. Single quotes inside SQL strings are escaped with doubled quotes, for example 'Ada''s notes'.

Persistence

The CLI loads the database file before each command and saves it afterward. The file is a SQL dump that can be read by bqn-sqlite again:

CREATE TABLE people (id, name, age);
INSERT INTO people VALUES (1, 'Ada', 37);

Tests

Run the BQN test suite with:

bqn test/test.bqn

Or with the bundled JS runtime:

node .research/BQN/bqn.js test/test.bqn

The tests cover table creation, full and column-list inserts, projection, filtering, ordering, update, delete, schema/table meta commands, save/load persistence, and dropping tables.

Notes

This is a basic clone, not a full SQLite implementation. It does not implement joins, indexes, transactions, constraints, aggregate functions, nested queries, or SQLite's complete type system. The implementation lives in src/bqn_sqlite.bqn; src/cli.bqn is a thin BQN command-line front end.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages