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}) {
|
{String? prefix}) {
|
||||||
final effectivePrefix = prefix ?? '';
|
final effectivePrefix = prefix ?? '';
|
||||||
return TodoCategoryItemCountData(
|
return TodoCategoryItemCountData(
|
||||||
name: const StringType().mapFromDatabaseResponse(
|
name: const StringType()
|
||||||
data['${effectivePrefix}todo_categories.name'])!,
|
.mapFromDatabaseResponse(data['${effectivePrefix}name'])!,
|
||||||
itemCount: const IntType()
|
itemCount: const IntType()
|
||||||
.mapFromDatabaseResponse(data['${effectivePrefix}item_count'])!,
|
.mapFromDatabaseResponse(data['${effectivePrefix}item_count'])!,
|
||||||
);
|
);
|
||||||
|
@ -590,7 +590,7 @@ class TodoItemWithCategoryNameViewData extends DataClass {
|
||||||
final effectivePrefix = prefix ?? '';
|
final effectivePrefix = prefix ?? '';
|
||||||
return TodoItemWithCategoryNameViewData(
|
return TodoItemWithCategoryNameViewData(
|
||||||
id: const IntType()
|
id: const IntType()
|
||||||
.mapFromDatabaseResponse(data['${effectivePrefix}todo_items.id'])!,
|
.mapFromDatabaseResponse(data['${effectivePrefix}id'])!,
|
||||||
title: const StringType()
|
title: const StringType()
|
||||||
.mapFromDatabaseResponse(data['${effectivePrefix}title'])!,
|
.mapFromDatabaseResponse(data['${effectivePrefix}title'])!,
|
||||||
);
|
);
|
||||||
|
|
|
@ -1512,9 +1512,9 @@ class TodoWithCategoryViewData extends DataClass {
|
||||||
final effectivePrefix = prefix ?? '';
|
final effectivePrefix = prefix ?? '';
|
||||||
return TodoWithCategoryViewData(
|
return TodoWithCategoryViewData(
|
||||||
title: const StringType()
|
title: const StringType()
|
||||||
.mapFromDatabaseResponse(data['${effectivePrefix}todos.title']),
|
.mapFromDatabaseResponse(data['${effectivePrefix}title']),
|
||||||
description: const StringType()
|
description: const StringType()
|
||||||
.mapFromDatabaseResponse(data['${effectivePrefix}categories.desc'])!,
|
.mapFromDatabaseResponse(data['${effectivePrefix}desc'])!,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
factory TodoWithCategoryViewData.fromJson(Map<String, dynamic> json,
|
factory TodoWithCategoryViewData.fromJson(Map<String, dynamic> json,
|
||||||
|
|
|
@ -28,4 +28,19 @@ void main() {
|
||||||
.get();
|
.get();
|
||||||
expect(rows.isSorted((a, b) => a.id.compareTo(b.id)), isFalse);
|
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) {
|
void writeArguments(StringBuffer buffer) {
|
||||||
String readAndMap(MoorColumn column) {
|
String readAndMap(MoorColumn column) {
|
||||||
var columnName = column.name.name;
|
final columnName = column.name.name;
|
||||||
if (column.table != null && column.table != table) {
|
|
||||||
columnName = '${column.table!.sqlName}.${column.name.name}';
|
|
||||||
}
|
|
||||||
final rawData = "data['\${effectivePrefix}$columnName']";
|
final rawData = "data['\${effectivePrefix}$columnName']";
|
||||||
final sqlType = 'const ${sqlTypes[column.type]}()';
|
final sqlType = 'const ${sqlTypes[column.type]}()';
|
||||||
var loadType = '$sqlType.mapFromDatabaseResponse($rawData)';
|
var loadType = '$sqlType.mapFromDatabaseResponse($rawData)';
|
||||||
|
|
Loading…
Reference in New Issue