lua.wetgenes.wiretasks.sqlite_code
wire.tasks("sqlite",1,"require('wiretasks').sqlite_code()",{
sqlite_filename = "./test.sql" ,
sqlite_pragmas = "" ,
})
result = wire.memo({
fifo=wire.fifo("sqlite"),
data={
sql="SELECT name FROM sqlite_master WHERE type='table';",
},
on_result=function() end,
}):resolve()
The code we run in "sqlite" tasks to handle sqlite requests via memos.
This function requires the following libraries to be available.
require("lsqlite3")
As we are opening an sqlite database here it probably wont help you much to have more than one thread per database as they will just fight over file access. To open multiple sqlite databases create multiple tasks with different names.
Globals passed into the thread control the startup actions, primarily you should provide an sqlite_filename to open.
sqlite_filename="./test.sql"
The sqlite database to open when this thread starts.
Most memos are simple SQL queries, but some extra commands exist via data.action
data.action="close"
Shut down the sqlite database, this combined with waiting for the thread to halt allows sqlite to clean up before exiting the process.
When data.action is not set we are performing an SQL query.
data.sql="SELECT name FROM sqlite_master WHERE type='table';",
Will return result.rows filled with data.
data.compact=true
If this boolean is set then we will return compact rows, data.rows will contain rows that are arrays and data.names will be an array of column names. If not set then we return rows as [name]=value objects.
data.binds={ name=value , ... }
Bind these values to an sqlite statement.
data.blobs={ name=value , ... }
Bind these values to an sqlite statement as blobs. This must be used
for sending binary data.