NeuxDb
Version: 0.1.0
NeuxDb is a super simple, fast, and tight embedded database library. NeuxDb stores data in CSV format with a pipe delimiter (|) and schemas in JSON format.
Designed with the "Single Function Interface" philosophy, NeuxDb eliminates boilerplate complexity by providing a single primary function: run(sql).
Key Features
- Super Simple API: Simply call
neuxdb::run("SQL"). - Type-Safe: Supports
IntandTextdata types with automatic validation. - Concurrency Safe: Uses exclusive file locking (
flock) to prevent race conditions. - SQL-Like: Supports
CREATE,INSERT,SELECT,UPDATE,DELETE,DROP, andSHOW TABLES. - Zero Dependency Config: No complex configuration required, simply specify the data folder.
Installation
Add to Cargo.toml:
[]
= "0.1.0"
(Ensure dependencies thiserror, serde, serde_json, csv, and fs2 are present)
Quick Start
use ;
API Reference
Main Functions
init() -> Result<()>
Creates a data folder if it doesn't already exist. The default folder is data/, which can be changed via the NEUXDB_DATA_DIR environment variable.
run(sql: &str) -> Result<String>
The main function for executing SQL commands.
- Input: SQL command string.
- Output:
Ok(String): The result of the operation. ForSELECT, it's a formatted table. For other operations, it's a success message.Err(NeuxDbError): If an error occurs (e.g., table not found, incorrect syntax).
SQL Syntax Reference
NeuxDb supports a clean and consistent subset of SQL.
1. Data Definition
(column1, column2, ...);
table_name;
SHOW TABLES;
2. Data Manipulation
Insert
INSERT INTO table_name VALUES (value1, value2);
-- Example of mixed types:
INSERT INTO users VALUES (1, 'Alice');
Select
SELECT * FROM table_name;
SELECT column1 FROM table_name WHERE id = 1;
Support:
- Columns:
*or a specific list. - Operators:
=,!=(or<>),<,>,<=,>=,LIKE. - Logic:
AND,OR. - Wildcards (LIKE):
%(any character),_(single character).
Update
UPDATE table_name SET column = new_value WHERE condition;
Note: WHERE is required for security (prevents accidental mass updates).
Delete
DELETE FROM table_name WHERE condition;
Note: WHERE is required.
Data Types
NeuxDb automatically infers data types:
- Int: Whole number (e.g.,
1,500). Stored asi64. - Text: String enclosed in quotes (e.g.,
'Alice').
Loose Typing:
NeuxDb uses loose comparison. If you compare a Text column with a number (Int), the comparison will be based on their string representations.
Example: WHERE id = 1 will match the text column "1".
Error Handling
All errors are returned in the neuxdb::DbError enum.
use ;
match run
Configuration
Using environment variables:
NEUXDB_DATA_DIR: Absolute or relative path to the data storage folder. Default:"data".
Example SELECT Output
The run function returns a neat table string:
id | name
---+------
1 | Alice
2 | Bob
If no results:
id | name
---+------
(0 rows)
Internal Architecture (Overview)
This library is structured in a flat and modular way behind the scenes:
- Parser: Converts SQL strings to AST (
Statement). - Executor: Executes business logic and calls storage.
- Storage: Handles file I/O, CSV, and locking to ensure data integrity.
All of this complexity is abstracted into a single run() function.