-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented Drift connection & database (#176)
Closes #170
- Loading branch information
1 parent
0e98715
commit 755e1e5
Showing
4 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,15 @@ | ||
import 'package:drift/drift.dart'; | ||
import 'package:sizzle_starter/src/core/database/connection/open_connection_stub.dart' | ||
if (dart.library.io) 'package:sizzle_starter/src/core/database/connection/open_connection_io.dart' | ||
if (dart.library.html) 'package:sizzle_starter/src/core/database/connection/open_connection_html.dart' | ||
as connection; | ||
|
||
part 'app_database.g.dart'; | ||
|
||
@DriftDatabase() | ||
class AppDatabase extends _$AppDatabase { | ||
AppDatabase({required String name}) : super(connection.openConnection(name)); | ||
|
||
@override | ||
int get schemaVersion => 1; | ||
} |
This file contains 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,6 @@ | ||
import 'package:drift/drift.dart'; | ||
import 'package:drift/web.dart'; | ||
|
||
QueryExecutor openConnection(String name) => WebDatabase( | ||
name, | ||
); |
This file contains 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,15 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:drift/drift.dart'; | ||
import 'package:drift/native.dart'; | ||
import 'package:path/path.dart' as path; | ||
import 'package:path_provider/path_provider.dart'; | ||
|
||
QueryExecutor openConnection(String name) => LazyDatabase( | ||
() async { | ||
final dbFolder = await getApplicationDocumentsDirectory(); | ||
final file = File(path.join(dbFolder.path, '$name.sqlite')); | ||
|
||
return NativeDatabase(file); | ||
}, | ||
); |
This file contains 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,4 @@ | ||
import 'package:drift/drift.dart'; | ||
|
||
QueryExecutor openConnection(String name) => | ||
throw UnsupportedError('Platform is not recognised as supported one'); |