YapDatabaseExtensions icon indicating copy to clipboard operation
YapDatabaseExtensions copied to clipboard

YapDB.View public API missing the useful bits

Open aranasaurus opened this issue 10 years ago • 6 comments

I may just be missing something and this is supposed to be used from elsewhere or something, but none of the pieces of the YapDB.View api that would let me register it with YapDatabase are marked public, they're all internal.

  • .object on the enum is not public
  • createDatabaseView() is not public
  • registerInDatabase() is not public

aranasaurus avatar Oct 16 '15 21:10 aranasaurus

Going further down the rabbit hole I'm finding YapDatabaseViews don't get any of the love from your work on the Transaction or Connection since YapDatabaseExtensionTransaction and YapDatabaseConnection require slightly different info for an index (Group and Index within the group). So I guess we'd need separate extensions written for these classes.

aranasaurus avatar Oct 16 '15 23:10 aranasaurus

Hi @aranasaurus - sorry just getting back to this.

I can see that YapDB.View etc doesn't have public APIs, but if you put the view into a fetch, then you can register it in the database. i.e.

let fetch: YapDB.Fetch = .View(myView)
let database = YapDB.databaseNamed("MyApp.sqlite") { db in

    // Ensure that nothing inside this block attempts to access `database`
    // as it will cause a deadlock.

    db.registerExtension(YapDatabaseRelationship(), withName: "relationships")

    // Register default extensions
    let views: [YapDB.Fetch] = [
        Reminder.fetch,
        Person.view,
        Person.search
    ]

    views.forEach { $0.registerInDatabase(db) }
}

danthorpe avatar Oct 20 '15 15:10 danthorpe

Thanks @danthorpe. I wrote an extension on YapDatabaseExtensionTransaction that mirrored your generic read functions, as a quick and dirty fix on Friday and moved on for now. Hopefully I'll get back to it today.

aranasaurus avatar Oct 20 '15 16:10 aranasaurus

Okay, thanks @aranasaurus - although my comment was more about the availability of the registerInDatabase API.

I'm going to circle back to address the YapDB wrappers for version 2.3, and I'd like to also add APIs on YapDatabaseExtensionsTransaction etc.

danthorpe avatar Oct 21 '15 13:10 danthorpe

I knew you were referring to the registerInDatabase API... I was just saying the read methods on YapDatabaseExtensionTransaction was the quicker way to get me what I needed at the time. And I'll also put forth that doing that made using an extension very straight forward and felt pretty natural with the rest of the Extensions. The Fetch bit seems nice, but feels like a whole separate thing... maybe just because there's not docs for it and I haven't had time to fully grok it yet.

Anyway, long story short, I like the idea of adding the APIs to YapDatabaseExtensionTransaction :+1:

aranasaurus avatar Oct 21 '15 16:10 aranasaurus

Okay, sounds good, we're on the same page.

danthorpe avatar Oct 21 '15 16:10 danthorpe