/rosemary

Rosemary is an embedded database similar to SQLite written in Rust.

Primary LanguageRustMIT LicenseMIT

Rosemary DB

Software in process of development. Don't have any high expectations.

Rosemary is an embedded database similar to SQLite written in Rust. Query language inspired by stack-based programming.

Quick Start

$ cargo run

Database Reference

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>
...

Column types

Database support integers and strings with max length of 50.

Example:

table
id:Int
name:Str

Literals

Integer

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

String

Any sequence of characters that contain not only decimal digits will be a string.

Example:

query > name select

Operations

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

insert

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

delete

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

filter-and

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

filter-or

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

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

Usage

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 >

filters combination

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 )