This is a complete database library made for (Principal of Programming course in University of Shiraz)
- first create a
Context
object - open/create database
- execute commands with
ctx.exec
to control your data - read result of each command at
context.res()
and access to result data oncontext.rows()
- at last its better to
close
the context, alsoclean
context after you're done with its result
Note that all commands are case-insensitive you can use how case you want.
Select(<TableName>, <cols>, <query>)
ORSelect(<TableName>, <query>, <cols>)
- select some
DataRow
s from table and read their requested columns that matched in requested Query - you can
<TableName>
name of target table bare or wrapped in"
or'
or ` (str-format)<cols>
list of column names styled like above and wrapped in[ ... ]
to load these columns on each result rows, if not provided: all columns of table will be loaded, if you just wantRow
without their data, just pass an empty list ([]
)<query>
if provided, limits the resulting rows to match the required Query
- select some
- Comparators Commands:
<cmp>(col, data)
- use bellow functions in
<cmp>
to preform compare Queries EQ
as equals,NEQ
andNE
as not-equalsGT
as greater-than,GE
as greater-than-or-equalsLT
as less-than,LE
as less-than-or-equalsNGT
isLE
,NGE
isLT
,NLT
isGE
,NLE
isGT
In( <col>, <list> )
check value in<list>
(lst-format required),NIN
is its opposite
- use bellow functions in
- Logical Commands:
NOT( <query> )
inverse the result returned by query insideAND( <q1> , <q2> , ... )
join all query results and return results presented on all queriesOR( <q1> , <q2> , ... )
merge all query results and return results presented at least on one query
- Table Commands:
CreateTable( <name>, {<col:type>, ...} )
- create a table named
<name>
with columns with requested type. columns must send in set-format{ ... }
each follows<col>:<typ>
format.
- create a table named
DeleteTable( <name> )
Delete table<name>
from database
- Data Commands:
Insert( <table>, { <set1> }, { <set2> }, ...)
- insert data into
<table>
each data represented by its<set>
argument (set-format is required). - each
<set>
contains set of<col>=<val>
to assign data to each data cell <val>
type must match<col>
type
- insert data into
Update( <table>, { <set> }, <query>)
- update all rows matched in
<query>
with<set>
parameter - every parameter matches exactly like other functions described above
- update all rows matched in
Remove( <table>, <query> )
- Remove all rows in
table
matches inquery
- Remove all rows in
There is 4 DataType implemented in this Database:
Byte
orChar
and their arraysByte[fixed]
,Char[fixed]
Int
andInt[fixed]
hold any IntegersReal
andReal[fixed]
holds all Double/Float numbersText
variable size string without any restrictions- In later versions other types than Text, may able to have Variable-Size array
You can call exec
to run requested actions, also you can pass list of varargs
to fill in the gaps.
- VarArgs Gap Style
${<index>:<typ>}
:<index>
is optional and if its not provided every gap gets its own index start from 1 and continues.<typ>
follows like any DataType parameter rules mentioned above.
- String Format:
"<text>"
,'<text>'
, or`<text>`
- List Format:
[ <element1>, <element2>, ... ]
- Set Format:
[ <element1>, <element2>, ... ]
- Function Format:
<func>( <param1>, <param2>, ... )
- Parenthesis Format:
( ... )
- VarArgs Format:
${<index>:<typ>}
or${<typ>}
- Column Type Format:
<colName>:<type>
- Type Format:
<typ>
or<typ>[<elementCount>]
you can see test-context.cpp and test-bookstore.cpp in tests folder to see how to use this library also here some command examples:
CREATETABLE(students, id:int, name:text, grade:real, year:byte)
InserT(students, {id=1}, {id=2}, {id=3})
uPDATE(students, {id=10}, eq(id, 2))
select(students,[year])
SELECT(students,eq(year,255))
Select(students,and( nEQ(year,94) , neq(id,1374) ))
- add
OpenDatabase
,CloseDatabase
,DeleteDatabase
,ClearDatabase
database commands - add
sort
query command - add
like
,contains
,exists
,startsWith
,endsWith
, 'ignorecase' in string query commands - add
CompactTable
or something similar to compact database (remove additional space between rows) - add
Len(col)
,Count(<query>)
,Max(<col>)
,Min(<col>)
,Avg(<col>)
,Round
,isEmpty(<col>)
- add Index meta files, UniqueIndex, PrimaryKeyIndex
- add
Comment
to commands (assembly, c, ... style)