-
Hey GRDB community, I'm looking at implementing a form of optimistic concurrency control / optimistic locking on top of some of our tables as part of a synchronisation process. Ultimately what I'm trying to do is create a statement akin to I can do that using the query interface directly, but I can't see a way to customise the WHERE clause when working with a Record, or is this perhaps how Any suggestions would be much appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 9 replies
-
Hello @bok-,
Indeed GRDB provides no way to customize the WHERE clause of the
:-) Indeed it is always possible to talk to the database. But I have difficulties figuring out what your technique can be. The only updating method that allows configuration of the WHERE clause is the // UPDATE player
// SET name = ..., score = ...
// WHERE id = xxx and checksum = yyy
let updatedPlayersCount = try Player
.filter(id: xxx)
.filter(Column("checksum") == yyy)
.updateAll(db, [
Column("name").set(to: player.name),
Column("score").set(to: player.score),
])
It is not. The role of var player = Player(id: 1, name: "Bob", score: 500)
// UPDATE player SET score = 1000 WHERE id = 1 -- name not updated
try player.updateChanges(db) { $0.score = 1000 }
// Does not hit the database
try player.updateChanges(db) { $0.score = 1000 }
I don't think there exist any public api that allows you do to that. For example you can't create a Well done, @bok-, you just wrote a very interesting feature request :-) |
Beta Was this translation helpful? Give feedback.
Hello @bok-,
Indeed GRDB provides no way to customize the WHERE clause of the
UPDATE
statements generated by theupdate
family of record instance methods. It is made of the primary key and only the primary key.:-) Indeed it is always possible to talk to the database.
But I have difficulties figuring out what your technique can be. The only updating method that allows configuration of the WHERE clause is the
request.updateAll(db, assignments)
method. Maybe you write something as below?