-
Notifications
You must be signed in to change notification settings - Fork 96
Fix web support docs, add example/multiplatform
#189
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
966daf5
Fix web support docs, add `example/multiplatform`
denis-ryzhkov 1d43674
Add comment and fix in `README` re `sqlite3.wasm`
denis-ryzhkov 658183c
CI needs `path_provider` to analyze `example/multiplatform`
denis-ryzhkov 58338bc
Skip CI `analyze` of example which requires `path_provider` which req…
denis-ryzhkov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# https://dart.dev/guides/language/analysis-options | ||
include: package:lints/recommended.yaml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import 'package:sqlite3/common.dart' show CommonDatabase; | ||
import 'sqlite3/sqlite3.dart' show openSqliteDb; | ||
|
||
late CommonDatabase sqliteDb; | ||
|
||
Future<void> openDb() async { | ||
sqliteDb = await openSqliteDb(); | ||
|
||
final dbVersion = | ||
sqliteDb.select('PRAGMA user_version').first['user_version']; | ||
|
||
print('DB version: $dbVersion'); | ||
|
||
if (dbVersion == 0) { | ||
sqliteDb.execute(''' | ||
BEGIN; | ||
-- TODO | ||
PRAGMA user_version = 1; | ||
COMMIT; | ||
'''); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import 'package:path/path.dart' as path; | ||
import 'package:path_provider/path_provider.dart' | ||
show getApplicationDocumentsDirectory; | ||
import 'package:sqlite3/common.dart' show CommonDatabase; | ||
import 'package:sqlite3/sqlite3.dart' show sqlite3; | ||
|
||
Future<CommonDatabase> openSqliteDb() async { | ||
final docsDir = await getApplicationDocumentsDirectory(); | ||
final filename = path.join(docsDir.path, 'my_app.db'); | ||
return sqlite3.open(filename); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export 'unsupported.dart' | ||
if (dart.library.js) 'web.dart' | ||
if (dart.library.ffi) 'native.dart' show openSqliteDb; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import 'package:sqlite3/common.dart' show CommonDatabase; | ||
|
||
Future<CommonDatabase> openSqliteDb() async { | ||
throw UnsupportedError('Sqlite3 is unsupported on this platform.'); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import 'package:sqlite3/common.dart' show CommonDatabase; | ||
import 'package:sqlite3/wasm.dart' show IndexedDbFileSystem, WasmSqlite3; | ||
|
||
Future<CommonDatabase> openSqliteDb() async { | ||
const name = 'my_app'; | ||
// Please download `sqlite3.wasm` from https://github.com/simolus3/sqlite3.dart/releases | ||
// into the `web/` dir of your Flutter app. See `README.md` for details. | ||
final sqlite = await WasmSqlite3.loadFromUrl(Uri.parse('sqlite3.wasm')); | ||
final fileSystem = await IndexedDbFileSystem.open(dbName: name); | ||
sqlite.registerVirtualFileSystem(fileSystem, makeDefault: true); | ||
return sqlite.open(name); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import 'db/db.dart' show openDb; | ||
|
||
Future<void> main() async { | ||
// WidgetsFlutterBinding.ensureInitialized(); | ||
await openDb(); | ||
// runApp(const App()); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: sqlite3_multiplatform_example | ||
description: Uses common interface to `sqlite3` on web and native platforms. | ||
version: 0.1.0 | ||
publish_to: 'none' | ||
|
||
environment: | ||
sdk: ">=2.12.0 <4.0.0" | ||
|
||
dependencies: | ||
path: ^1.8.3 | ||
# path_provider: ^2.1.1 | ||
sqlite3: ^2.1.0 | ||
# sqlite3_flutter_libs: ^0.5.17 | ||
|
||
dev_dependencies: | ||
lints: ^3.0.0 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.