Skip to content
Ravi Teja Gudapati edited this page Jan 17, 2019 · 5 revisions

Update statement builder can be used to update records in a table. The table to be updated is provided during construction of the Update statement.

final update = Update('person');

Setting columns values

Use setValue method to set a column in the record.

final update= Update('person').setValue('age', 29);

Use setValues method to set multiple columns with a single call.

final update = Update('person').setValues({
  'name': 'Teja',
  'age': 29,
});

The above statement is equivalent to:

UPDATE person SET name='Teja', age=29;

Use setInt, ``setString, setBool` and `setDateTime` methods to set columns values in a type safe manner.

Filtering

where method is used to add conditional expression to filter which records will be updated by the statement.

final update = Update('person').setValue('name', 'Teja').where(eq('id', 1));

The above statement is equivalent to:

UPDATE person SET name='Teja' WHERE id = 1;

Refer [Conditional expressions][Wiki.Conditional_expression] article to learn how to write conditions for find statement's 'where' clause.

Update statement also provides various convenience methods to add where conditions with less code using methods eq, ne, gt, gtEq, ltEq, lt, like and between. Use and and or methods to build nested conditional expressions.

Executing the statement

Use the exec method to execute an update statement.

final update = Update('person').setValue('name', 'Teja').where(eq('id', 1));

await update.exec(adapter);
Clone this wiki locally