all repos — min @ 505e95942dd8879db3b68ae58c86e9a07bf39556

A small but practical concatenative programming language.

site/contents/reference-store.md

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
-----
content-type: "page"
title: "store Module"
-----
{@ _defs_.md || 0 @}

{#op||delete||{{dstore}} {{sl}}||{{dstore}}||
Removes an item from the datastore {{dstore}}. The item is uniquely identified by {{sl}}, which contains the collection containing the item and the item id, separated by a forward slash (/). Puts the reference to the modified datastore back on tbe stack.
 #}
 
{#op||get||{{dstore}} {{sl}}||{{d}}||
Retrieves item {{d}} from datastore {{dstore}}. {{d}} is retrieved by specifying {{sl}}, which contains the collection containing the item and the item id, separated by a forward slash (/).
 #}

{#op||has?||{{dstore}} {{sl}}||{{b}}||
Returns {{t}} if {{dstore}} has a key called {{sl}} (which contains the collection containing the item and the item id), {{f}} otherwise.#}

{#op||init||{{sl}}||{{dstore}}||
Initializes a bew datastore by creating the {{sl}} JSON file. Puts the datastore instance on the stack. #}

{#op||post||{{dstore}} {{sl}} {{d}}||{{dstore}}||
Adds the dictionary {{d}} to the datastore {{dstore}} inside collection {{sl}}, generating and adding a unique **id** field to {{d}}. If the collection {{sl}} does not exist it is created. Puts the reference to the modified datastore back on tbe stack.
 #}
 
{#op||put||{{dstore}} {{sl}} {{d}}||{{dstore}}||
Adds the dictionary {{d}} to the datastore {{dstore}}. {{sl}} contains the collection where {{d}} will be placed and the id of {{d}}, separated by a forward slash (/). If the collection {{sl}} does not exist it is created. Puts the reference to the modified datastore back on tbe stack.
 #}
 
{#op||query||{{dstore}} {{sl}} {{q}}||({{d0p}})||
> Retrieves a quotation of dictionaries from the collection {{sl}} of datastore {{dstore}} obtained by applying {{q}} as a filter to each item of the collection, picking only the elements that match the filter.
>
> > %sidebar%
> > Example
> >
> > Assuming that **ds** is a datastore, the following program retrieves all elements of teh collection **posts** whose author field is set to "h3rald":
> >
> >      ds "posts" ('author dget "h3rald" ==) dquery
 #}

{#op||read||{{sl}}||{{dstore}}||
Reads the previously-created datastore from the file {{sl}} and puts the resulting datastore instance on the stack.
 #}

{#op||write||{{dstore}}||{{dstore}}||
Writes the contents of the datastore {{dstore}} to the filesystem.
 #}