mirror of https://github.com/AMT-Cheif/drift.git
Fix nullability for drift -> sqlparser mapping
This commit is contained in:
parent
9f48d49cb3
commit
f38d56842e
|
@ -1381,23 +1381,23 @@ class $WeirdTableTable extends Table
|
||||||
|
|
||||||
class MyViewData extends DataClass {
|
class MyViewData extends DataClass {
|
||||||
final String configKey;
|
final String configKey;
|
||||||
final String configValue;
|
final String? configValue;
|
||||||
final SyncType syncState;
|
final SyncType? syncState;
|
||||||
final SyncType syncStateImplicit;
|
final SyncType? syncStateImplicit;
|
||||||
const MyViewData(
|
const MyViewData(
|
||||||
{required this.configKey,
|
{required this.configKey,
|
||||||
required this.configValue,
|
this.configValue,
|
||||||
required this.syncState,
|
this.syncState,
|
||||||
required this.syncStateImplicit});
|
this.syncStateImplicit});
|
||||||
factory MyViewData.fromJson(Map<String, dynamic> json,
|
factory MyViewData.fromJson(Map<String, dynamic> json,
|
||||||
{ValueSerializer? serializer}) {
|
{ValueSerializer? serializer}) {
|
||||||
serializer ??= driftRuntimeOptions.defaultSerializer;
|
serializer ??= driftRuntimeOptions.defaultSerializer;
|
||||||
return MyViewData(
|
return MyViewData(
|
||||||
configKey: serializer.fromJson<String>(json['config_key']),
|
configKey: serializer.fromJson<String>(json['config_key']),
|
||||||
configValue: serializer.fromJson<String>(json['config_value']),
|
configValue: serializer.fromJson<String?>(json['config_value']),
|
||||||
syncState: serializer.fromJson<SyncType>(json['sync_state']),
|
syncState: serializer.fromJson<SyncType?>(json['sync_state']),
|
||||||
syncStateImplicit:
|
syncStateImplicit:
|
||||||
serializer.fromJson<SyncType>(json['sync_state_implicit']),
|
serializer.fromJson<SyncType?>(json['sync_state_implicit']),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
factory MyViewData.fromJsonString(String encodedJson,
|
factory MyViewData.fromJsonString(String encodedJson,
|
||||||
|
@ -1410,22 +1410,24 @@ class MyViewData extends DataClass {
|
||||||
serializer ??= driftRuntimeOptions.defaultSerializer;
|
serializer ??= driftRuntimeOptions.defaultSerializer;
|
||||||
return <String, dynamic>{
|
return <String, dynamic>{
|
||||||
'config_key': serializer.toJson<String>(configKey),
|
'config_key': serializer.toJson<String>(configKey),
|
||||||
'config_value': serializer.toJson<String>(configValue),
|
'config_value': serializer.toJson<String?>(configValue),
|
||||||
'sync_state': serializer.toJson<SyncType>(syncState),
|
'sync_state': serializer.toJson<SyncType?>(syncState),
|
||||||
'sync_state_implicit': serializer.toJson<SyncType>(syncStateImplicit),
|
'sync_state_implicit': serializer.toJson<SyncType?>(syncStateImplicit),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
MyViewData copyWith(
|
MyViewData copyWith(
|
||||||
{String? configKey,
|
{String? configKey,
|
||||||
String? configValue,
|
Value<String?> configValue = const Value.absent(),
|
||||||
SyncType? syncState,
|
Value<SyncType?> syncState = const Value.absent(),
|
||||||
SyncType? syncStateImplicit}) =>
|
Value<SyncType?> syncStateImplicit = const Value.absent()}) =>
|
||||||
MyViewData(
|
MyViewData(
|
||||||
configKey: configKey ?? this.configKey,
|
configKey: configKey ?? this.configKey,
|
||||||
configValue: configValue ?? this.configValue,
|
configValue: configValue.present ? configValue.value : this.configValue,
|
||||||
syncState: syncState ?? this.syncState,
|
syncState: syncState.present ? syncState.value : this.syncState,
|
||||||
syncStateImplicit: syncStateImplicit ?? this.syncStateImplicit,
|
syncStateImplicit: syncStateImplicit.present
|
||||||
|
? syncStateImplicit.value
|
||||||
|
: this.syncStateImplicit,
|
||||||
);
|
);
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
|
@ -1475,13 +1477,13 @@ class MyView extends ViewInfo<MyView, MyViewData> implements HasResultSet {
|
||||||
configKey: attachedDatabase.options.types
|
configKey: attachedDatabase.options.types
|
||||||
.read(DriftSqlType.string, data['${effectivePrefix}config_key'])!,
|
.read(DriftSqlType.string, data['${effectivePrefix}config_key'])!,
|
||||||
configValue: attachedDatabase.options.types
|
configValue: attachedDatabase.options.types
|
||||||
.read(DriftSqlType.string, data['${effectivePrefix}config_value'])!,
|
.read(DriftSqlType.string, data['${effectivePrefix}config_value']),
|
||||||
syncState: MyView.$convertersyncStaten.fromSql(attachedDatabase
|
syncState: MyView.$convertersyncState.fromSql(attachedDatabase
|
||||||
.options.types
|
.options.types
|
||||||
.read(DriftSqlType.int, data['${effectivePrefix}sync_state'])!),
|
.read(DriftSqlType.int, data['${effectivePrefix}sync_state'])),
|
||||||
syncStateImplicit: MyView.$convertersyncStateImplicitn.fromSql(
|
syncStateImplicit: MyView.$convertersyncStateImplicit.fromSql(
|
||||||
attachedDatabase.options.types.read(DriftSqlType.int,
|
attachedDatabase.options.types.read(
|
||||||
data['${effectivePrefix}sync_state_implicit'])!),
|
DriftSqlType.int, data['${effectivePrefix}sync_state_implicit'])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1489,16 +1491,17 @@ class MyView extends ViewInfo<MyView, MyViewData> implements HasResultSet {
|
||||||
'config_key', aliasedName, false,
|
'config_key', aliasedName, false,
|
||||||
type: DriftSqlType.string);
|
type: DriftSqlType.string);
|
||||||
late final GeneratedColumn<String> configValue = GeneratedColumn<String>(
|
late final GeneratedColumn<String> configValue = GeneratedColumn<String>(
|
||||||
'config_value', aliasedName, false,
|
'config_value', aliasedName, true,
|
||||||
type: DriftSqlType.string);
|
type: DriftSqlType.string);
|
||||||
late final GeneratedColumnWithTypeConverter<SyncType, int> syncState =
|
late final GeneratedColumnWithTypeConverter<SyncType?, int> syncState =
|
||||||
GeneratedColumn<int>('sync_state', aliasedName, false,
|
GeneratedColumn<int>('sync_state', aliasedName, true,
|
||||||
type: DriftSqlType.int)
|
type: DriftSqlType.int)
|
||||||
.withConverter<SyncType>(MyView.$convertersyncStaten);
|
.withConverter<SyncType?>(MyView.$convertersyncState);
|
||||||
late final GeneratedColumnWithTypeConverter<SyncType, int> syncStateImplicit =
|
late final GeneratedColumnWithTypeConverter<SyncType?, int>
|
||||||
GeneratedColumn<int>('sync_state_implicit', aliasedName, false,
|
syncStateImplicit = GeneratedColumn<int>(
|
||||||
|
'sync_state_implicit', aliasedName, true,
|
||||||
type: DriftSqlType.int)
|
type: DriftSqlType.int)
|
||||||
.withConverter<SyncType>(MyView.$convertersyncStateImplicitn);
|
.withConverter<SyncType?>(MyView.$convertersyncStateImplicit);
|
||||||
@override
|
@override
|
||||||
MyView createAlias(String alias) {
|
MyView createAlias(String alias) {
|
||||||
return MyView(attachedDatabase, alias);
|
return MyView(attachedDatabase, alias);
|
||||||
|
@ -1527,7 +1530,7 @@ abstract class _$CustomTablesDb extends GeneratedDatabase {
|
||||||
'CREATE TRIGGER my_trigger AFTER INSERT ON config BEGIN INSERT INTO with_defaults VALUES (new.config_key, LENGTH(new.config_value));END',
|
'CREATE TRIGGER my_trigger AFTER INSERT ON config BEGIN INSERT INTO with_defaults VALUES (new.config_key, LENGTH(new.config_value));END',
|
||||||
'my_trigger');
|
'my_trigger');
|
||||||
late final MyView myView = MyView(this);
|
late final MyView myView = MyView(this);
|
||||||
Future<int> writeConfig({required String key, required String value}) {
|
Future<int> writeConfig({required String key, String? value}) {
|
||||||
return customInsert(
|
return customInsert(
|
||||||
'REPLACE INTO config (config_key, config_value) VALUES (?1, ?2)',
|
'REPLACE INTO config (config_key, config_value) VALUES (?1, ?2)',
|
||||||
variables: [Variable<String>(key), Variable<String>(value)],
|
variables: [Variable<String>(key), Variable<String>(value)],
|
||||||
|
@ -1588,7 +1591,7 @@ abstract class _$CustomTablesDb extends GeneratedDatabase {
|
||||||
}).asyncMap(config.mapFromRow);
|
}).asyncMap(config.mapFromRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
Selectable<String> typeConverterVar(SyncType var1, List<SyncType> var2,
|
Selectable<String> typeConverterVar(SyncType? var1, List<SyncType?> var2,
|
||||||
{TypeConverterVar$pred? pred}) {
|
{TypeConverterVar$pred? pred}) {
|
||||||
var $arrayStartIndex = 2;
|
var $arrayStartIndex = 2;
|
||||||
final generatedpred = $write(
|
final generatedpred = $write(
|
||||||
|
@ -1600,10 +1603,12 @@ abstract class _$CustomTablesDb extends GeneratedDatabase {
|
||||||
return customSelect(
|
return customSelect(
|
||||||
'SELECT config_key FROM config WHERE ${generatedpred.sql} AND(sync_state = ?1 OR sync_state_implicit IN ($expandedvar2))',
|
'SELECT config_key FROM config WHERE ${generatedpred.sql} AND(sync_state = ?1 OR sync_state_implicit IN ($expandedvar2))',
|
||||||
variables: [
|
variables: [
|
||||||
Variable<int>($ConfigTable.$convertersyncStaten.toSql(var1)),
|
Variable<int>(NullAwareTypeConverter.wrapToSql(
|
||||||
|
$ConfigTable.$convertersyncStaten, var1)),
|
||||||
...generatedpred.introducedVariables,
|
...generatedpred.introducedVariables,
|
||||||
for (var $ in var2)
|
for (var $ in var2)
|
||||||
Variable<int>($ConfigTable.$convertersyncStateImplicitn.toSql($))
|
Variable<int>(NullAwareTypeConverter.wrapToSql(
|
||||||
|
$ConfigTable.$convertersyncStateImplicitn, $))
|
||||||
],
|
],
|
||||||
readsFrom: {
|
readsFrom: {
|
||||||
config,
|
config,
|
||||||
|
@ -1659,8 +1664,8 @@ abstract class _$CustomTablesDb extends GeneratedDatabase {
|
||||||
}).asyncMap((QueryRow row) async {
|
}).asyncMap((QueryRow row) async {
|
||||||
return MultipleResult(
|
return MultipleResult(
|
||||||
row: row,
|
row: row,
|
||||||
a: row.read<String>('a'),
|
a: row.readNullable<String>('a'),
|
||||||
b: row.read<int>('b'),
|
b: row.readNullable<int>('b'),
|
||||||
c: await withConstraints.mapFromRowOrNull(row, tablePrefix: 'nested_0'),
|
c: await withConstraints.mapFromRowOrNull(row, tablePrefix: 'nested_0'),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -1695,11 +1700,13 @@ abstract class _$CustomTablesDb extends GeneratedDatabase {
|
||||||
row: row,
|
row: row,
|
||||||
rowid: row.read<int>('rowid'),
|
rowid: row.read<int>('rowid'),
|
||||||
configKey: row.read<String>('config_key'),
|
configKey: row.read<String>('config_key'),
|
||||||
configValue: row.read<String>('config_value'),
|
configValue: row.readNullable<String>('config_value'),
|
||||||
syncState: $ConfigTable.$convertersyncStaten
|
syncState: NullAwareTypeConverter.wrapFromSql(
|
||||||
.fromSql(row.read<int>('sync_state')),
|
$ConfigTable.$convertersyncStaten,
|
||||||
syncStateImplicit: $ConfigTable.$convertersyncStateImplicitn
|
row.readNullable<int>('sync_state')),
|
||||||
.fromSql(row.read<int>('sync_state_implicit')),
|
syncStateImplicit: NullAwareTypeConverter.wrapFromSql(
|
||||||
|
$ConfigTable.$convertersyncStateImplicitn,
|
||||||
|
row.readNullable<int>('sync_state_implicit')),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1711,11 +1718,12 @@ abstract class _$CustomTablesDb extends GeneratedDatabase {
|
||||||
return ReadViewResult(
|
return ReadViewResult(
|
||||||
row: row,
|
row: row,
|
||||||
configKey: row.read<String>('config_key'),
|
configKey: row.read<String>('config_key'),
|
||||||
configValue: row.read<String>('config_value'),
|
configValue: row.readNullable<String>('config_value'),
|
||||||
syncState:
|
syncState: NullAwareTypeConverter.wrapFromSql(
|
||||||
MyView.$convertersyncStaten.fromSql(row.read<int>('sync_state')),
|
MyView.$convertersyncStaten, row.readNullable<int>('sync_state')),
|
||||||
syncStateImplicit: MyView.$convertersyncStateImplicitn
|
syncStateImplicit: NullAwareTypeConverter.wrapFromSql(
|
||||||
.fromSql(row.read<int>('sync_state_implicit')),
|
MyView.$convertersyncStateImplicitn,
|
||||||
|
row.readNullable<int>('sync_state_implicit')),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1747,7 +1755,7 @@ abstract class _$CustomTablesDb extends GeneratedDatabase {
|
||||||
.then((rows) => Future.wait(rows.map(config.mapFromRow)));
|
.then((rows) => Future.wait(rows.map(config.mapFromRow)));
|
||||||
}
|
}
|
||||||
|
|
||||||
Selectable<NestedResult> nested(String var1) {
|
Selectable<NestedResult> nested(String? var1) {
|
||||||
return customSelect(
|
return customSelect(
|
||||||
'SELECT"defaults"."a" AS "nested_0.a", "defaults"."b" AS "nested_0.b", defaults.b AS "\$n_0" FROM with_defaults AS defaults WHERE a = ?1',
|
'SELECT"defaults"."a" AS "nested_0.a", "defaults"."b" AS "nested_0.b", defaults.b AS "\$n_0" FROM with_defaults AS defaults WHERE a = ?1',
|
||||||
variables: [
|
variables: [
|
||||||
|
@ -1866,13 +1874,13 @@ class AnotherResult extends CustomResultSet {
|
||||||
}
|
}
|
||||||
|
|
||||||
class MultipleResult extends CustomResultSet {
|
class MultipleResult extends CustomResultSet {
|
||||||
final String a;
|
final String? a;
|
||||||
final int b;
|
final int? b;
|
||||||
final WithConstraint? c;
|
final WithConstraint? c;
|
||||||
MultipleResult({
|
MultipleResult({
|
||||||
required QueryRow row,
|
required QueryRow row,
|
||||||
required this.a,
|
this.a,
|
||||||
required this.b,
|
this.b,
|
||||||
this.c,
|
this.c,
|
||||||
}) : super(row);
|
}) : super(row);
|
||||||
@override
|
@override
|
||||||
|
@ -1901,16 +1909,16 @@ typedef Multiple$predicate = Expression<bool> Function(
|
||||||
class ReadRowIdResult extends CustomResultSet {
|
class ReadRowIdResult extends CustomResultSet {
|
||||||
final int rowid;
|
final int rowid;
|
||||||
final String configKey;
|
final String configKey;
|
||||||
final String configValue;
|
final String? configValue;
|
||||||
final SyncType syncState;
|
final SyncType? syncState;
|
||||||
final SyncType syncStateImplicit;
|
final SyncType? syncStateImplicit;
|
||||||
ReadRowIdResult({
|
ReadRowIdResult({
|
||||||
required QueryRow row,
|
required QueryRow row,
|
||||||
required this.rowid,
|
required this.rowid,
|
||||||
required this.configKey,
|
required this.configKey,
|
||||||
required this.configValue,
|
this.configValue,
|
||||||
required this.syncState,
|
this.syncState,
|
||||||
required this.syncStateImplicit,
|
this.syncStateImplicit,
|
||||||
}) : super(row);
|
}) : super(row);
|
||||||
@override
|
@override
|
||||||
int get hashCode =>
|
int get hashCode =>
|
||||||
|
@ -1941,15 +1949,15 @@ typedef ReadRowId$expr = Expression<int> Function($ConfigTable config);
|
||||||
|
|
||||||
class ReadViewResult extends CustomResultSet {
|
class ReadViewResult extends CustomResultSet {
|
||||||
final String configKey;
|
final String configKey;
|
||||||
final String configValue;
|
final String? configValue;
|
||||||
final SyncType syncState;
|
final SyncType? syncState;
|
||||||
final SyncType syncStateImplicit;
|
final SyncType? syncStateImplicit;
|
||||||
ReadViewResult({
|
ReadViewResult({
|
||||||
required QueryRow row,
|
required QueryRow row,
|
||||||
required this.configKey,
|
required this.configKey,
|
||||||
required this.configValue,
|
this.configValue,
|
||||||
required this.syncState,
|
this.syncState,
|
||||||
required this.syncStateImplicit,
|
this.syncStateImplicit,
|
||||||
}) : super(row);
|
}) : super(row);
|
||||||
@override
|
@override
|
||||||
int get hashCode =>
|
int get hashCode =>
|
||||||
|
|
|
@ -1612,10 +1612,10 @@ abstract class _$TodoDb extends GeneratedDatabase {
|
||||||
return AllTodosWithCategoryResult(
|
return AllTodosWithCategoryResult(
|
||||||
row: row,
|
row: row,
|
||||||
id: row.read<int>('id'),
|
id: row.read<int>('id'),
|
||||||
title: row.read<String>('title'),
|
title: row.readNullable<String>('title'),
|
||||||
content: row.read<String>('content'),
|
content: row.read<String>('content'),
|
||||||
targetDate: row.read<DateTime>('target_date'),
|
targetDate: row.readNullable<DateTime>('target_date'),
|
||||||
category: row.read<int>('category'),
|
category: row.readNullable<int>('category'),
|
||||||
catId: row.read<int>('catId'),
|
catId: row.read<int>('catId'),
|
||||||
catDesc: row.read<String>('catDesc'),
|
catDesc: row.read<String>('catDesc'),
|
||||||
);
|
);
|
||||||
|
@ -1631,7 +1631,7 @@ abstract class _$TodoDb extends GeneratedDatabase {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Selectable<TodoEntry> withIn(String var1, String var2, List<int> var3) {
|
Selectable<TodoEntry> withIn(String? var1, String? var2, List<int> var3) {
|
||||||
var $arrayStartIndex = 3;
|
var $arrayStartIndex = 3;
|
||||||
final expandedvar3 = $expandVar($arrayStartIndex, var3.length);
|
final expandedvar3 = $expandVar($arrayStartIndex, var3.length);
|
||||||
$arrayStartIndex += var3.length;
|
$arrayStartIndex += var3.length;
|
||||||
|
@ -1686,19 +1686,19 @@ abstract class _$TodoDb extends GeneratedDatabase {
|
||||||
|
|
||||||
class AllTodosWithCategoryResult extends CustomResultSet {
|
class AllTodosWithCategoryResult extends CustomResultSet {
|
||||||
final int id;
|
final int id;
|
||||||
final String title;
|
final String? title;
|
||||||
final String content;
|
final String content;
|
||||||
final DateTime targetDate;
|
final DateTime? targetDate;
|
||||||
final int category;
|
final int? category;
|
||||||
final int catId;
|
final int catId;
|
||||||
final String catDesc;
|
final String catDesc;
|
||||||
AllTodosWithCategoryResult({
|
AllTodosWithCategoryResult({
|
||||||
required QueryRow row,
|
required QueryRow row,
|
||||||
required this.id,
|
required this.id,
|
||||||
required this.title,
|
this.title,
|
||||||
required this.content,
|
required this.content,
|
||||||
required this.targetDate,
|
this.targetDate,
|
||||||
required this.category,
|
this.category,
|
||||||
required this.catId,
|
required this.catId,
|
||||||
required this.catDesc,
|
required this.catDesc,
|
||||||
}) : super(row);
|
}) : super(row);
|
||||||
|
|
|
@ -58,7 +58,8 @@ class TypeMapping {
|
||||||
return _driftTypeToParser(column.sqlType,
|
return _driftTypeToParser(column.sqlType,
|
||||||
overrideHint: column.typeConverter != null
|
overrideHint: column.typeConverter != null
|
||||||
? TypeConverterHint(column.typeConverter!)
|
? TypeConverterHint(column.typeConverter!)
|
||||||
: null);
|
: null)
|
||||||
|
.withNullable(column.nullable);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResolvedType _driftTypeToParser(DriftSqlType type, {TypeHint? overrideHint}) {
|
ResolvedType _driftTypeToParser(DriftSqlType type, {TypeHint? overrideHint}) {
|
||||||
|
|
Loading…
Reference in New Issue