-
Notifications
You must be signed in to change notification settings - Fork 26
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
Support directory for windows #378
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hortigado I know you mentioned in #377 this is your first PR, and I want to commend you on the bravery to open one. Open source is an intimidating space because it's so exposed - your work is on display for everyone to critique. I really appreciate that you've opened so many issues and taken the step forward to open this PR. Thank you.
However, I apologize for not examining your work more closely yesterday. I should've caught some of my concerns earlier.
I think the core of what you have here is useful beyond sqlite_provider
(for example, the cache manager). A helper function that wraps your logic would be useful in both places.
Future<String> _dbName(String fileName) async {
if (!Platform.isWindows) return fileName;
final directory = await getApplicationSupportDirectory();
return '${directory.path}/$fileName';
}
A function like this wouldn't live inside the Brick packages because of the Flutter dependency (as convenient as that would be, it breaks the portability). But it should be listed in the comments of the sqliteProvider
field of OfflineFirstRepository. This function should also be listed in the documentation, perhaps under a Windows Support
header for easy search discovery with a quick example showing how you'd include this function in your repository (maybe as a static method) and where you'd invoke it (on creation of the repository, as the db name for sqliteProvider
and offlineQueueManager
).
Again, thank you for opening this PR. This is helpful because I've never run Flutter on Windows and this covers that blind spot. I hope these comments are useful to you and won't discourage you from revising this PR to be documentation focused or from opening a new PR in the future.
@@ -136,8 +138,17 @@ class SqliteProvider implements Provider<SqliteModel> { | |||
|
|||
/// Access the latest instantiation of the database [safely](https://github.com/tekartik/sqflite/blob/master/sqflite/doc/opening_db.md#prevent-database-locked-issue). | |||
@protected | |||
Future<Database> getDb() { | |||
_openDb ??= databaseFactory.openDatabase(dbName); | |||
Future<Database> getDb() async { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is a little misleading to traditional async
usage. It requires that the return value is an unfulfilled Future. This protects openDatabase
from being called more than once. More on this soon, but I wanted to give you a quick thesis: this function shouldn't have any await
s.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's true that it doesn't cover the cachemanager. The truth is, I think that in that case the best thing would be to separate it into an auxiliary function. I was also not aware of the problem with sqlite with async.
I didn't analyze the code much because it was a quick fix that I had placed for testing.
What should I do now to make the changes or would you do them yourself? I don't really understand how this world of PR works haha.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do them myself, although you wouldn't get the credit for the code. Is that alright with you if I make a PR with applying these suggestions to the documentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, better than you, I still have to learn a little more to make a more elaborate PR. Greetings
dbPath = await getDatabasesPath(); | ||
} | ||
final String path = join(dbPath, dbName); | ||
_openDb ??= openDatabase(path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getDb
is invoked multiple times throughout sqliteProvider
. It needs to execute quickly, if at all, which is why there's memoization with ??=
.
@@ -16,7 +16,8 @@ dependencies: | |||
meta: ">=1.3.0 <2.0.0" | |||
sqflite_common: ">=2.0.0 <3.0.0" | |||
synchronized: ^3.0.0 | |||
|
|||
path_provider: ^2.1.3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
brick_sqlite
doesn't have a flutter
dependency, which makes it very nimble and suitable to all sorts of environments (especially FFI). This was a big part of Brick v2. path_provider
would reintroduce a Flutter dependency.
@hortigado Closing this PR in favor of #387 |
No description provided.