Remove includeJoinedTableColumns entirely

This commit is contained in:
Simon Binder 2022-07-16 12:07:12 +02:00
parent b95e70b438
commit 8d840f3eb3
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
7 changed files with 17 additions and 38 deletions

View File

@ -5,8 +5,9 @@
It is an error to use a non-nullable type converter on a column that is nullable in It is an error to use a non-nullable type converter on a column that is nullable in
SQL and vice-versa. SQL and vice-versa.
- __Breaking__: Mapping methods on type converters are now called `toSql` and `fromSql`. - __Breaking__: Mapping methods on type converters are now called `toSql` and `fromSql`.
- __Breaking__: The `includeJoinedTableColumns` parameter on `selectOnly()` is now - __Breaking__: Remove the `includeJoinedTableColumns` parameter on `selectOnly()`.
disabled by default. The method now behaves as if that parameter was turned off. To use columns from a
joined table, add them with `addColumns`.
- Consistently handle transaction errors like a failing `BEGIN` or `COMMIT` - Consistently handle transaction errors like a failing `BEGIN` or `COMMIT`
across database implementations. across database implementations.
- Support nested transactions. - Support nested transactions.

View File

@ -571,10 +571,8 @@ class $TodoCategoryItemCountView
} }
@override @override
Query? get query => (attachedDatabase.selectOnly(todoCategories, Query? get query =>
includeJoinedTableColumns: false) (attachedDatabase.selectOnly(todoCategories)..addColumns($columns)).join([
..addColumns($columns))
.join([
innerJoin(todoItems, todoItems.categoryId.equalsExp(todoCategories.id)) innerJoin(todoItems, todoItems.categoryId.equalsExp(todoCategories.id))
]); ]);
@override @override
@ -686,9 +684,7 @@ class $TodoItemWithCategoryNameViewView extends ViewInfo<
@override @override
Query? get query => Query? get query =>
(attachedDatabase.selectOnly(todoItems, includeJoinedTableColumns: false) (attachedDatabase.selectOnly(todoItems)..addColumns($columns)).join([
..addColumns($columns))
.join([
innerJoin( innerJoin(
todoCategories, todoCategories.id.equalsExp(todoItems.categoryId)) todoCategories, todoCategories.id.equalsExp(todoItems.categoryId))
]); ]);

View File

