Lighter icon indicating copy to clipboard operation
Lighter copied to clipboard

Add an option to generate `INSERT OR REPLACE` instead of just `INSERT`

Open andlang opened this issue 10 months ago • 0 comments

It would be great to have an option (or parameter) to not only have INSERT statements, but also INSERT OR REPLACE.

In my use case, with 250k entries, where I just want to add and update entries, it is around 50 times faster, to use INSERT OR REPLACE instead of something like:

let oldIDs = Set(try await database.select(from: \.solarBodies, \.id))

let recordsToUpdate = result.bodies.filter {  oldIDs.contains($0.id) }
let recordsToInsert = result.bodies.filter { !oldIDs.contains($0.id) }

try await database.transaction { tx in
    try tx.update(recordsToUpdate)
    try tx.insert(recordsToInsert)
}

Or would there be a better option, that Lighter has already included?

andlang avatar Feb 10 '25 11:02 andlang