CursorsQL is a primitive but intuitive database in Rust for beginners.
CursorsQL is a small database that is easy to learn and use. It is intended for use by people who are newcomers to database technology and SQL.
By design, CursorsQL are minimal and simple, and limited. Even though there are some conveniences CQL offers, CQL is just a stepping stone to true SQL databases like MySQL, SQLite, and PostgresQL,
Unlike the past slow.db and css.db, this project is an actual useable and feasible database that is fast and complete for beginners to database technology.
If something's wrong or doesn't work how you feel, you can open an issue.
Documentation is available here.
CursorsDB and CQL are available in one package named @cursorsdottsx/cursorsql
, so you can install them with either npm
or yarn
, or any other package manager.
NPM:
$ npm install @cursorsdottsx/cursorsql
Yarn:
$ yarn add @cursorsdottsx/cursorsql
The package also comes with a CLI you can use by installing the package globally and executing cql
or using npx cql
.
Types for TypeScript are included as the project frontend is in TypeScript.
There is some configuration and setup required before you use CQL and the database driver, though.
- First you'll need to use
cql config
to set up CursorsDB. - Next, use
cql
to use the CLI. - Create a new database with the CLI.
- Use the database driver and connect to the database.
Example usage:
import CQLClient from "@cursorsdottsx/cursorsql";
const client = new CQLClient("cql connection string");
await new Promise((resolve, reject) => {
client.on("ready", () => {
console.log("Connected to CursorsQL!");
return resolve();
});
});
CQL has 6 different kinds of statements and only supports basic CRUD. They are as follows:
select
Reading from the databasecreate
Creating a new tableinsert
Inserting into a tableupsert
Upserting into a tableupdate
Updating a tabledelete
Deleting from a table
CQL supports many primitive types and arrays along with nullables.
i8
8 bit integeri16
16 bit integeri32
32 bit integeri64
64 bit integeru8
unsigned 8 bit integeru16
unsigned 16 bit integeru32
unsigned 32 bit integeru64
unsigned 64 bit integerf32
32 bit IEEE-754 floating pointf64
64 bit IEEE-754 floating pointbool
booleanstr
stringnull
null
Suffixing a type with ?
will make the type nullable.
CQL also has a few column constraints.
The constraints are:
max
can be used to enforce a max value for numbers or max length for stringsmin
can be used to enforce a min value for numbers or min length for stringsunique
can be used to enforce a unique column
In addition to constraints, CQL also supports modifiers after a select
statement.
Modifiers will modify the output a select
statement produces.
Currently, all supported modifiers are:
order
will try to order the results as best as it can (1 for ascending and -1 for descending)sort
will sort the results by a column (1 for ascending and -1 for descending)limit
will limit the result count to a maximum value
create =
'create'
table
'{'
( col type ( ( ( 'max' | 'min' ) number ) | 'unique' )* ',' )*
( col type ( ( ( 'max' | 'min' ) number ) | 'unique' )* ( ',' )? )
'}'
';' ;
insert =
'insert'
table
'{'
( '{'
( col ( string | number | boolean ) ',' )*
( col ( string | number | boolean ) ( ',' )? )
'}' ',' )*
( '{'
( col ( string | number | boolean ) ',' )*
( col ( string | number | boolean ) ( ',' )? )
'}' ( ',' )? )
'}'
';' ;
select =
'select'
( '*' | '{' ( col ',' )* ( col ( ',' )? ) '}' )
'from'
table
( 'where' '{'
( col ( '=' | '!' | '>' | '>=' | '<' | '<=' ) ( string | number | boolean ) ',' )*
( col ( '=' | '!' | '>' | '>=' | '<' | '<=' ) ( string | number | boolean ) ( ',' )? )
'}' )?
( ( 'sort' | 'order' | 'limit' ) number )*
';' ;
update =
'update'
table
'{'
( col ( string | number | boolean ) ',' )*
( col ( string | number | boolean ) ( ',' )? )
'}'
( 'where' '{'
( col ( '=' | '!' | '>' | '>=' | '<' | '<=' ) ( string | number | boolean ) ',' )*
( col ( '=' | '!' | '>' | '>=' | '<' | '<=' ) ( string | number | boolean ) ( ',' )? )
'}' )?
';' ;
upsert =
'upsert'
table
'{'
( col ( string | number | boolean ) ',' )*
( col ( string | number | boolean ) ( ',' )? )
'}'
'{'
( col ( string | number | boolean ) ',' )*
( col ( string | number | boolean ) ( ',' )? )
'}'
( 'where' '{'
( col ( '=' | '!' | '>' | '>=' | '<' | '<=' ) ( string | number | boolean ) ',' )*
( col ( '=' | '!' | '>' | '>=' | '<' | '<=' ) ( string | number | boolean ) ( ',' )? )
'}' )?
';' ;
delete =
'delete'
table
(
( 'where' '{'
( col ( '=' | '!' | '>' | '>=' | '<' | '<=' ) ( string | number | boolean ) ',' )*
( col ( '=' | '!' | '>' | '>=' | '<' | '<=' ) ( string | number | boolean ) ( ',' )? )
'}' )?
( ( 'sort' | 'order' | 'limit' ) number )*
)?
';' ;
CursorsML is a really simple markup language with little syntax that CursorsDB uses to store metadata.
In the future, more syntax and semantics will be added to provide more efficient methods of storing data.
The documentation has more information on CursorsML.
- Node.js v16 or newer
- Rust v1.58 or newer
First, install all dependencies with either NPM or Yarn.
NPM:
$ npm install
Yarn:
$ yarn
Next, install dependencies inside the server.
$ cd server/
$ cargo build
Then, create your changes and commit them.
Finally, open a pull request!