copyWith method

Sqler copyWith({
  1. List<QSelectField>? selects,
  2. bool? delete,
  3. List<QField>? from,
  4. List<Where>? where,
  5. Map<String, QVar>? params,
  6. List<QField>? groupBy,
  7. List<Having>? having,
  8. List<QOrder>? orderBy,
  9. Limit? limit,
  10. List<Join>? joins,
  11. List<Map<String, QVar>>? insert,
  12. Map<String, QVar>? update,
})

Creates a copy of this query with optional overrides for specific properties.

This method implements the copy-with pattern, allowing you to create a new Sqler instance based on the current one but with some properties modified. Any parameter that is null will use the value from the current instance.

Returns a new Sqler instance with the specified modifications.

Example:

var baseQuery = Sqler().from(QField('users'));
var modifiedQuery = baseQuery.copyWith(
  selects: [QSelect('name'), QSelect('email')],
  limit: Limit(0, 10)
); // Creates a new query with different SELECT and LIMIT

Implementation

Sqler copyWith({
  List<QSelectField>? selects,
  bool? delete,
  List<QField>? from,
  List<Where>? where,
  Map<String, QVar>? params,
  List<QField>? groupBy,
  List<Having>? having,
  List<QOrder>? orderBy,
  Limit? limit,
  List<Join>? joins,
  List<Map<String, QVar>>? insert,
  Map<String, QVar>? update,
}) {
  var newQuery = Sqler();
  newQuery._select = selects ?? _select;
  newQuery._delete = delete ?? _delete;
  newQuery._from = from ?? _from;
  newQuery._where = where ?? _where;
  newQuery._params = params ?? _params;
  newQuery._groupBy = groupBy ?? _groupBy;
  newQuery._having = having ?? _having;
  newQuery._orderBy = orderBy ?? _orderBy;
  newQuery._limit = limit ?? _limit;
  newQuery._joins = joins ?? _joins;
  newQuery._insert = insert ?? _insert;
  newQuery._update = update ?? _update;

  return newQuery;
}