
It does not take a "array like table" containing a set of records to add at once. But! Lua to the rescue

Code: Select all
db:add(mydb.folks, unpack(persontable))
This API is a bit.. fuzzy, and I apologize for that


Code: Select all
db:add(mydb.folks, unpack(persontable))
I caught that last night, then left the window open and went to bed without saving. Heh.Vadi wrote:Lua doesn't allow duplicate table values. Has nothing to do with db at all here. You create a table, then overwrite name Abby with Bob and then with Carlos. So you end up with a table of 1 element.
Code: Select all
echo( "Initializing.\n")
db:create("people", {folks={"name"}})
local mydb = db:get_database("people")
local persontable= {{name="Abby"}, {name="Bob"}, {name="Carlos"}}
db:add(mydb.folks, unpack(persontable))
Code: Select all
echo("Querying " .. matches[2] .. ".\n")
local mydb = db:get_database("people")
local searching = capitalize(matches[2])
local results= db:fetch(mydb.folks, db:eq(mydb.folks.name, searching))
display(results)
No results to speak of.Initializing.
Querying Abby.
Code: Select all
Alias name=Init DB(^init$) matched.
Alias: capture group #1 = <init>
LUA: ERROR running script Init DB (Alias2) ERROR:/home/kris/.config/mudlet/db.lua:517: Failed to
add item: this is probably a violation of a UNIQUE index or other constraint.Alias name=query
Code: Select all
db(^find (\w+)$) matched.
Alias: capture group #1 = <find Abby>
Alias: capture group #2 = <Abby>
LUA: ERROR running script query db (Alias3) ERROR:[string "function Alias3()..."]:4: attempt to
call global 'capitalize' (a nil value)
Code: Select all
Alias name=Init DB(^init$) matched.
Alias: capture group #1 = <init>
LUA: ERROR running script Init DB (Alias2) ERROR:/home/kris/.config/mudlet/db.lua:517: Failed to
add item: this is probably a violation of a UNIQUE index or other constraint.Alias name=query
db(^find (\w+)$) matched.
Alias: capture group #1 = <find Abby>
Alias: capture group #2 = <Abby>
LUA: ERROR running script query db (Alias3) ERROR:[string "function Alias3()..."]:3: attempt to
call method 'fetch_database' (a nil value)