Manual:Database Functions

From Mudlet
Revision as of 02:56, 14 January 2012 by Darmir (talk | contribs) (→‎db:add)
Jump to navigation Jump to search

db:add

db:add(sheet reference, table1, …, tableN)
Adds one or more new rows to the specified sheet. If any of these rows would violate a UNIQUE index, a lua error will be thrown and execution will cancel. As such it is advisable that if you use a UNIQUE index, you test those values before you attempt to insert a new row.
See also: paste


Examples

<lua> --Each table is a series of key-value pairs to set the values of the sheet, but if any keys do not exist then they will be set to nil or the default value.

       db:add(mydb.enemies, {name="Bob Smith", city="San Francisco"})
       db:add(mydb.enemies,
               {name="John Smith", city="San Francisco"},
               {name="Jane Smith", city="San Francisco"},
               {name="Richard Clark"})

</lua> As you can see, all fields are optional.