Woori Query Language
Woori Query language or WQL
is WooriDB's Query Language and it is inspired by SparQL, Datalog and SQL. Its main features are:
Transactions
CREATE
entity tree key by name.UNIQUE
: With unique values for entity map keys inside entity tree.ENCRYPTS
: With encrypted values for defined key-values inside entity map.
INSERT
entity map into entity tree.UPDATE
s withSET
orCONTENT
entity map.- SET UPDATE replaces the sent entity map as the entity's map content.
- CONTENT UPDATE updates numerical and string the current entity's map content with the sent entity map value and the other values work the same way as SET.
MATCH UPDATE
updates entity map content with new content if match condition is satisfied.DELETE
s the last entity map content for an entity id.EVICT
- Evicts a specific entity id and entity map
- Evicts all entities in the entity tree key.
Queries
SELECT
the only way to retrieve an entity's content.WHERE
clause is available.WHEN
clause is available
CHECK
the only way to verify keys that are encrypted.
ALL DATA STRUCTURES HASHMAPS, HASHSETS AND LIST MUST CONTAIN A
,
AFTER EACH ELEMENT. Example#{name, ssn,}
is valid but#{name, ssn}
is not valid.
Examples
CREATE
Creates an entity tree key.
CREATE ENTITY my_entity
this will create an entity tree key namedmy_entity
, in SQL terms it meansCREATE TABLE my_entity
.CREATE ENTITY my_entity UNIQUES #{name, ssn,}
the entity tree key namedmy_entity
will only allow unique values for the entities keysname
andssn
in its maps.CREATE ENTITY my_entity ENCRYPTS #{pswd,}
the entity tree key namedmy_entity
will encrypt the entities keys that arepswd
. The hashing cost of the encrypt is defined by the environment variableHASHING_COST
, the recommended is between 10 and 14.- Encrypted keys cannot be unique so
CREATE ENTITY my_entity UNIQUES #{name, ssn, pswd,} ENCRYPTS #{pswd,}
is invalid butCREATE ENTITY my_entity UNIQUES #{name, ssn,} ENCRYPTS #{pswd,}
is valid.
INSERT
Inserts an entity id and an entity map into entity tree key.
INSERT {a: 123, b: "hello julia",} INTO entity_key
this will insert the entity map{a: 123, b: "hello julia",}
(keya
containing asType::Integer(123)
and keyb
containing aType::String("hello julia")
) and a random Uuid for entity ID into entity tree keyentity_key
.
To INSERT entity with a predefined Uuid
it is necessary to use the keyword WITH
after the entity tree key followed by as Uuid-V4. INSERT {a: 123, b: "hello julia",} INTO entity_key WITH 4f6fccb0-20fb-4d8e-af7c-65db30f4954a
.
UPDATE SET
Updates the content by replacing the previous entity map in entity tree key my_entity_name
with the entity id 48c7640e-9287-468a-a07c-2fb00da5eaed
.
UPDATE my_entity_name SET {a: -4, b: 32,} INTO 48c7640e-9287-468a-a07c-2fb00da5eaed
this will replace the current entity map stored in entity id48c7640e-9287-468a-a07c-2fb00da5eaed
.
UPDATE CONTENT
Updates the content by numerical addition or string concatenation of the previous entity map in entity tree key my_entity_name
with the entity id 48c7640e-9287-468a-a07c-2fb00da5eaed
. Non numerical or non string value will just be replaced. If the key doesn't exist it will be created.
UPDATE my_entity_name CONTENT {a: -4, b: 32,} INTO 48c7640e-9287-468a-a07c-2fb00da5eaed
this will add-4
to entity map keya
and add32
to entity map keyb
in the current entity map stored in entity id48c7640e-9287-468a-a07c-2fb00da5eaed
.
MATCH UPDATE
Similar to SET, but it requires a precondition to be satisfied.
MATCH ALL(a == 1, b >= 3, c != \"hello\", d < 7,) UPDATE this_entity SET {a: 123, g: NiL,} INTO d6ca73c0-41ff-4975-8a60-fc4a061ce536
if all conditions defined insideALL
are satisfied the set update will happen.ALL
is an logicaland
between all conditions, meaning that all of them must be true.ANY
is an logicalor
between all conditions, meaning that at least one of them must be true.- NULL KEYS,
ALL
returns an error if a null key is present andANY
just ignores null keys. - Possible conditions are:
==
means equals, so ifa == 100
, this means that the entity map keya
must equal to100
.!=
means not equal, so ifa != 100
, this means that the entity map keya
must not equal to100
.>=
means greater or equal, so ifa >= 100
, this means that the entity map keya
must br greater or equal to100
.<=
means lesser or equal, so ifa <= 100
, this means that the entity map keya
must be lesser or equal to100
.>
means greater, so ifa > 100
, this means that the entity map keya
must be greater than100
.<
means lesser, so ifa < 100
, this means that the entity map keya
must be less than100
.
DELETE
Deletes the last entity map event for an entity ID in entity tree key, that is, it deletes the last state of an entity map.
DELETE 48c7640e-9287-468a-a07c-2fb00da5eaed FROM my_entity_name
this will delete the last state of entity id48c7640e-9287-468a-a07c-2fb00da5eaed
in entity tree keymy_entity_name
from entity history.
EVICT
Removes all occurrences of an entity from the entity tree. It can be just the entity id or the whole entity tree key.
EVICT 48c7640e-9287-468a-a07c-2fb00da5eaed FROM my_entity_name
removes all occurrences of the entity id48c7640e-9287-468a-a07c-2fb00da5eaed
from the entity tree keymy_entity_name
, they cannot be queried anymore.EVICT my_entity
removes the keymy_entity
from the entity tree. It cannot be queried anymore. It is similar to SQL'sDROP TABLE my_entity
.
CHECK
Checks for encrypted key data validity. This transaction only works with keys that are encrypted and it serves as a way to verify if the passed values are true
of false
against encrypted data.
CHECK {pswd: "my-password", ssn: 3948453,} FROM my_entity_name ID 48c7640e-9287-468a-a07c-2fb00da5eaed
this will check if keyspsdw
andssn
from entity id48c7640e-9287-468a-a07c-2fb00da5eaed
in entity tree keymy_entity_name
have the values"my-password"
for pswd and3948453
for ssn.
SELECT
This is the way to query entities from WooriDB. Similar to SQL and SparQL SELECT
.
Possible SELECT
combinations:
SELECT * FROM my_entity_name
selects all entity ids and entity maps for the entity tree keymy_entity_name
with all the possible entities map keys.SELECT #{name, last_name, age,} FROM my_entity_name
selects all entity ids and entity maps for the entity tree keymy_entity_name
with only the keysname, last_name, age
for the entities map.SELECT * FROM my_entity_name ID 48c7640e-9287-468a-a07c-2fb00da5eaed
selects the entity map containing the entity id48c7640e-9287-468a-a07c-2fb00da5eaed
from the entity tree keymy_entity_name
with all the possible entities map keys.SELECT #{name, last_name, age,} FROM my_entity_name ID 48c7640e-9287-468a-a07c-2fb00da5eaed
selects the entity map containing the entity id48c7640e-9287-468a-a07c-2fb00da5eaed
from the entity tree keymy_entity_name
with only the keysname, last_name, age
for the entities map.SELECT * FROM my_entity_name IDS IN #{48c7640e-9287-468a-a07c-2fb00da5eaed, 57c7640e-9287-448a-d07c-3db01da5earg, 54k6640e-5687-445a-d07c-5hg61da5earg,}
this will return the entities map containing the entities ids#{48c7640e-9287-468a-a07c-2fb00da5eaed, 57c7640e-9287-448a-d07c-3db01da5earg, 54k6640e-5687-445a-d07c-5hg61da5earg,}
from entity tree keymy_entity_name
. Keys set is available.Select * FROM my_entity ID 0a1b16ed-886c-4c99-97c9-0b977778ec13 WHEN AT 2014-11-28T21:00:09+09:00
this will select the last entity map state for the entity id0a1b16ed-886c-4c99-97c9-0b977778ec13
in entity tree keymy_entity
at date2014-11-28
. Requires to use DateTime UTC, for now.SELECT * FROM entity_name ID <uuid> WHEN START 2014-11-28T09:00:09Z END 2014-11-28T21:00:09Z
this will select the all entity map states for the entity id0a1b16ed-886c-4c99-97c9-0b977778ec13
in entity tree keymy_entity
in the time range starting at2014-11-28T09:00:09Z
and ending at2014-11-28T21:00:09Z
.SELECT * FROM my_entity WHERE { ?* my_entity:a ?a, ?* my_entity:c ?c, (== ?a 123),(or (>= ?c 4300.0), (< ?c 6.9),),}
this will select all entities ids and entities maps from entity tree keymy_entity
that satisfy the where clause.?* my_entity:a ?a
and?* my_entity:c ?c
define that the entity keysa
andc
from entity tree keymy_entity
will receive the attributed value?a
and?c
respectively.(== ?a 123)
selects all entities which entity map keya
is equal to123
.(or (>= ?c 4300.0), (< ?c 6.9),)
selects all entities which entity map keyc
is greater than or equal to4300.0
or is smaller than6.9
.
WHERE Clause
Possible functions for the where clause:
in
:(in ?k1 123 34543 7645 435)
,?k1
must be present in the set containing123 34543 7645 435
. NOTE: for now, please don't use,
.between
:(between ?k1 0 435)
,?k1
must be between starting value0
and ending value435
. If you set more than 2 arguments it will return aClauseError
.like
:(like ?k2 "%naomi%")
, like is comparing?k2
with the string"%naomi%"
considering that%
are wildcards."%naomi"
meansend_with("naomi")
,"naomi%"
meansstarts_with("naomi")
and"%naomi%"
meanscontains("naomi")
. Possible regex support in the future.==
,>=
,>
,<
,<=
,!=
->(>= ?k1 0)
which means get all values that?k1
is greater than or equal to0
.or
: All arguments inside theor
function call will be evaluated totrue
if any of them istrue
.
Relation Algebra
Some relation algebra may be implemented:
- Projection
- Union
- Intersection
- Difference (SQL's EXCEPT?)
- Join
- Product (SQL's CROSS JOIN?)
- Assign
- Dedup
- Sort
- Aggregate
- Division
Entity map value TYPES
Types Notes
Precise floats or numbers larger than f64::MAX/i128::MAX can be defined with an UPPERCASE
P
at the end.
- Note: This type cannot be updated with
UPDATE CONTENT
.- Ex.:
INSERT {a: 98347883122138743294728345738925783257325789353593473247832493483478935673.9347324783249348347893567393473247832493483478935673P, } INTO my_entity
.
BLOB
will not be supported. Check out To BLOB or Not To BLOB: Large Object Storage in a Database or a Filesystem
-
Char(char)
contains the type char defined by'c'
, -
Integer(isize)
contains the type isize, just a number without.
, -
String(String)
contains any value passed with"this is a string"
, -
Uuid(Uuid)
contains anUuid V4
, -
Float(f64)
contains the type f64, any number containing.
, -
Boolean(bool)
contains type booleantrue
offalse
, -
Vector(Vec<Types>)
contains a vector ofTypes
, -
Map(HashMap<String, Types>)
contains a HashMap of keyString
and valueTypes
, -
Hash(String)
contains a Hash generated byENCRYPTS
, -
Precise(String)
contains a very large integer or a very large float, -
Nil
contains anull/nil
value, -
DateTime
contains a DateTime