0

I'm using GRDB and a custom struct. Fetching rows works perfectly, however the issue comes when trying to update or delete rows. When I try to add the line to save the record, I get a compiler error that the "variablename" has no member 'save'. The same error appears if I try to delete.

The struct is defined like so:

struct ActiveTraffic {
    var id: Int
    ...
}

extension ActiveTraffic: TableMapping, RowConvertible {
    static let databaseTableName = "ActiveTraffic"

    enum Columns {
        static let id = Column("id")
        ...
    }

    init(row: Row) {
        id = row[Columns.id]
        ...
    } 
}

The class using it is like so:

import GRDB
class CustomManager {

...

    try appDBQueue.inTransaction { db in
        var activeTraffic = ActiveTraffic(id: traffic.id, ...)
        activeTraffic.save(db)
        return .commit
    }
}

Looking at all of the documentation, it would appear that all I have to do is call .save on the instance to hit the generic implementation of .save or .delete, however it's not recognizing the additional functionality. Any ideas?

PilotGuy
  • 41
  • 1
  • 6
  • 1
    I'm no expert in this, but my reading suggests you need MutablePersistable instead of TableMapping. From the docs: "/// Types that adopt MutablePersistable can be inserted, updated, and deleted." – Phillip Mills Apr 03 '18 at 18:08
  • Phillip -- You're right. I'm not sure how I missed this. I've been reading the docs for about 4 hours... If you'll post as an answer, I'll give you the points. Thanks!!! – PilotGuy Apr 03 '18 at 18:34

0 Answers0