Skip to content

Commit 7b1d3f7

Browse files
committed
Revert to using CommonDatabase type
1 parent 4852ace commit 7b1d3f7

File tree

6 files changed

+22
-20
lines changed

6 files changed

+22
-20
lines changed

example/custom_functions_example.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import 'dart:io';
33
import 'dart:isolate';
44

55
import 'package:sqlite3/common.dart';
6-
import 'package:sqlite_async/sqlite3.dart' as sqlite;
76
import 'package:sqlite_async/sqlite_async.dart';
87

98
/// Since the functions need to be created on every SQLite connection,
@@ -12,7 +11,7 @@ class TestOpenFactory extends DefaultSqliteOpenFactory {
1211
TestOpenFactory({required super.path, super.sqliteOptions});
1312

1413
@override
15-
FutureOr<sqlite.Database> open(SqliteOpenOptions options) async {
14+
FutureOr<CommonDatabase> open(SqliteOpenOptions options) async {
1615
final db = await super.open(options);
1716

1817
db.createFunction(

example/linux_cli_example.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'dart:async';
22
import 'dart:ffi';
33

4-
import 'package:sqlite_async/sqlite3.dart' as sqlite;
4+
import 'package:sqlite_async/sqlite3_common.dart';
55
import 'package:sqlite_async/sqlite_async.dart';
66
import 'package:sqlite3/open.dart' as sqlite_open;
77

@@ -17,7 +17,7 @@ class TestOpenFactory extends DefaultSqliteOpenFactory {
1717
this.sqlitePath = defaultSqlitePath});
1818

1919
@override
20-
FutureOr<sqlite.Database> open(SqliteOpenOptions options) async {
20+
FutureOr<CommonDatabase> open(SqliteOpenOptions options) async {
2121
// For details, see:
2222
// https://pub.dev/packages/sqlite3#manually-providing-sqlite3-libraries
2323
sqlite_open.open.overrideFor(sqlite_open.OperatingSystem.linux, () {

lib/src/common/abstract_open_factory.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'dart:async';
22
import 'package:meta/meta.dart';
33

4-
import 'package:sqlite_async/sqlite3.dart' as sqlite;
4+
import 'package:sqlite_async/sqlite3_common.dart' as sqlite;
55
import 'package:sqlite_async/src/common/mutex.dart';
66
import 'package:sqlite_async/src/sqlite_connection.dart';
77
import 'package:sqlite_async/src/sqlite_options.dart';
@@ -11,11 +11,11 @@ import 'package:sqlite_async/src/update_notification.dart';
1111
///
1212
/// Since connections are opened in dedicated background isolates, this class
1313
/// must be safe to pass to different isolates.
14-
abstract class SqliteOpenFactory {
14+
abstract class SqliteOpenFactory<Database extends sqlite.CommonDatabase> {
1515
String get path;
1616

1717
/// Opens a direct connection to the SQLite database
18-
FutureOr<sqlite.Database> open(SqliteOpenOptions options);
18+
FutureOr<Database> open(SqliteOpenOptions options);
1919

2020
/// Opens an asynchronous [SqliteConnection]
2121
FutureOr<SqliteConnection> openConnection(SqliteOpenOptions options);
@@ -61,7 +61,9 @@ class SqliteOpenOptions {
6161
/// to configure the connection.
6262
///
6363
/// Override the [open] method to customize the process.
64-
abstract class AbstractDefaultSqliteOpenFactory implements SqliteOpenFactory {
64+
abstract class AbstractDefaultSqliteOpenFactory<
65+
Database extends sqlite.CommonDatabase>
66+
implements SqliteOpenFactory<Database> {
6567
@override
6668
final String path;
6769
final SqliteOptions sqliteOptions;
@@ -75,13 +77,13 @@ abstract class AbstractDefaultSqliteOpenFactory implements SqliteOpenFactory {
7577
@protected
7678

7779
/// Opens a direct connection to a SQLite database connection
78-
FutureOr<sqlite.Database> openDB(SqliteOpenOptions options);
80+
FutureOr<Database> openDB(SqliteOpenOptions options);
7981

8082
@override
8183

8284
/// Opens a direct connection to a SQLite database connection
8385
/// and executes setup pragma statements to initialize the DB
84-
FutureOr<sqlite.Database> open(SqliteOpenOptions options) async {
86+
FutureOr<Database> open(SqliteOpenOptions options) async {
8587
var db = await openDB(options);
8688

8789
// Pragma statements don't have the same BUSY_TIMEOUT behavior as normal statements.

lib/src/common/isolate_connection_factory.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import 'dart:async';
2-
import 'package:sqlite3/sqlite3.dart' as sqlite;
2+
import 'package:sqlite_async/sqlite3.dart';
3+
import 'package:sqlite_async/sqlite3_common.dart' as sqlite;
34
import 'package:sqlite_async/src/common/mutex.dart';
45
import 'package:sqlite_async/src/common/abstract_open_factory.dart';
56
import 'package:sqlite_async/src/impl/isolate_connection_factory_impl.dart';
67
import 'package:sqlite_async/src/sqlite_connection.dart';
78
import 'port_channel.dart';
89

9-
mixin IsolateOpenFactoryMixin {
10-
AbstractDefaultSqliteOpenFactory get openFactory;
10+
mixin IsolateOpenFactoryMixin<Database extends sqlite.CommonDatabase> {
11+
AbstractDefaultSqliteOpenFactory<Database> get openFactory;
1112

1213
/// Opens a synchronous sqlite.Database directly in the current isolate.
1314
///
@@ -16,14 +17,15 @@ mixin IsolateOpenFactoryMixin {
1617
/// with SQLITE_BUSY if another isolate is using the database at the same time.
1718
/// 2. Other connections are not notified of any updates to tables made within
1819
/// this connection.
19-
FutureOr<sqlite.Database> openRawDatabase({bool readOnly = false}) async {
20+
FutureOr<Database> openRawDatabase({bool readOnly = false}) async {
2021
return openFactory
2122
.open(SqliteOpenOptions(primaryConnection: false, readOnly: readOnly));
2223
}
2324
}
2425

2526
/// A connection factory that can be passed to different isolates.
26-
abstract class IsolateConnectionFactory with IsolateOpenFactoryMixin {
27+
abstract class IsolateConnectionFactory<Database extends sqlite.CommonDatabase>
28+
with IsolateOpenFactoryMixin<Database> {
2729
Mutex get mutex;
2830

2931
SerializedPortClient get upstreamPort;
@@ -35,7 +37,7 @@ abstract class IsolateConnectionFactory with IsolateOpenFactoryMixin {
3537
return IsolateConnectionFactoryImpl(
3638
openFactory: openFactory,
3739
mutex: mutex,
38-
upstreamPort: upstreamPort) as IsolateConnectionFactory;
40+
upstreamPort: upstreamPort) as IsolateConnectionFactory<Database>;
3941
}
4042

4143
/// Open a new SqliteConnection.

lib/src/impl/stub_sqlite_open_factory.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'dart:async';
22

3-
import 'package:sqlite3/sqlite3.dart' as sqlite;
3+
import 'package:sqlite3/common.dart';
44
import 'package:sqlite_async/src/common/abstract_open_factory.dart';
55
import 'package:sqlite_async/src/sqlite_connection.dart';
66
import 'package:sqlite_async/src/sqlite_options.dart';
@@ -11,7 +11,7 @@ class DefaultSqliteOpenFactory extends AbstractDefaultSqliteOpenFactory {
1111
super.sqliteOptions = const SqliteOptions.defaults()});
1212

1313
@override
14-
sqlite.Database openDB(SqliteOpenOptions options) {
14+
CommonDatabase openDB(SqliteOpenOptions options) {
1515
throw UnimplementedError();
1616
}
1717

test/utils/native_test_utils.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import 'package:glob/list_local_fs.dart';
88
import 'package:sqlite_async/sqlite3_common.dart';
99
import 'package:sqlite_async/sqlite_async.dart';
1010
import 'package:sqlite3/open.dart' as sqlite_open;
11-
import 'package:sqlite3/sqlite3.dart' as sqlite;
1211

1312
import 'abstract_test_utils.dart';
1413

@@ -22,7 +21,7 @@ class TestSqliteOpenFactory extends TestDefaultSqliteOpenFactory {
2221
initStatements});
2322

2423
@override
25-
FutureOr<sqlite.Database> open(SqliteOpenOptions options) async {
24+
FutureOr<CommonDatabase> open(SqliteOpenOptions options) async {
2625
sqlite_open.open.overrideFor(sqlite_open.OperatingSystem.linux, () {
2726
return DynamicLibrary.open(sqlitePath);
2827
});

0 commit comments

Comments
 (0)