-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
INSERT INTO multiple values #168
Comments
This sounds great, but we'd need some kind of way to build a type-safe way of handling this: keywords.insert(Word) { rows in
for word in ["A", "B", "C"] {
rows.append(word)
}
} Something like the above. The big issue with most of the type-safe shims in SQLite.swift is the translation layers needed between func insert<A : Value>(Expression<A>, builder: BulkInsertBuilder<A> -> Void)
func insert<A : Value>(Expression<A?>, builder: BulkInsertBuilder<A?> -> Void)
func insert<A : Value, B : Value>(Expression<A>, Expression<B>, builder: BulkInsertBuilder<(A, B)> -> Void)
func insert<A : Value, B : Value>(Expression<A>, Expression<B?>, builder: BulkInsertBuilder<(A, B?)> -> Void)
func insert<A : Value, B : Value>(Expression<A?>, Expression<B>, builder: BulkInsertBuilder<(A?, B)> -> Void)
func insert<A : Value, B : Value>(Expression<A?>, Expression<B?>, builder: BulkInsertBuilder<(A?, B?)> -> Void) It grows exponentially by argument count. If there were a way to define it once and have the type system resolve the wrapping/unwrapping, this would work great. As it stands, I can't figure out a scalable solution. |
Perhaps this would work: keywords.insert(["A", "B", "C"]) { word in
return [Word <- word]
} The function would look like: public func insert<C: CollectionType>(
or action: OnConflict? = nil,
rows: C,
callback: C.Generator.Element -> [Setter]) -> Insert
{
for row in rows {
let values = callback(row)
// ... construct query
}
} |
Just realized that what I suggested isn't type safe :). |
I know Setter probably doesn't work this way, but I was thinking you could use an Array of tuples: var rows = [(Setter<Word>)]()
rows.append((Word <- "A"))
rows.append((Word <- "B"))
rows.append((Word <- "C"))
keywords.insert(rows) That would ensure each row had the same columns. The tricky part is ensuring that insert takes Alternatively you can just run insert multiple times within a transaction. Most of the overhead is going to be in writing to disk anyway. |
Yep. I haven't figured out a maintainable way to build this in Swift yet. We may need to wait for Swift to evolve and have more powerful generic type resolution.
Yeah. I think that's the preferred approach, for now. |
Added to Feature Requests in the "suspended" section, so we don't lose track of this and/or for repeat requests. |
Is there still a way to insert multiple rows in one go ? |
this is very common use case? no update? |
I'd love to insert many values in single query so I build array of Setter
and this produced that query:
while expected is
I must doing something wrong. What should I do to get right query?
The text was updated successfully, but these errors were encountered: