diff options
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 28 |
1 files changed, 15 insertions, 13 deletions
@@ -51,7 +51,7 @@ then exit. This behavior is useful when you want to have a script file with an access to the luna API. If luna is started with -D flag it will accept user input into its stdio. The -input is executed in Lua state as is or (if `luna.evalfn` was called in +input is executed in Lua state as is or (if `luna.onEval` was called in LUAFILE) is passed to a custom eval handler. ## Lua API @@ -60,9 +60,11 @@ All API functions return 2 values: the first one is a boolean indicating if the call was successful (true for successful and false if there was an error) and the second one is the value (or an error text if the call was unsuccessful). -API names are hyphenated since I am mostly calling the functions from -[fennel language](https://fennel-lang.org/) and for lisps hyphenation is the -norm. +All API names have hyphenated alternatives since I am mostly calling the +functions from [fennel language](https://fennel-lang.org/) and for lisps +hyphenation is the norm. So for example you can call `luna.db.execTx` also +as `luna.db["exec-tx"]`, `luna.http.encodeURL` as `luna.http["encode-url"]` +and so on. Every argument in every API function is required: luna does not support optional arguments yet. Pass an empty value for corresponding type instead if you do not @@ -99,7 +101,7 @@ luna.http.request("GET", "https://git.sr.ht", {Accept = "text/html"}, "") ``` -__luna.http\["encode-url"\](string)__: +__luna.http.encodeURL(string)__: encodes a STRING for a safe usage in URLs. @@ -126,7 +128,7 @@ commits a transaction TX. ```lua local ok, tx = luna.db.begin(db) -local ok, err = luna.db["exec-tx"](tx, "DELETE FROM foobar;") +local ok, err = luna.db.execTx(tx, "DELETE FROM foobar;") local ok, err = luna.db.commit(tx) ``` @@ -136,18 +138,18 @@ rolls back a transaction TX. ```lua local ok, tx = luna.db.begin(db) -local ok, err = luna.db["exec-tx"](tx, "DELETE FROM foobar;", {}) +local ok, err = luna.db.execTx(tx, "DELETE FROM foobar;", {}) local ok, err = luna.db.rollback(tx) -- the tx was rolled back so "DELETE FROM foobar;" isn't executed ``` -__luna.db\["exec-tx"\](tx, query, args)__: +__luna.db.execTx(tx, query, args)__: executes a QUERY with ARGS in the context of a given transaction TX. ```lua local ok, tx = luna.db.begin(db) -local ok, err = luna.db["exec-tx"]( +local ok, err = luna.db.execTx( tx, "INSERT INTO foobar VALUES (?, ?, ?);" {1, "hello!", "2024-12-26 12:00:00"} @@ -185,13 +187,13 @@ local ok, res = luna.db.query( ``` -__luna.db.\["query\*"\](db, query, args)__: +__luna.db.queryAssoc(db, query, args)__: executes a QUERY with ARGS in a given DB and returns result as an array of tables where keys are column names and values are associated value: ```lua local ok, db = luna.db.open("file:var/db.sqlite?_journal=WAL&_sync=NORMAL") -local ok, res = luna.db["query*"]( +local ok, res = luna.db.queryAssoc( db, "SELECT * FROM foobar WHERE name = '?'", {"hello!"} @@ -232,7 +234,7 @@ __luna.crypto.sha1(string)__: returns hex-encoded SHA1 hash of a STRING. -__luna.evalfn(handler)__: +__luna.onEval(handler)__: sets an eval handler for server commands. Handler accepts one argument TEXT. If the server is started with -D flag it starts listening for input from stdio. In this case if eval handler is set the handler will receive the user input and @@ -241,7 +243,7 @@ executed in Lua state as is. ``` local fennel = require("fennel") -luna.evalfn(function (text) fennel.eval(text, {env = _G}) end) +luna.onEval(function (text) fennel.eval(text, {env = _G}) end) ``` |
