diff --git a/drift/CHANGELOG.md b/drift/CHANGELOG.md index 5bd8b886..bc027854 100644 --- a/drift/CHANGELOG.md +++ b/drift/CHANGELOG.md @@ -4,6 +4,8 @@ - Add the `@TableIndex` annotation for table classes to add an index to the table. - 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 diff --git a/drift/lib/src/runtime/query_builder/statements/select/select.dart b/drift/lib/src/runtime/query_builder/statements/select/select.dart index 9b9140f6..2c0c0d63 100644 --- a/drift/lib/src/runtime/query_builder/statements/select/select.dart +++ b/drift/lib/src/runtime/query_builder/statements/select/select.dart @@ -214,4 +214,13 @@ class TypedResult { 'Invalid call to read(): $expr. This result set does not have a column ' '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( + GeneratedColumnWithTypeConverter column) { + return column.converter.fromSql(read(column)); + } } diff --git a/drift/test/database/statements/join_test.dart b/drift/test/database/statements/join_test.dart index 1b622c2c..54d7fae6 100644 --- a/drift/test/database/statements/join_test.dart +++ b/drift/test/database/statements/join_test.dart @@ -62,6 +62,7 @@ void main() { 't.content': 'content', 't.target_date': date.millisecondsSinceEpoch ~/ 1000, 't.category': 3, + 't.status': 'workInProgress', 'c.id': 3, 'c.desc': 'description', 'c.description_in_upper_case': 'DESCRIPTION', @@ -85,6 +86,7 @@ void main() { content: 'content', targetDate: date, category: 3, + status: TodoStatus.workInProgress, )); expect( @@ -101,6 +103,9 @@ void main() { expect(row.read(todos.id), 5); 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)); });