NOSQL::KEYS 1g 2024-06-19 laplante@plcb.ca GOWEB/NOSQL


title: “NOSQL::KEYS Function” author: “Pierre Laplante laplante@plcb.ca” date: “2024-06-19” version: “1.0.0” section: “1g”

category: “GOWEB/NOSQL”

Name

nosql::keys returns an array containing all the keys stored in the database.

Synopsis

nosql::keys([db: database, error: id])

Description

The nosql::keys function returns an array containing all the keys stored in the database.
If the database parameter is not specified, the function will operate on an in-memory database.

Examples

{{
    res := nosql::open("/tmp/xx");
    nosql::set(res, "kint", 1);
    "kint="; nosql::get(res, "kint"); "\n";
    nosql::set(res, "kfloat", 3.1415);
    "kfloat="; nosql::get(res, "kfloat"); "\n";
    nosql::set(res, "kstring", "String");
    "kstring="; nosql::get(res, "kstring"); "\n";
    nosql::set(res, "kbool", true);
    "kbool="; nosql::get(res, "kbool"); "\n";
    id := "mystrid";
    nosql::set(res, "kid", id);
    "kid="; nosql::get(res, "kid"); "\n";
    a := [1, 3.1515, "string", true];
    nosql::set(res, "karray", a);
    "karray="; nosql::get(res, "karray"); "\n";
    nosql::set(res, "kmap", {"x" : 2, "y" : 3.1414});
    "KMAP="; nosql::get(res, "kmap"); "\n";
    "--- DUMP ---\n";
    x := nosql::dump(res);
    "x="; x; "\n";
    "--- DUMP ---\n";
    nosql::get(res, "xywhdue", error : err);
    "errget = "; err; "\n";
    nosql::delete(res, "xywhdue", error : err);
    "errdelete = "; err; "\n";
    nosql::exist(res, "xywhdue", error : err);
    "errexist = "; err; "\n";
    "keys = "; nosql::keys(res); "\n";
    nosql::close(res);
}}

Output:

kint=1
kfloat=3.1415
kstring=String
kbool=true
kid=mystrid
karray=[1,3.1515,"string",true]
KMAP={"x":2,"y":3.1414}
--- DUMP ---
x={"karray":[1,3.1515,"string",true],"kbool":true,"kfloat":3.1415,"kid":"mystrid","kint":1,"kmap":{"x":2,"y":3.1414},"kstring":"String"}
--- DUMP ---
errget = nosql::get : problem getting key 'xywhdue' : Key not found
errdelete =
falseerrexist =
keys = ["karray","kbool","kfloat","kid","kint","kmap","kstring"]

Example with TTL

res={{
    dbdir := "/tmp/ttl";
    remove(recursive:true, dbdir);
    db := nosql::open(dbdir);
    nosql::set_ttl(db, "mykey", "myvalue", "1s");
    "key="; nosql::get(db, "mykey"); "\n";
    flush();
    sleep("2s");
    nosql::get(db, "mykey", error:err);
    "err="; err;
}}

Output:

res=key=myvalue
err=nosql::get : problem getting key 'mykey' : Key not found

Author

Pierre Laplante laplante@plcb.ca

See also

Version