title: “NOSQL::SET Function” author: “Pierre Laplante laplante@plcb.ca” date: “2024-06-19” version: “1.0.0” section: “1g”
nosql::set stores a value associated with the specified key in the database.
nosql::set(key, data [, db: database, error: id])
The nosql::set
function stores a value associated with the specified key in the database.
If the database parameter is not specified, the function will use an in-memory database.
{{
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"]
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
Pierre Laplante laplante@plcb.ca