@ -244,13 +244,6 @@ abstract class DatabaseConnectionUser {
/// The [distinct] parameter (defaults to false) can be used to remove /// The [distinct] parameter (defaults to false) can be used to remove
/// duplicate rows from the result set. /// duplicate rows from the result set.
/// ///
/// The [includeJoinedTableColumns] parameter (defaults to true) can be used
/// to determinate join statement's `useColumns` parameter default value. Set
/// it to false if you don't want to include joined table columns by default.
/// If you leave it on true and don't set `useColumns` parameter to false in
/// join declarations, all columns of joined table will be included in query
/// by default.
///
/// For simple queries, use [select]. /// For simple queries, use [select].
/// ///
/// See also: /// See also:
@ -258,10 +251,9 @@ abstract class DatabaseConnectionUser {
/// - the documentation on [group by](https://drift.simonbinder.eu/docs/advanced-features/joins/#group-by) /// - the documentation on [group by](https://drift.simonbinder.eu/docs/advanced-features/joins/#group-by)
JoinedSelectStatement<T, R> selectOnly<T extends HasResultSet, R>( JoinedSelectStatement<T, R> selectOnly<T extends HasResultSet, R>(
ResultSetImplementation<T, R> table, ResultSetImplementation<T, R> table,
{bool distinct = false, {bool distinct = false}) {
bool includeJoinedTableColumns = false}) {
return JoinedSelectStatement<T, R>( return JoinedSelectStatement<T, R>(
resolvedEngine, table, [], distinct, false, includeJoinedTableColumns); resolvedEngine, table, [], distinct, false, false);
} }
/// Starts a [DeleteStatement] that can be used to delete rows from a table. /// Starts a [DeleteStatement] that can be used to delete rows from a table.
@ -627,11 +619,8 @@ class TableOrViewOperations<Tbl extends HasResultSet, Row> {
/// Composes a `SELECT` statement only selecting a subset of columns. /// Composes a `SELECT` statement only selecting a subset of columns.
/// ///
/// This is equivalent to calling [DatabaseConnectionUser.selectOnly]. /// This is equivalent to calling [DatabaseConnectionUser.selectOnly].
JoinedSelectStatement<Tbl, Row> selectOnly( JoinedSelectStatement<Tbl, Row> selectOnly({bool distinct = false}) {
{bool distinct = false, bool includeJoinedTableColumns = false}) { return _user.selectOnly(_sourceSet, distinct: distinct);
return _user.selectOnly(_sourceSet,
distinct: distinct,
includeJoinedTableColumns: includeJoinedTableColumns);
} }
} }

View File

@ -14,11 +14,8 @@ extension TableOrViewStatements<Tbl extends HasResultSet, Row>
/// Composes a `SELECT` statement only selecting a subset of columns. /// Composes a `SELECT` statement only selecting a subset of columns.
/// ///
/// This is equivalent to calling [DatabaseConnectionUser.selectOnly]. /// This is equivalent to calling [DatabaseConnectionUser.selectOnly].
JoinedSelectStatement<Tbl, Row> selectOnly( JoinedSelectStatement<Tbl, Row> selectOnly({bool distinct = false}) {
{bool distinct = false, bool includeJoinedTableColumns = false}) { return attachedDatabase.selectOnly(this, distinct: distinct);
return attachedDatabase.selectOnly(this,
distinct: distinct,
includeJoinedTableColumns: includeJoinedTableColumns);
} }
} }

View File

@ -406,8 +406,7 @@ void main() {
final categories = db.categories; final categories = db.categories;
final todos = db.todosTable; final todos = db.todosTable;
final query = final query = db.selectOnly(categories).join([
db.selectOnly(categories, includeJoinedTableColumns: false).join([
innerJoin( innerJoin(
todos, todos,
todos.category.equalsExp(categories.id), todos.category.equalsExp(categories.id),

View File

@ -1497,8 +1497,7 @@ class $CategoryTodoCountViewView
@override @override
Query? get query => Query? get query =>
(attachedDatabase.selectOnly(categories, includeJoinedTableColumns: false) (attachedDatabase.selectOnly(categories)..addColumns($columns))
..addColumns($columns))
.join([innerJoin(todos, todos.category.equalsExp(categories.id))]) .join([innerJoin(todos, todos.category.equalsExp(categories.id))])
..groupBy([categories.id]); ..groupBy([categories.id]);
@override @override
@ -1605,9 +1604,7 @@ class $TodoWithCategoryViewView
} }
@override @override
Query? get query => (attachedDatabase.selectOnly(todos, Query? get query => (attachedDatabase.selectOnly(todos)..addColumns($columns))
includeJoinedTableColumns: false)
..addColumns($columns))
.join([innerJoin(categories, categories.id.equalsExp(todos.category))]); .join([innerJoin(categories, categories.id.equalsExp(todos.category))]);
@override @override
Set<String> get readTables => const {'todos', 'categories'}; Set<String> get readTables => const {'todos', 'categories'};

View File

@ -132,8 +132,8 @@ class ViewWriter extends TableOrViewWriter {
buffer.write('@override\nQuery? get query => '); buffer.write('@override\nQuery? get query => ');
final query = view.viewQuery; final query = view.viewQuery;
if (query != null) { if (query != null) {
buffer.write('(attachedDatabase.selectOnly(${query.from}, ' buffer.write('(attachedDatabase.selectOnly(${query.from})'
'includeJoinedTableColumns: false)..addColumns(\$columns))' '..addColumns(\$columns))'
'${query.query};'); '${query.query};');
} else { } else {
buffer.write('null;\n'); buffer.write('null;\n');