![]() MUDLET STRING FUNCTIONS SERIESĮach 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. 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. It has one index, a compound index tracking the combination of name and area. 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. For sheets with unique indexes, you may specify a _violations key to indicate how the db layer handle cases where the data is duplicate (unique index is violated). IGNORE - The command that would add a record that violates uniqueness just fails silently.A hard error is thrown, cancelling the script. REPLACE - The old record which matched the unique index is dropped, and the new one is added to replace it. Returns a reference of an already existing database. This instance can be used to get references to the sheets (and from there, fields) that are defined within the database. You use these references to construct queries. If a database has a sheet named enemies, you can obtain a reference to that sheet by simply doing: MUDLET STRING FUNCTIONS UPDATEĪt first, update your db:create schema to have the new field. 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. 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. If there is no key, means it doesn't exist yet, so it should be added. order = nil then - do not do the things you see here elsewhere else. ![]() 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. 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. ![]() If it is a simple number, it deletes a specific row by _row_id.If it is a table that contains a _row_id (e.g., a table returned by db:get) it deletes just that record.Otherwise, it deletes every record which matches the query pattern which is specified as with b:get.If the query is simply true, then it will truncate the entire contents of the sheet.Įnemies = db : fetch ( mydb.one When passed an actual result table that was obtained from db:fetch, it will delete the record for that table.Įnemies, true ) Those deletion commands will do in order: city, "San Francisco" )) db : delete ( mydb.two When passed a number, will delete the record for that _row_id.This example shows getting the row id from a table. three As above, but this example just passes in the row id directly.four Here, we will delete anything which matches the same kind of query as db:fetch uses- namely, anyone who is in the city of San Francisco.five And finally, we will delete the entire contents of the enemies table.ĭb:eq db:eq(field reference, value) Returns a database expression to test if the field in the sheet is equal to the value.db:exp db:exp(string) Returns the string as-is to the database. Use this function with caution, but it is very useful in some circumstances. One of the most common of such is incrementing an existing field in a db:set() operation, as so:ĭb : fetch ( mydb.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |