SIMPLE_SQL_INSERT_BUILDER
Fluent builder for INSERT statements. Chain .value() calls to add column values.
Value Setting
value (a_column: READABLE_STRING_8; a_value: detachable ANY): like Current
Add column-value pair. Supports STRING, INTEGER, REAL, BOOLEAN, or Void for NULL.
value_raw (a_column: READABLE_STRING_8; a_sql_expr: READABLE_STRING_8): like Current
Add raw SQL expression (e.g., "CURRENT_TIMESTAMP", "datetime('now')").
Conflict Handling
or_replace: like Current
Use INSERT OR REPLACE (upsert based on PRIMARY KEY or UNIQUE constraint).
or_ignore: like Current
Use INSERT OR IGNORE (silently skip if constraint violated).
Execution
execute
Execute the INSERT statement.
to_sql: STRING_8
Generate SQL without executing.
Examples
Basic Insert
db.insert_into ("users")
.value ("name", "Alice")
.value ("email", "alice@example.com")
.value ("age", 30)
.execute
print ("Inserted ID: " + db.last_insert_rowid.out)
Insert with NULL and Raw SQL
db.insert_into ("logs")
.value ("message", "User logged in")
.value ("user_id", 42)
.value ("error_code", Void) -- NULL
.value_raw ("created_at", "datetime('now')")
.execute
Upsert (Insert or Replace)
-- Assumes 'email' has UNIQUE constraint
db.insert_into ("users")
.or_replace
.value ("email", "alice@example.com")
.value ("name", "Alice Updated")
.value ("last_login", "2024-01-15")
.execute
Insert or Ignore (skip duplicates)
db.insert_into ("tags")
.or_ignore
.value ("name", "important")
.execute -- Won't fail if tag already exists
Getting the Inserted ID
After executing an insert, use db.last_insert_rowid to get the auto-generated ID.