Code examples¶
Custom APIs, hooks, events, schedulers, migrations, process initializers and test cases all receive the same global object g. Every page of this section is one method of it, with a snippet you can paste into the editor of the admin panel.
Every snippet has the same shape :
dbg.sys.dbThe 17 schema APIs of a table, from get all to distinct with query.
geng.sys.db.genThe same 17 operations without the schema.
sysg.sys.systemEncrypt, hash, tokens, secrets, queries, indexes, events, validation, external calls.
⚡g.sys.cacheRedis keys and cache resets.
reqg.reqBody, headers, params, query params, event data and the tokens of the caller.
resg.resOutput, status code, errors, warnings, content type.
</>Custom APIA complete custom API, from the settings to the code.
≡g.logger and g.sharedLogs which reach the caller and the log table, and values shared between hooks.
The second argument
Every g.sys call takes an optional second argument. With true, the call returns the whole response envelope and never throws : const res = await g.sys.db.count({ ... }, true); if (!res.success) .... Without it, the call returns data and throws the errors, so the caller of your API gets them.