Dado
Database Facilities for LuaSQL

Examples

Here is a simple example of the package's basic use.

local dado = require"dado"
db = dado.connect ("dbname", "username")
db.conn:execute ("drop table mytable") -- direct use of LuaSQL
db:assertexec [[
create table mytable (
    key     integer,
    field1  varchar(10),
    field2  varchar(10),
    adate   date
)]]
data = {
    { field1 = "val1", field2 = "val21", },
    { field1 = "val2", field2 = "val22", },
    { field1 = "val3", field2 = "val32", },
}

-- Insert
for index, record in ipairs(data) do
    record.key = index
    db:insert ("mytable", record)
end

-- Update
local r = data[2]
r.field1 = "field2"
db:update ("mytable", r, "key = "..r.key)

-- Retrieving rows
for field1, field2 in db:select ("field1, field2", "mytable", "key >= 1", "order by key") do
    print(field1, field2)
end

Valid XHTML 1.0!

$Id: examples.html,v 1.4 2008/04/20 21:27:42 tomas Exp $