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
CREATEentity 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.
INSERTentity map into entity tree.UPDATEs withSETorCONTENTentity 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 UPDATEupdates entity map content with new content if match condition is satisfied.DELETEs 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
SELECTthe only way to retrieve an entity's content.WHEREclause is available.WHENclause is available
CHECKthe 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_entitythis 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_entitywill only allow unique values for the entities keysnameandssnin its maps.CREATE ENTITY my_entity ENCRYPTS #{pswd,}the entity tree key namedmy_entitywill 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_keythis will insert the entity map{a: 123, b: "hello julia",}(keyacontaining asType::Integer(123)and keybcontaining 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-2fb00da5eaedthis 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-2fb00da5eaedthis will add-4to entity map keyaand add32to entity map keybin 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-fc4a061ce536if all conditions defined insideALLare satisfied the set update will happen.ALLis an logicalandbetween all conditions, meaning that all of them must be true.ANYis an logicalorbetween all conditions, meaning that at least one of them must be true.- NULL KEYS,
ALLreturns an error if a null key is present andANYjust ignores null keys. - Possible conditions are:
==means equals, so ifa == 100, this means that the entity map keyamust equal to100.!=means not equal, so ifa != 100, this means that the entity map keyamust not equal to100.>=means greater or equal, so ifa >= 100, this means that the entity map keyamust br greater or equal to100.<=means lesser or equal, so ifa <= 100, this means that the entity map keyamust be lesser or equal to100.>means greater, so ifa > 100, this means that the entity map keyamust be greater than100.<means lesser, so ifa < 100, this means that the entity map keyamust 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_namethis will delete the last state of entity id48c7640e-9287-468a-a07c-2fb00da5eaedin entity tree keymy_entity_namefrom 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_nameremoves all occurrences of the entity id48c7640e-9287-468a-a07c-2fb00da5eaedfrom the entity tree keymy_entity_name, they cannot be queried anymore.EVICT my_entityremoves the keymy_entityfrom 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-2fb00da5eaedthis will check if keyspsdwandssnfrom entity id48c7640e-9287-468a-a07c-2fb00da5eaedin entity tree keymy_entity_namehave the values"my-password"for pswd and3948453for ssn.
SELECT
This is the way to query entities from WooriDB. Similar to SQL and SparQL SELECT.
Possible SELECT combinations:
SELECT * FROM my_entity_nameselects all entity ids and entity maps for the entity tree keymy_entity_namewith all the possible entities map keys.SELECT #{name, last_name, age,} FROM my_entity_nameselects all entity ids and entity maps for the entity tree keymy_entity_namewith only the keysname, last_name, agefor the entities map.SELECT * FROM my_entity_name ID 48c7640e-9287-468a-a07c-2fb00da5eaedselects the entity map containing the entity id48c7640e-9287-468a-a07c-2fb00da5eaedfrom the entity tree keymy_entity_namewith all the possible entities map keys.SELECT #{name, last_name, age,} FROM my_entity_name ID 48c7640e-9287-468a-a07c-2fb00da5eaedselects the entity map containing the entity id48c7640e-9287-468a-a07c-2fb00da5eaedfrom the entity tree keymy_entity_namewith only the keysname, last_name, agefor 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:00this will select the last entity map state for the entity id0a1b16ed-886c-4c99-97c9-0b977778ec13in entity tree keymy_entityat 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:09Zthis will select the all entity map states for the entity id0a1b16ed-886c-4c99-97c9-0b977778ec13in entity tree keymy_entityin the time range starting at2014-11-28T09:00:09Zand 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_entitythat satisfy the where clause.?* my_entity:a ?aand?* my_entity:c ?cdefine that the entity keysaandcfrom entity tree keymy_entitywill receive the attributed value?aand?crespectively.(== ?a 123)selects all entities which entity map keyais equal to123.(or (>= ?c 4300.0), (< ?c 6.9),)selects all entities which entity map keycis greater than or equal to4300.0or is smaller than6.9.
WHERE Clause
Possible functions for the where clause:
in:(in ?k1 123 34543 7645 435),?k1must be present in the set containing123 34543 7645 435. NOTE: for now, please don't use,.between:(between ?k1 0 435),?k1must be between starting value0and ending value435. If you set more than 2 arguments it will return aClauseError.like:(like ?k2 "%naomi%"), like is comparing?k2with 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?k1is greater than or equal to0.or: All arguments inside theorfunction call will be evaluated totrueif 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
Pat the end.
- Note: This type cannot be updated with
UPDATE CONTENT.- Ex.:
INSERT {a: 98347883122138743294728345738925783257325789353593473247832493483478935673.9347324783249348347893567393473247832493483478935673P, } INTO my_entity.
BLOBwill 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 booleantrueoffalse, -
Vector(Vec<Types>)contains a vector ofTypes, -
Map(HashMap<String, Types>)contains a HashMap of keyStringand valueTypes, -
Hash(String)contains a Hash generated byENCRYPTS, -
Precise(String)contains a very large integer or a very large float, -
Nilcontains anull/nilvalue, -
DateTimecontains a DateTime