mirror of https://github.com/AMT-Cheif/drift.git
Revert using mapFromRow() for matched tables in queries
This commit is contained in:
parent
c9071f2f7d
commit
2c57a80771
|
@ -300,10 +300,11 @@ mixin QueryEngine on DatabaseConnectionUser {
|
|||
|
||||
/// Will be used by generated code to resolve inline Dart components in sql.
|
||||
@protected
|
||||
GenerationContext $write(Component component) {
|
||||
// for good measure, act like there are multiple tables. This will make
|
||||
// column references be explicit about their table name.
|
||||
final context = GenerationContext.fromDb(this)..hasMultipleTables = true;
|
||||
GenerationContext $write(Component component, {bool hasMultipleTables}) {
|
||||
final context = GenerationContext.fromDb(this);
|
||||
if (hasMultipleTables != null) {
|
||||
context.hasMultipleTables = hasMultipleTables;
|
||||
}
|
||||
|
||||
// we don't want ORDER BY clauses to write the ORDER BY tokens because those
|
||||
// are already declared in sql
|
||||
|
|
|
@ -1113,7 +1113,10 @@ abstract class _$CustomTablesDb extends GeneratedDatabase {
|
|||
Email _email;
|
||||
Email get email => _email ??= Email(this);
|
||||
Config _rowToConfig(QueryRow row) {
|
||||
return config.mapFromRow(row);
|
||||
return Config(
|
||||
configKey: row.readString('config_key'),
|
||||
configValue: row.readString('config_value'),
|
||||
);
|
||||
}
|
||||
|
||||
Selectable<Config> readConfig(String var1) {
|
||||
|
@ -1155,7 +1158,11 @@ abstract class _$CustomTablesDb extends GeneratedDatabase {
|
|||
}
|
||||
|
||||
EMail _rowToEMail(QueryRow row) {
|
||||
return email.mapFromRow(row);
|
||||
return EMail(
|
||||
sender: row.readString('sender'),
|
||||
title: row.readString('title'),
|
||||
body: row.readString('body'),
|
||||
);
|
||||
}
|
||||
|
||||
Selectable<EMail> searchEmails(String term) {
|
||||
|
|
|
@ -1372,7 +1372,13 @@ abstract class _$TodoDb extends GeneratedDatabase {
|
|||
}
|
||||
|
||||
TodoEntry _rowToTodoEntry(QueryRow row) {
|
||||
return todosTable.mapFromRow(row);
|
||||
return TodoEntry(
|
||||
id: row.readInt('id'),
|
||||
title: row.readString('title'),
|
||||
content: row.readString('content'),
|
||||
targetDate: row.readDateTime('target_date'),
|
||||
category: row.readInt('category'),
|
||||
);
|
||||
}
|
||||
|
||||
Selectable<TodoEntry> withInQuery(String var1, String var2, List<int> var3) {
|
||||
|
@ -1493,7 +1499,13 @@ mixin _$SomeDaoMixin on DatabaseAccessor<TodoDb> {
|
|||
$SharedTodosTable get sharedTodos => db.sharedTodos;
|
||||
$TodosTableTable get todosTable => db.todosTable;
|
||||
TodoEntry _rowToTodoEntry(QueryRow row) {
|
||||
return todosTable.mapFromRow(row);
|
||||
return TodoEntry(
|
||||
id: row.readInt('id'),
|
||||
title: row.readString('title'),
|
||||
content: row.readString('content'),
|
||||
targetDate: row.readDateTime('target_date'),
|
||||
category: row.readInt('category'),
|
||||
);
|
||||
}
|
||||
|
||||
Selectable<TodoEntry> todosForUserQuery(int user) {
|
||||
|
|
|
@ -98,22 +98,15 @@ class QueryWriter {
|
|||
..write('${_select.resultClassName} ${_nameOfMappingMethod()}')
|
||||
..write('(QueryRow row) {\n');
|
||||
|
||||
// If we're matching an existing table from moor - let's just use the
|
||||
// mapping method we're generating for each table!
|
||||
if (_select.resultSet.matchingTable != null) {
|
||||
final table = _select.resultSet.matchingTable;
|
||||
_buffer.write('return ${table.tableFieldName}.mapFromRow(row);\n');
|
||||
} else {
|
||||
// For more complex results, generate a custom constructor call
|
||||
_buffer.write('return ${_select.resultClassName}(');
|
||||
for (final column in _select.resultSet.columns) {
|
||||
final fieldName = _select.resultSet.dartNameFor(column);
|
||||
_buffer.write('$fieldName: ${_readingCode(column)},');
|
||||
}
|
||||
|
||||
_buffer.write(');\n');
|
||||
// note that, even if the result set has a matching table, we can't just
|
||||
// use the mapFromRow() function of that table - the column names might
|
||||
// be different!
|
||||
_buffer.write('return ${_select.resultClassName}(');
|
||||
for (final column in _select.resultSet.columns) {
|
||||
final fieldName = _select.resultSet.dartNameFor(column);
|
||||
_buffer.write('$fieldName: ${_readingCode(column)},');
|
||||
}
|
||||
_buffer.write('}\n');
|
||||
_buffer.write(');\n}\n');
|
||||
|
||||
_writtenMappingMethods.add(_nameOfMappingMethod());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue