
three As above, but this example just passes in the row id directly.This example shows getting the row id from a table. two When passed a number, will delete the record for that _row_id.one When passed an actual result table that was obtained from db:fetch, it will delete the record for that table.enemies, true ) Those deletion commands will do in order: city, "San Francisco" )) db : delete ( mydb. If the query is simply true, then it will truncate the entire contents of the sheet.Įnemies = db : fetch ( mydb.Otherwise, it deletes every record which matches the query pattern which is specified as with b:get.If it is a table that contains a _row_id (e.g., a table returned by db:get) it deletes just that record.If it is a simple number, it deletes a specific row by _row_id.The argument for query tries to be intelligent: namedb - observe that we use the REAL type by default instead and a default of 0 local sql_add = ] conn : execute ( sql_add ) conn : commit () end end db:delete db:delete(sheet reference, query) Deletes rows from the specified sheet. namedb - order should be a text field, so note that we specify it's type with TEXT and the default value at the end with "" local sql_add = ] conn : execute ( sql_add ) conn : commit () end - here is an another example, in one where we need to add a field that is a number if someperson. order = nil then - do not do the things you see here elsewhere else. If there is no key, means it doesn't exist yet, so it should be added. people ) - this requires at least one entry in the database to work if next ( test ) then local _, someperson = next ( test ) - in this example, we want to add an order key. then, we'll tell the database to create it if it doesn't exist - fetch the data we've got in our sample database local test = db : fetch ( ndb.

#MUDLET TABLES UPDATE#
at first, update your db:create schema to have the new field. If a database has a sheet named enemies, you can obtain a reference to that sheet by doing: You use these references to construct queries. This instance can be used to get references to the sheets (and from there, fields) that are defined within the database. Returns a reference of an already existing database.

The second sheet has two indexes, but one is unique: it isn’t possible to add two items to the enemies sheet with the same name. It has one index, a compound index tracking the combination of name and area.

enemies, ) The above will create a database with two sheets the first is kills and is used to track every successful kill, with both where and when the kill happened.
#MUDLET TABLES SERIES#
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.
#MUDLET TABLES PLUS#
Returns nil plus the error message if the operation failed (so it won't raise a runtime error in Mudlet). As such it is advisable that if you use a UNIQUE index, you test those values before you attempt to insert a new row. If any of these rows would violate a UNIQUE index, a lua error will be thrown and execution will cancel.
#MUDLET TABLES HOW TO#
They are in addition to the LuaSQL sqlite driver that's available directly within Mudlet (also see the LuaSQL manual for comparison).įor a tutorial on how to get started with the database functions, see here.ĭb:add db:add(sheet reference, table1, …, tableN) Adds one or more new rows to the specified sheet. These database functions make using a database with Mudlet easier.
