mirror of https://github.com/AMT-Cheif/drift.git
Add utility for reading columns with converter
This commit is contained in:
parent
2f732202b0
commit
0ed7358f62
|
@ -4,6 +4,8 @@
|
||||||
- Add the `@TableIndex` annotation for table classes to add an index to the
|
- Add the `@TableIndex` annotation for table classes to add an index to the
|
||||||
table.
|
table.
|
||||||
- Support `json_each` and `json_tree`.
|
- Support `json_each` and `json_tree`.
|
||||||
|
- Add `TypedResult.readWithConverter` to read a column with a type converter
|
||||||
|
from a join result row.
|
||||||
|
|
||||||
## 2.11.1
|
## 2.11.1
|
||||||
|
|
||||||
|
|
|
@ -214,4 +214,13 @@ class TypedResult {
|
||||||
'Invalid call to read(): $expr. This result set does not have a column '
|
'Invalid call to read(): $expr. This result set does not have a column '
|
||||||
'for that expression.');
|
'for that expression.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Reads a column that has a type converter applied to it from the row.
|
||||||
|
///
|
||||||
|
/// This calls [read] internally, which reads the column but without applying
|
||||||
|
/// a type converter.
|
||||||
|
D? readWithConverter<D, S extends Object>(
|
||||||
|
GeneratedColumnWithTypeConverter<D, S> column) {
|
||||||
|
return column.converter.fromSql(read<S>(column));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,7 @@ void main() {
|
||||||
't.content': 'content',
|
't.content': 'content',
|
||||||
't.target_date': date.millisecondsSinceEpoch ~/ 1000,
|
't.target_date': date.millisecondsSinceEpoch ~/ 1000,
|
||||||
't.category': 3,
|
't.category': 3,
|
||||||
|
't.status': 'workInProgress',
|
||||||
'c.id': 3,
|
'c.id': 3,
|
||||||
'c.desc': 'description',
|
'c.desc': 'description',
|
||||||
'c.description_in_upper_case': 'DESCRIPTION',
|
'c.description_in_upper_case': 'DESCRIPTION',
|
||||||
|
@ -85,6 +86,7 @@ void main() {
|
||||||
content: 'content',
|
content: 'content',
|
||||||
targetDate: date,
|
targetDate: date,
|
||||||
category: 3,
|
category: 3,
|
||||||
|
status: TodoStatus.workInProgress,
|
||||||
));
|
));
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
|
@ -101,6 +103,9 @@ void main() {
|
||||||
expect(row.read(todos.id), 5);
|
expect(row.read(todos.id), 5);
|
||||||
expect(row.read(categories.description), 'description');
|
expect(row.read(categories.description), 'description');
|
||||||
|
|
||||||
|
expect(row.read(todos.status), 'workInProgress');
|
||||||
|
expect(row.readWithConverter(todos.status), TodoStatus.workInProgress);
|
||||||
|
|
||||||
verify(executor.runSelect(argThat(contains('DISTINCT')), any));
|
verify(executor.runSelect(argThat(contains('DISTINCT')), any));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue