-
-
Notifications
You must be signed in to change notification settings - Fork 722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose DatabaseRegion(table:) initializer #510
Expose DatabaseRegion(table:) initializer #510
Conversation
Hello @charlesmchen-signal. Wow, Signal is pretty involved here these days, it's a pleasure to see you all :-) So you want to make Is it possible that you complete the PR checklist from the pull request template?
|
aef957b
to
263cc69
Compare
Hi @groue - Thanks for your work on GRDB. Pull Request Checklist
Done.
I've elaborated the docs - I'm not sure what you consider sufficient. I'd be happy to go further if you'd be kind enough to offer some guidance. While doing this, I decided to go ahead and elaborate the comments on the other initializers and make them public as well.
Skipped.
Skipped. |
263cc69
to
07e6b26
Compare
Oops, things have turned wild. I guess it's my fault. I'll try to provide better guidance. First of all, no DatabaseRegion initializer was public. This is because DatabaseRegion is tightly coupled with SQLite inner guts, and a few GRDB optimizations which are supposed to remain hidden implementation details. We're dealing with a key GRDB feature here, which is the definition of observed regions. As you have noticed, besides the trivial empty DatabaseRegionObservation(tracking: Player.all())
DatabaseRegionObservation(tracking: Player.filter(key: 1))
DatabaseRegionObservation(tracking: SQLRequest<Player>(sql: "SELECT * FROM player")) I think it is good to define a region through a request, because 1. this makes very clear in application code what results the application is interested in, 2. it grants GRDB opportunities to add optimizations for certain kinds of requests, which means that your application becomes more efficient as new GRDB versions ship, 3. it provides a unified way to define regions, from trivial requests to the most complex ones. Learn once, apply everywhere. Conclusion: I want that requests remain the one true fostered way to define regions. Now, it looks like your request for a public // The request way
struct Player: TableRecord { }
DatabaseRegionObservation(tracking: Player.all())
// This pull request
DatabaseRegionObservation(tracking: DatabaseRegion(table: "player")) Other initializers are, on the other side, really much too much precise and implementation-dependent, and I prefer to keep them private: // The request way only
DatabaseRegionObservation(tracking: Player.select(Column("name")))
DatabaseRegionObservation(tracking: Player.filter(keys: [1, 2, 3])) So :-) If the "request way" still does not convince you, and you still need Please keep only For the documentation guidance, I suggest you have a look at API Design Guidelines . It talks about documentation comments. This could give: /// Creates a region that spans all rows and columns of a database table.
///
/// - parameter table: A table name.
init(table: String) { ... ) |
In all honesty, this wasn't easy to guess for you 😅. I was so happy with the DatabaseRegion type that I bragged about its implementation in the documentation, instead of remaining on the very edge of what's useful with it. I guess this is a classical sin, a common mistake: writing doc is hard, especially when you're the one who wrote the code. Eventually, the documentation for DatabaseRegion will be enhanced. And today, let's just pretend we don't know how it works 😈 |
07e6b26
to
9f41277
Compare
Hi @groue, I've pushed a commit that takes your suggestions. Thanks |
Perfect, @charlesmchen-signal, thank you! I'll push a couple other commits and merge your PR :-) |
Thank you @groue |
We have `Table` now, wich is DatabaseRegionConvertible. This deprecation will revert #510
Hello @charlesmchen-signal, I intend to deprecate For example: -DatabaseRegionObservation(tracking: DatabaseRegion(table: "player"))
+DatabaseRegionObservation(tracking: Table("player")) ( Would this deprecation, and replacement solution, fit your needs at Signal? |
OK, so |
Hi there,
We'd like to use
DatabaseRegion
andDatabaseRegionObservation
to observe changes to db tables. To do so, we need theDatabaseRegion(table:)
initializer to be public.