Fix dialect properties

This commit is contained in:
westito 2022-05-12 20:58:05 +02:00
parent 763c09c024
commit f379ca0b25
3 changed files with 25 additions and 12 deletions

View File

@ -292,7 +292,7 @@ class DelegatedDatabase extends _BaseExecutor {
SqlDialect get dialect => SqlDialect.sqlite;
@override
bool get supportsBigInt => false;
bool get supportsBigInt => true;
final Lock _openingLock = Lock();

View File

@ -24,7 +24,10 @@ class GenerationContext {
final SqlTypeSystem typeSystem;
/// The [SqlDialect] that should be respected when generating the query.
final SqlDialect dialect;
SqlDialect get dialect => executor?.executor.dialect ?? SqlDialect.sqlite;
/// Whether executor supports BigInt type
bool get supportsBigInt => executor?.executor.supportsBigInt ?? true;
/// The actual [DatabaseConnectionUser] that's going to execute the generated
/// query.
@ -36,9 +39,6 @@ class GenerationContext {
/// This is almost always the case, but not in a `CREATE VIEW` statement.
final bool supportsVariables;
/// Whether executor supports BigInt type
bool get supportsBigInt => executor?.executor.supportsBigInt ?? false;
final List<dynamic> _boundVariables = [];
/// The values of [introducedVariables] that will be sent to the underlying
@ -61,14 +61,12 @@ class GenerationContext {
/// Constructs a [GenerationContext] by copying the relevant fields from the
/// database.
GenerationContext.fromDb(this.executor, {this.supportsVariables = true})
: typeSystem = executor?.typeSystem ?? SqlTypeSystem.defaultInstance,
// ignore: invalid_null_aware_operator, (doesn't seem to actually work)
dialect = executor?.executor?.dialect ?? SqlDialect.sqlite;
: typeSystem = executor?.typeSystem ?? SqlTypeSystem.defaultInstance;
/// Constructs a custom [GenerationContext] by setting the fields manually.
/// See [GenerationContext.fromDb] for a more convenient factory.
GenerationContext(this.typeSystem, this.executor,
{this.dialect = SqlDialect.sqlite, this.supportsVariables = true});
{this.supportsVariables = true});
/// Introduces a variable that will be sent to the database engine. Whenever
/// this method is called, a question mark should be added to the [buffer] so

View File

@ -9,21 +9,36 @@ typedef DatabaseOpener = FutureOr<QueryExecutor> Function();
/// A special database executor that delegates work to another [QueryExecutor].
/// The other executor is lazily opened by a [DatabaseOpener].
class LazyDatabase extends QueryExecutor {
late QueryExecutor _delegate;
/// Underlying executor
late final QueryExecutor _delegate;
bool _delegateAvailable = false;
final SqlDialect _dialect;
Completer<void>? _openDelegate;
@override
bool get supportsBigInt => _delegate.supportsBigInt;
@override
SqlDialect get dialect {
// Drift reads dialect before database opened, so we must know in advance
if (_delegateAvailable && _dialect != _delegate.dialect) {
throw Exception('LazyDatabase created with $_dialect, but underlying '
'database is ${_delegate.dialect}.');
}
return _dialect;
}
/// The function that will open the database when this [LazyDatabase] gets
/// opened for the first time.
final DatabaseOpener opener;
/// Declares a [LazyDatabase] that will run [opener] when the database is
/// first requested to be opened.
LazyDatabase(this.opener);
/// first requested to be opened. You must specify the same [dialect] as the
/// underlying database has
LazyDatabase(this.opener, {SqlDialect dialect = SqlDialect.sqlite})
: _dialect = dialect;
Future<void> _awaitOpened() {
if (_delegateAvailable) {