SIMPLE_SQL_UPDATE_BUILDER

Fluent builder for UPDATE statements. Chain .set() and .where() calls.

View Source

Value Setting

set (a_column: READABLE_STRING_8; a_value: detachable ANY): like Current
Set column to value. Can be called multiple times for multiple columns.
set_raw (a_column: READABLE_STRING_8; a_sql_expr: READABLE_STRING_8): like Current
Set column to raw SQL expression (e.g., "count + 1").

Filtering

where (a_condition: READABLE_STRING_8): like Current
Add WHERE clause to limit which rows are updated.
where (a_condition: READABLE_STRING_8; a_value: detachable ANY): like Current
WHERE with single parameter binding.
Always Use WHERE

Without a WHERE clause, UPDATE affects ALL rows in the table. Always specify conditions unless you intend to update every row.

Execution

execute
Execute the UPDATE statement.
to_sql: STRING_8
Generate SQL without executing.

Examples

Basic Update

db.update ("users")
    .set ("name", "Alice Smith")
    .set ("email", "alice.smith@example.com")
    .where ("id = ?", 42)
    .execute

print ("Updated " + db.changes.out + " rows%N")

Increment Counter

db.update ("articles")
    .set_raw ("view_count", "view_count + 1")
    .where ("id = ?", article_id)
    .execute

Soft Delete (set deleted_at)

db.update ("documents")
    .set_raw ("deleted_at", "datetime('now')")
    .where ("id = ?", doc_id)
    .execute

Set to NULL

db.update ("users")
    .set ("reset_token", Void)  -- Sets to NULL
    .set ("password_changed", 1)
    .where ("id = ?", user_id)
    .execute

Batch Update with Condition

-- Mark all old sessions as expired
db.update ("sessions")
    .set ("expired", 1)
    .where ("last_activity < datetime('now', '-24 hours')")
    .execute

print ("Expired " + db.changes.out + " sessions%N")
Checking Affected Rows

Use db.changes after executing to see how many rows were actually modified.