Skip to content
Brian edited this page May 15, 2016 · 2 revisions
 update(tableName[, options])

JSQL query used to update a record in the database.

Table of Contents

Parameters

tableName

The name of the table to update. update will throw an error if tableName is an empty string or ends with a period.

If the name contains a space, everything after the last space will be ignored.

If the name contains a period, everything before the last period (which is also before the last space) will be used to choose the schema to store the table in. If the name does not contain a period, the default schema will be used.

The name "triggers" is reserved, and may not be used for the table.

options (optional)

See options for additional information.

Options for modifying the behavior of the update query.

Property Default Explanation
useTransaction null If set to a Transaction object, executing the query will add the query to the transaction's queue instead of actually executing it.

Returns

The update function returns a Update object, which is a subclass of cls.QueryBuilder. This object has the following functions you can use to build your query:

field(name[, value])

Sets a single field of the records to be updated, and optionally the value for that field.

Parameter Type Optional Remarks
name String No Must be non-empty
value varies Yes The value will be fed into the type handler for the given field before being stored in the database.

value(value)

Sets a single value of the records to be updated.

Parameter Type Optional Remarks
value varies No The value will be fed into the type handler for the given field before being stored in the database.

fields(names[, values])

Sets multiple fields of the records to be updated, and optionally the values for those fields.

Parameter Type Optional Remarks
names Array of Strings No Must have at least one element, and all elements must be non-empty.
values Array Yes Must have the same number of elements as names. Each value will be fed into the type handler for the given field before being stored in the database.

fields(...names)

Sets multiple fields of the records to be updated.

Parameter Type Optional Remarks
names String args No Must have at least one argument, and all arguments must be non-empty.

fields(fields)

Sets multiple fields of the records to be updated as well as their values.

Parameter Type Optional Remarks
fields Object No Must have at least one key. Each key must be a non-empty string. Each value will be fed into the type handler for the given field before being stored in the database.

values(values)

Sets multiple values of the records to be updated.

Parameter Type Optional Remarks
values Array or args No Must have at least one element or at least one argument. Each value will be fed into the type handler for the given field before being stored in the database.

where(...expr)

Creates a condition to limit what records are updated. See expr for more information.

Parameter Type Optional Remarks
expr varies args No At least one argument must be supplied. For each argument:
  • If it is an instance of cls.Expression, that expression will be used.
  • If it is a String, it will be parsed into an Expression
  • Otherwise, it will be the operand to an Identity Expression

execute([options])

Performs the update operation.

options.useTransaction can override the same option specified in update and cls.DefaultOptions.

If the number of fields and the number of values specified by various calls to field, value, fields, and values are not the same, this function will throw an error.

This function will return the number of records updated.

Clone this wiki locally