Skip to content
Discussion options

You must be logged in to vote

This won't work:

self.id = sourceSequence.hashValue ^ targetSequence.hashValue

Hash values are not stable across launches of the app (nor are they guaranteed to be unique).

This is probably the most basic of questions but how do I implement the condition 'value.id exists in the SequenceCount table' ?

Something like this:

if try SequenceCount.find(value.id).fetchOne(db) != nil {
  
}

You could also just perform the update and check how many rows were changed, and if none were do an insert:

let didUpdate = try SequenceCount
  .find(value.id)
  .update { $0.count += value.count }
  .returning(\.id)
  .fetchCount(db) == 1
if !didUpdate {
  // insert
}

And there are some advanced tricks you…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@wltrup
Comment options

@mbrandonw
Comment options

Answer selected by wltrup
@wltrup
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants