mirror of https://github.com/AMT-Cheif/drift.git
Fix view mapping generation (#1855)
This commit is contained in:
parent
a4dc3a3305
commit
49f3f64bcc
|
@ -479,8 +479,8 @@ class TodoCategoryItemCountData extends DataClass {
|
|||
{String? prefix}) {
|
||||
final effectivePrefix = prefix ?? '';
|
||||
return TodoCategoryItemCountData(
|
||||
name: const StringType().mapFromDatabaseResponse(
|
||||
data['${effectivePrefix}todo_categories.name'])!,
|
||||
name: const StringType()
|
||||
.mapFromDatabaseResponse(data['${effectivePrefix}name'])!,
|
||||
itemCount: const IntType()
|
||||
.mapFromDatabaseResponse(data['${effectivePrefix}item_count'])!,
|
||||
);
|
||||
|
@ -590,7 +590,7 @@ class TodoItemWithCategoryNameViewData extends DataClass {
|
|||
final effectivePrefix = prefix ?? '';
|
||||
return TodoItemWithCategoryNameViewData(
|
||||
id: const IntType()
|
||||
.mapFromDatabaseResponse(data['${effectivePrefix}todo_items.id'])!,
|
||||
.mapFromDatabaseResponse(data['${effectivePrefix}id'])!,
|
||||
title: const StringType()
|
||||
.mapFromDatabaseResponse(data['${effectivePrefix}title'])!,
|
||||
);
|
||||
|
|
|
@ -1512,9 +1512,9 @@ class TodoWithCategoryViewData extends DataClass {
|
|||
final effectivePrefix = prefix ?? '';
|
||||
return TodoWithCategoryViewData(
|
||||
title: const StringType()
|
||||
.mapFromDatabaseResponse(data['${effectivePrefix}todos.title']),
|
||||
.mapFromDatabaseResponse(data['${effectivePrefix}title']),
|
||||
description: const StringType()
|
||||
.mapFromDatabaseResponse(data['${effectivePrefix}categories.desc'])!,
|
||||
.mapFromDatabaseResponse(data['${effectivePrefix}desc'])!,
|
||||
);
|
||||
}
|
||||
factory TodoWithCategoryViewData.fromJson(Map<String, dynamic> json,
|
||||
|
|
|
@ -28,4 +28,19 @@ void main() {
|
|||
.get();
|
||||
expect(rows.isSorted((a, b) => a.id.compareTo(b.id)), isFalse);
|
||||
});
|
||||
|
||||
test('can select view', () async {
|
||||
final category = await db.categories.insertReturning(
|
||||
CategoriesCompanion.insert(description: 'category description'));
|
||||
await db.todosTable.insertOne(TodosTableCompanion.insert(
|
||||
content: 'some content',
|
||||
title: const Value('title'),
|
||||
category: Value(category.id)));
|
||||
|
||||
final result = await db.todoWithCategoryView.select().getSingle();
|
||||
expect(
|
||||
result,
|
||||
TodoWithCategoryViewData(
|
||||
description: 'category description', title: 'title'));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -363,10 +363,7 @@ class RowMappingWriter {
|
|||
|
||||
void writeArguments(StringBuffer buffer) {
|
||||
String readAndMap(MoorColumn column) {
|
||||
var columnName = column.name.name;
|
||||
if (column.table != null && column.table != table) {
|
||||
columnName = '${column.table!.sqlName}.${column.name.name}';
|
||||
}
|
||||
final columnName = column.name.name;
|
||||
final rawData = "data['\${effectivePrefix}$columnName']";
|
||||
final sqlType = 'const ${sqlTypes[column.type]}()';
|
||||
var loadType = '$sqlType.mapFromDatabaseResponse($rawData)';
|
||||
|
|
Loading…
Reference in New Issue