Rosemary is an embedded database similar to SQLite written in Rust. Query language inspired by stack-based programming.
$ cargo run
For now database support work with one table. Structure of the table can be changed with table schema file.
Schema file have next structure
<table_name>
<column_name>:<column_type>
<column_name>:<column_type>
<column_name>:<column_type>
...
Database support integers and strings with max length of 50.
Example:
table
id:Int
name:Str
Currently an integer is a sequence of decimal digits that optionally starts with a dash (-) to indicate a negative integer.
Example:
query > * select id 3 == filter-and
Any sequence of characters that contain not only decimal digits will be a string.
Example:
query > name select
The select
operation is used to select data from a table.
select
syntax
<column_name> <column_name> ... select
Example:
query > id name select
0 John
1 Alexey
The insert
operation is used to insert new records in a table. Provided arguments must be the same type as columns and in corresponding order.
insert
syntax
<arg> <arg> ... insert
Example:
query > 0 Emily insert
The delete
operation is used to delete existing records in a table. delete
operation expect a column name and a value, all rows with that value will be deleted.
delete
syntax
<column_name> <value> delete
Example:
query > id 5 delete
The filter-and
operation is used to extract only those records that fulfill a specified condition. filter-and
operation expect a sequence of conditions and must be used after select
operation. The operation displays a record if all conditions is true.
filter-and
syntax
* select <condition> <condition> filter-and
Example:
query > * select id 3 > name == John filter-and
The filter-or
acts like a filter-and
operation but displays a record if any of the conditions is true.
filter-or
syntax
* select <condition> <condition> filter-or
Example:
query > * select id 3 > name == John filter-or
Conditions used with filter-and
and filter-or
operations. All of them have the same syntax.
Currently supported four conditions: ==
(equal), !=
(not equal), <
(less than), >
(more than).
Conditions syntax
<column_name> <value> condition
To provide a query go to query mode with command query
. query >
prompt indicates that you in query mode.
> query
query >
To exit from query mode or program use exit
command.
query > exit
>
To be able to write mulitline queries put a (
in query to go to muliline query mode. query :
prompt indicates that you in multiline query mode.
In this mode all lines will be executed as one query.
query > ( * select
query :
To end multiline query put a )
in a query.
query > ( * select
query : id 5 == filter-and )
query >
You can combine several filter-and
and filter-or
operation ot produce complicated conditions.
Example:
query > ( * select
query : id 2 > id 5 < filter-and
query : name John == name Emily == filter-or )