Skip to content

Commit bca0316

Browse files
committed
Allow values to insert to be passed as array of setters
This lets the columns to be built up dynamically. For example: var values = [name <- "Alice"] if shouldSetEmail { values.append(email <- "[email protected]") } if let insertedID = users.insert(values) { ... }
1 parent 01cb756 commit bca0316

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

SQLite Common/Query.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,19 @@ public struct Query {
449449
return insert([value] + more)
450450
}
451451

452-
private func insert(values: [Setter]) -> (ID: Int?, statement: Statement) {
452+
/// Runs an INSERT statement against the query.
453+
///
454+
/// :param: values An array of values to set.
455+
///
456+
/// :returns: The row ID.
457+
public func insert(values: [Setter]) -> Int? { return insert(values).ID }
458+
459+
/// Runs an INSERT statement against the query.
460+
///
461+
/// :param: values An array of values to set.
462+
///
463+
/// :returns: The row ID and statement.
464+
public func insert(values: [Setter]) -> (ID: Int?, statement: Statement) {
453465
let statement = insertStatement(values).run()
454466
return (statement.failed ? nil : database.lastID, statement)
455467
}

0 commit comments

Comments
 (0)