dariopellegrini / StorageDone-iOS

Swift library to make easy using local document-oriented database in iOS apps.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

insertOrUpdate method is not updating DB

TOrnelas opened this issue · comments

I have implemented my User class with the primaryKey() function:

struct User: Codable {
    var username: String
    var authToken: String
    
    func primaryKey() -> String {
        return "username"
    }
}

However, when I use the insertOrUpdate method, the user it's inserted again on the DB leaving me with duplicated user entries (with the same username)

Hello @TOrnelas.
You probably forgot to implement PrimaryKey protocol on that struct.

struct User: Codable, PrimaryKey {
    var username: String
    var authToken: String
    
    func primaryKey() -> String {
        return "username"
    }
}

You can find a reference here https://github.com/dariopellegrini/StorageDone-iOS#primary-key.

Let me know if your problem is solved.

That was it! Thank you very much. Closing the issue