BoxerQueryOption.merge constructor
BoxerQueryOption.merge(
- List<
BoxerQueryOption> options, { - BoxerOptionType join = BoxerOptionType.AND,
Attention groupBy having limit offset are implemented by merge
Implementation
factory BoxerQueryOption.merge(
List<BoxerQueryOption> options, {
BoxerOptionType join = BoxerOptionType.AND,
}) {
bool? distinct;
List<String> columns = [];
List<String> wheres = [];
List<Object?> whereArgs = [];
List<String> orderBys = [];
options.forEach((e) {
// use the last one
if (e.distinct != null) distinct = e.distinct;
/// columns
if (e.columns != null) columns.addAll(e.columns!);
/// where and whereArgs
String? _where = e.where;
if (_where != null && (_where = _where.trim()).isNotEmpty) {
wheres.add(_where);
// Important: u may ensure that the 'whereArgs' is not null, and its length is equal with 'where' clause
if (e.whereArgs != null) whereArgs.addAll(e.whereArgs!);
}
/// orderBy
String? _orderBy = e.orderBy;
if (_orderBy != null && (_orderBy = _orderBy.trim()).isNotEmpty) {
orderBys.add(_orderBy);
}
});
/// use the first one as the clone template
BoxerQueryOption newOp = options.firstSafe?.clone() ?? BoxerQueryOption();
String? _where = joinWith(wheres, join);
List<Object?>? _whereArgs = whereArgs.isEmpty ? null : whereArgs;
/// assign the merge value to the new option obj
newOp.where = _where;
newOp.whereArgs = _whereArgs;
if (columns.isNotEmpty) {
newOp.columns = columns;
}
if (orderBys.isNotEmpty) {
newOp.orderBy = orderBys.join(", ");
}
newOp.distinct = distinct;
/// TODO ... groupBy MERGE NOT IMPLEMENTATION
/// TODO ... having MERGE NOT IMPLEMENTATION
/// TODO ... limit MERGE NOT IMPLEMENTATION, WHICH ONE TO USE?
/// TODO ... offset MERGE NOT IMPLEMENTATION, WHICH ONE TO USE?
return newOp;
}