I have an example project: https://github.com/AppleEducate/moor_shared
Currently uses SQlite on mobile, web and desktop.
I am curious if i am missing something simple. How do i link a path to sqlite on desktop? https://github.com/simolus3/moor/issues/76
Does macos, windows and linux have sqlite on the operating system already or do i need to bundle it?
MacOS definitely has sqlite available as a shared library. The error code returned from sqlite here is 14 (SQLITE_CANTOPEN). Maybe that is because of some permission problems? The same error occurs when opening a database in /tmp/db.sqlite, which I would assume is available. The used library pretty much uses the sqlite example from dart:ffi.
OK cool, i thought macos did too.
It could be of how macos sandboxes the app, but i would think this path would still work.
@AppleEducate I managed to get your code working by using a file that would be stored in 'Library/Containers/$appId/Data'
// put this in lib/data/database/mobile.dart
if (Platform.isMacOS || Platform.isLinux) {
final file = File('db.sqlite');
return Database(VMDatabase(file, logStatements: logStatements));
}
I think it failed to open a database in /tmp/db.sqlite because Mac apps aren't allowed to access the global file system (??). And I think the reason it didn't work with your original code is that you're implicitly using Directory.toString here, which doesn't return a valid path. I don't have enough experience with MacOS development to give a definite answer unfortunately.
ok no worries, thank you! I will update my example. I don't have much experience either with MacOS but we have a client that wants one.
That worked!!
I think it failed to open a database in /tmp/db.sqlite because Mac apps aren't allowed to access the global file system (??).
The macOS App Sandbox, which the example project is configured to use by default, does not allow arbitrary filesystem access.