nut.db.update - brianhang/nutscript2 GitHub Wiki

Description

nut.db.update(tableName, data, condition, callback, limit)

This server function updates certain rows within the database to the given values. The keys of data determine which fields within the tableName table are updated and the values are what the corresponding fields are updated to. Rows are only updated if they satisfy condition. The number of rows can be limited by the limit parameter.

Parameters

Name Description
tableName Which table is updated within the database.
data The fields and values that are updated. If data is empty, then the function does nothing.
condition An optional string that is used to determine which row(s) are updated.
callback An optional function that is called after the update query is done. The only parameter is result, which is the result of the update. If result is nil, that means an error was encountered.
limit An optional parameter that is used to limit the number of rows that can be updated. If limit is a number, then that is the maximum number of rows. If limit is nil, then there is no limit. If limit is a string, then it can be used for complex limits.

Side Effects

  • The database is updated.

Errors

  • data is not a table

Example

-- Renames all characters named John to Johnny.
nut.db.update("characters", {name = "Johnny"}, "name = 'John'")