Merge pull request #43 from debuggerx01/master
Add 'where.raw(String whereSql)'
This commit is contained in:
commit
8adb18662d
28 changed files with 1797 additions and 689 deletions
|
@ -1,67 +0,0 @@
|
||||||
// **************************************************************************
|
|
||||||
// JsonModelGenerator
|
|
||||||
// **************************************************************************
|
|
||||||
|
|
||||||
@generatedSerializable
|
|
||||||
class Employee extends _Employee {
|
|
||||||
Employee(
|
|
||||||
{this.id,
|
|
||||||
this.firstName,
|
|
||||||
this.lastName,
|
|
||||||
this.salary,
|
|
||||||
this.createdAt,
|
|
||||||
this.updatedAt});
|
|
||||||
|
|
||||||
@override
|
|
||||||
final String id;
|
|
||||||
|
|
||||||
@override
|
|
||||||
final String firstName;
|
|
||||||
|
|
||||||
@override
|
|
||||||
final String lastName;
|
|
||||||
|
|
||||||
@override
|
|
||||||
final double salary;
|
|
||||||
|
|
||||||
@override
|
|
||||||
final DateTime createdAt;
|
|
||||||
|
|
||||||
@override
|
|
||||||
final DateTime updatedAt;
|
|
||||||
|
|
||||||
Employee copyWith(
|
|
||||||
{String id,
|
|
||||||
String firstName,
|
|
||||||
String lastName,
|
|
||||||
double salary,
|
|
||||||
DateTime createdAt,
|
|
||||||
DateTime updatedAt}) {
|
|
||||||
return new Employee(
|
|
||||||
id: id ?? this.id,
|
|
||||||
firstName: firstName ?? this.firstName,
|
|
||||||
lastName: lastName ?? this.lastName,
|
|
||||||
salary: salary ?? this.salary,
|
|
||||||
createdAt: createdAt ?? this.createdAt,
|
|
||||||
updatedAt: updatedAt ?? this.updatedAt);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator ==(other) {
|
|
||||||
return other is _Employee &&
|
|
||||||
other.id == id &&
|
|
||||||
other.firstName == firstName &&
|
|
||||||
other.lastName == lastName &&
|
|
||||||
other.salary == salary &&
|
|
||||||
other.createdAt == createdAt &&
|
|
||||||
other.updatedAt == updatedAt;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
int get hashCode {
|
|
||||||
return hashObjects([id, firstName, lastName, salary, createdAt, updatedAt]);
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
|
||||||
return EmployeeSerializer.toMap(this);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,18 +1,19 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:angel3_migration/angel3_migration.dart';
|
||||||
import 'package:angel3_orm/angel3_orm.dart';
|
import 'package:angel3_orm/angel3_orm.dart';
|
||||||
import 'package:angel3_serialize/angel3_serialize.dart';
|
import 'package:angel3_serialize/angel3_serialize.dart';
|
||||||
import 'package:optional/optional.dart';
|
import 'package:optional/optional.dart';
|
||||||
|
|
||||||
part 'main.g.dart';
|
part 'main.g.dart';
|
||||||
part 'main.serializer.g.dart';
|
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
var query = EmployeeQuery()
|
var query = EmployeeQuery()
|
||||||
..where?.firstName.equals('Rich')
|
..where?.firstName.equals('Rich')
|
||||||
..where?.lastName.equals('Person')
|
..where?.lastName.equals('Person')
|
||||||
|
..where?.raw('COM.deleted = false')
|
||||||
..orWhere((w) => w.salary.greaterThanOrEqualTo(75000))
|
..orWhere((w) => w.salary.greaterThanOrEqualTo(75000))
|
||||||
..join('companies', 'company_id', 'id');
|
..join('companies', 'company_id', 'id', alias: 'COM');
|
||||||
|
|
||||||
var richPerson = await query.getOne(_FakeExecutor());
|
var richPerson = await query.getOne(_FakeExecutor());
|
||||||
if (richPerson.isPresent) {
|
if (richPerson.isPresent) {
|
||||||
|
@ -31,7 +32,7 @@ class _FakeExecutor extends QueryExecutor {
|
||||||
print(
|
print(
|
||||||
'_FakeExecutor received query: $query and values: $substitutionValues');
|
'_FakeExecutor received query: $query and values: $substitutionValues');
|
||||||
return [
|
return [
|
||||||
[1, 'Rich', 'Person', 100000.0, now, now]
|
[1, now, now, 'Rich', 'Person', 100000.0]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,65 +51,3 @@ abstract class _Employee extends Model {
|
||||||
|
|
||||||
double? get salary;
|
double? get salary;
|
||||||
}
|
}
|
||||||
|
|
||||||
class EmployeeQuery extends Query<Employee, EmployeeQueryWhere> {
|
|
||||||
@override
|
|
||||||
final QueryValues values = MapQueryValues();
|
|
||||||
|
|
||||||
EmployeeQueryWhere? _where;
|
|
||||||
|
|
||||||
EmployeeQuery() {
|
|
||||||
_where = EmployeeQueryWhere(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
EmployeeQueryWhere? get where => _where;
|
|
||||||
|
|
||||||
@override
|
|
||||||
String get tableName => 'employees';
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<String> get fields =>
|
|
||||||
['id', 'first_name', 'last_name', 'salary', 'created_at', 'updated_at'];
|
|
||||||
|
|
||||||
@override
|
|
||||||
EmployeeQueryWhere newWhereClause() => EmployeeQueryWhere(this);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Optional<Employee> deserialize(List row) {
|
|
||||||
return Optional.ofNullable(Employee(
|
|
||||||
id: row[0].toString(),
|
|
||||||
firstName: row[1] as String,
|
|
||||||
lastName: row[2] as String,
|
|
||||||
salary: row[3] as double,
|
|
||||||
createdAt: row[4] as DateTime,
|
|
||||||
updatedAt: row[5] as DateTime));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class EmployeeQueryWhere extends QueryWhere {
|
|
||||||
EmployeeQueryWhere(EmployeeQuery query)
|
|
||||||
: id = NumericSqlExpressionBuilder(query, 'id'),
|
|
||||||
firstName = StringSqlExpressionBuilder(query, 'first_name'),
|
|
||||||
lastName = StringSqlExpressionBuilder(query, 'last_name'),
|
|
||||||
salary = NumericSqlExpressionBuilder(query, 'salary'),
|
|
||||||
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
|
|
||||||
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
|
|
||||||
|
|
||||||
@override
|
|
||||||
Iterable<SqlExpressionBuilder> get expressionBuilders {
|
|
||||||
return [id, firstName, lastName, salary, createdAt, updatedAt];
|
|
||||||
}
|
|
||||||
|
|
||||||
final NumericSqlExpressionBuilder<int> id;
|
|
||||||
|
|
||||||
final StringSqlExpressionBuilder firstName;
|
|
||||||
|
|
||||||
final StringSqlExpressionBuilder lastName;
|
|
||||||
|
|
||||||
final NumericSqlExpressionBuilder<double> salary;
|
|
||||||
|
|
||||||
final DateTimeSqlExpressionBuilder createdAt;
|
|
||||||
|
|
||||||
final DateTimeSqlExpressionBuilder updatedAt;
|
|
||||||
}
|
|
||||||
|
|
|
@ -2,6 +2,171 @@
|
||||||
|
|
||||||
part of 'main.dart';
|
part of 'main.dart';
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// MigrationGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
class EmployeeMigration extends Migration {
|
||||||
|
@override
|
||||||
|
void up(Schema schema) {
|
||||||
|
schema.create('employees', (table) {
|
||||||
|
table.serial('id').primaryKey();
|
||||||
|
table.timeStamp('created_at');
|
||||||
|
table.timeStamp('updated_at');
|
||||||
|
table.varChar('first_name', length: 255);
|
||||||
|
table.varChar('last_name', length: 255);
|
||||||
|
table.declareColumn(
|
||||||
|
'salary', Column(type: ColumnType('decimal'), length: 255));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void down(Schema schema) {
|
||||||
|
schema.drop('employees');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// OrmGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
class EmployeeQuery extends Query<Employee, EmployeeQueryWhere> {
|
||||||
|
EmployeeQuery({Query? parent, Set<String>? trampoline})
|
||||||
|
: super(parent: parent) {
|
||||||
|
trampoline ??= <String>{};
|
||||||
|
trampoline.add(tableName);
|
||||||
|
_where = EmployeeQueryWhere(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
final EmployeeQueryValues values = EmployeeQueryValues();
|
||||||
|
|
||||||
|
EmployeeQueryWhere? _where;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Map<String, String> get casts {
|
||||||
|
return {'salary': 'text'};
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get tableName {
|
||||||
|
return 'employees';
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<String> get fields {
|
||||||
|
return const [
|
||||||
|
'id',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
'first_name',
|
||||||
|
'last_name',
|
||||||
|
'salary'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
EmployeeQueryWhere? get where {
|
||||||
|
return _where;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
EmployeeQueryWhere newWhereClause() {
|
||||||
|
return EmployeeQueryWhere(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Optional<Employee> parseRow(List row) {
|
||||||
|
if (row.every((x) => x == null)) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
var model = Employee(
|
||||||
|
id: row[0].toString(),
|
||||||
|
createdAt: (row[1] as DateTime?),
|
||||||
|
updatedAt: (row[2] as DateTime?),
|
||||||
|
firstName: (row[3] as String?),
|
||||||
|
lastName: (row[4] as String?),
|
||||||
|
salary: double.tryParse(row[5].toString()));
|
||||||
|
return Optional.of(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Optional<Employee> deserialize(List row) {
|
||||||
|
return parseRow(row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class EmployeeQueryWhere extends QueryWhere {
|
||||||
|
EmployeeQueryWhere(EmployeeQuery query)
|
||||||
|
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||||
|
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||||
|
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
|
||||||
|
firstName = StringSqlExpressionBuilder(query, 'first_name'),
|
||||||
|
lastName = StringSqlExpressionBuilder(query, 'last_name'),
|
||||||
|
salary = NumericSqlExpressionBuilder<double>(query, 'salary');
|
||||||
|
|
||||||
|
final NumericSqlExpressionBuilder<int> id;
|
||||||
|
|
||||||
|
final DateTimeSqlExpressionBuilder createdAt;
|
||||||
|
|
||||||
|
final DateTimeSqlExpressionBuilder updatedAt;
|
||||||
|
|
||||||
|
final StringSqlExpressionBuilder firstName;
|
||||||
|
|
||||||
|
final StringSqlExpressionBuilder lastName;
|
||||||
|
|
||||||
|
final NumericSqlExpressionBuilder<double> salary;
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<SqlExpressionBuilder> get expressionBuilders {
|
||||||
|
return [id, createdAt, updatedAt, firstName, lastName, salary];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class EmployeeQueryValues extends MapQueryValues {
|
||||||
|
@override
|
||||||
|
Map<String, String> get casts {
|
||||||
|
return {'salary': 'decimal'};
|
||||||
|
}
|
||||||
|
|
||||||
|
String? get id {
|
||||||
|
return (values['id'] as String?);
|
||||||
|
}
|
||||||
|
|
||||||
|
set id(String? value) => values['id'] = value;
|
||||||
|
DateTime? get createdAt {
|
||||||
|
return (values['created_at'] as DateTime?);
|
||||||
|
}
|
||||||
|
|
||||||
|
set createdAt(DateTime? value) => values['created_at'] = value;
|
||||||
|
DateTime? get updatedAt {
|
||||||
|
return (values['updated_at'] as DateTime?);
|
||||||
|
}
|
||||||
|
|
||||||
|
set updatedAt(DateTime? value) => values['updated_at'] = value;
|
||||||
|
String? get firstName {
|
||||||
|
return (values['first_name'] as String?);
|
||||||
|
}
|
||||||
|
|
||||||
|
set firstName(String? value) => values['first_name'] = value;
|
||||||
|
String? get lastName {
|
||||||
|
return (values['last_name'] as String?);
|
||||||
|
}
|
||||||
|
|
||||||
|
set lastName(String? value) => values['last_name'] = value;
|
||||||
|
double? get salary {
|
||||||
|
return double.tryParse((values['salary'] as String));
|
||||||
|
}
|
||||||
|
|
||||||
|
set salary(double? value) => values['salary'] = value.toString();
|
||||||
|
void copyFrom(Employee model) {
|
||||||
|
createdAt = model.createdAt;
|
||||||
|
updatedAt = model.updatedAt;
|
||||||
|
firstName = model.firstName;
|
||||||
|
lastName = model.lastName;
|
||||||
|
salary = model.salary;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// **************************************************************************
|
// **************************************************************************
|
||||||
// JsonModelGenerator
|
// JsonModelGenerator
|
||||||
// **************************************************************************
|
// **************************************************************************
|
||||||
|
@ -10,63 +175,154 @@ part of 'main.dart';
|
||||||
class Employee extends _Employee {
|
class Employee extends _Employee {
|
||||||
Employee(
|
Employee(
|
||||||
{this.id,
|
{this.id,
|
||||||
|
this.createdAt,
|
||||||
|
this.updatedAt,
|
||||||
this.firstName,
|
this.firstName,
|
||||||
this.lastName,
|
this.lastName,
|
||||||
this.salary,
|
this.salary});
|
||||||
this.createdAt,
|
|
||||||
this.updatedAt});
|
/// A unique identifier corresponding to this item.
|
||||||
|
@override
|
||||||
|
String? id;
|
||||||
|
|
||||||
|
/// The time at which this item was created.
|
||||||
|
@override
|
||||||
|
DateTime? createdAt;
|
||||||
|
|
||||||
|
/// The last time at which this item was updated.
|
||||||
|
@override
|
||||||
|
DateTime? updatedAt;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
final String? id;
|
String? firstName;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
final String? firstName;
|
String? lastName;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
final String? lastName;
|
double? salary;
|
||||||
|
|
||||||
@override
|
|
||||||
final double? salary;
|
|
||||||
|
|
||||||
@override
|
|
||||||
final DateTime? createdAt;
|
|
||||||
|
|
||||||
@override
|
|
||||||
final DateTime? updatedAt;
|
|
||||||
|
|
||||||
Employee copyWith(
|
Employee copyWith(
|
||||||
{String? id,
|
{String? id,
|
||||||
|
DateTime? createdAt,
|
||||||
|
DateTime? updatedAt,
|
||||||
String? firstName,
|
String? firstName,
|
||||||
String? lastName,
|
String? lastName,
|
||||||
double? salary,
|
double? salary}) {
|
||||||
DateTime? createdAt,
|
|
||||||
DateTime? updatedAt}) {
|
|
||||||
return Employee(
|
return Employee(
|
||||||
id: id ?? this.id,
|
id: id ?? this.id,
|
||||||
|
createdAt: createdAt ?? this.createdAt,
|
||||||
|
updatedAt: updatedAt ?? this.updatedAt,
|
||||||
firstName: firstName ?? this.firstName,
|
firstName: firstName ?? this.firstName,
|
||||||
lastName: lastName ?? this.lastName,
|
lastName: lastName ?? this.lastName,
|
||||||
salary: salary ?? this.salary,
|
salary: salary ?? this.salary);
|
||||||
createdAt: createdAt ?? this.createdAt,
|
|
||||||
updatedAt: updatedAt ?? this.updatedAt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool operator ==(other) {
|
bool operator ==(other) {
|
||||||
return other is _Employee &&
|
return other is _Employee &&
|
||||||
other.id == id &&
|
other.id == id &&
|
||||||
|
other.createdAt == createdAt &&
|
||||||
|
other.updatedAt == updatedAt &&
|
||||||
other.firstName == firstName &&
|
other.firstName == firstName &&
|
||||||
other.lastName == lastName &&
|
other.lastName == lastName &&
|
||||||
other.salary == salary &&
|
other.salary == salary;
|
||||||
other.createdAt == createdAt &&
|
|
||||||
other.updatedAt == updatedAt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get hashCode {
|
int get hashCode {
|
||||||
return hashObjects([id, firstName, lastName, salary, createdAt, updatedAt]);
|
return hashObjects([id, createdAt, updatedAt, firstName, lastName, salary]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'Employee(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, firstName=$firstName, lastName=$lastName, salary=$salary)';
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
return EmployeeSerializer.toMap(this);
|
return EmployeeSerializer.toMap(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// SerializerGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
const EmployeeSerializer employeeSerializer = EmployeeSerializer();
|
||||||
|
|
||||||
|
class EmployeeEncoder extends Converter<Employee, Map> {
|
||||||
|
const EmployeeEncoder();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Map convert(Employee model) => EmployeeSerializer.toMap(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
class EmployeeDecoder extends Converter<Map, Employee> {
|
||||||
|
const EmployeeDecoder();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Employee convert(Map map) => EmployeeSerializer.fromMap(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
class EmployeeSerializer extends Codec<Employee, Map> {
|
||||||
|
const EmployeeSerializer();
|
||||||
|
|
||||||
|
@override
|
||||||
|
EmployeeEncoder get encoder => const EmployeeEncoder();
|
||||||
|
@override
|
||||||
|
EmployeeDecoder get decoder => const EmployeeDecoder();
|
||||||
|
static Employee fromMap(Map map) {
|
||||||
|
return Employee(
|
||||||
|
id: map['id'] as String?,
|
||||||
|
createdAt: map['created_at'] != null
|
||||||
|
? (map['created_at'] is DateTime
|
||||||
|
? (map['created_at'] as DateTime)
|
||||||
|
: DateTime.parse(map['created_at'].toString()))
|
||||||
|
: null,
|
||||||
|
updatedAt: map['updated_at'] != null
|
||||||
|
? (map['updated_at'] is DateTime
|
||||||
|
? (map['updated_at'] as DateTime)
|
||||||
|
: DateTime.parse(map['updated_at'].toString()))
|
||||||
|
: null,
|
||||||
|
firstName: map['first_name'] as String?,
|
||||||
|
lastName: map['last_name'] as String?,
|
||||||
|
salary: map['salary'] as double?);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Map<String, dynamic> toMap(_Employee? model) {
|
||||||
|
if (model == null) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
'id': model.id,
|
||||||
|
'created_at': model.createdAt?.toIso8601String(),
|
||||||
|
'updated_at': model.updatedAt?.toIso8601String(),
|
||||||
|
'first_name': model.firstName,
|
||||||
|
'last_name': model.lastName,
|
||||||
|
'salary': model.salary
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class EmployeeFields {
|
||||||
|
static const List<String> allFields = <String>[
|
||||||
|
id,
|
||||||
|
createdAt,
|
||||||
|
updatedAt,
|
||||||
|
firstName,
|
||||||
|
lastName,
|
||||||
|
salary
|
||||||
|
];
|
||||||
|
|
||||||
|
static const String id = 'id';
|
||||||
|
|
||||||
|
static const String createdAt = 'created_at';
|
||||||
|
|
||||||
|
static const String updatedAt = 'updated_at';
|
||||||
|
|
||||||
|
static const String firstName = 'first_name';
|
||||||
|
|
||||||
|
static const String lastName = 'last_name';
|
||||||
|
|
||||||
|
static const String salary = 'salary';
|
||||||
|
}
|
||||||
|
|
|
@ -1,61 +0,0 @@
|
||||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
|
||||||
|
|
||||||
part of 'main.dart';
|
|
||||||
|
|
||||||
// **************************************************************************
|
|
||||||
// SerializerGenerator
|
|
||||||
// **************************************************************************
|
|
||||||
|
|
||||||
abstract class EmployeeSerializer {
|
|
||||||
static Employee fromMap(Map map) {
|
|
||||||
return Employee(
|
|
||||||
id: map['id'] as String?,
|
|
||||||
firstName: map['first_name'] as String?,
|
|
||||||
lastName: map['last_name'] as String?,
|
|
||||||
salary: map['salary'] as double?,
|
|
||||||
createdAt: map['created_at'] != null
|
|
||||||
? (map['created_at'] is DateTime
|
|
||||||
? (map['created_at'] as DateTime?)
|
|
||||||
: DateTime.parse(map['created_at'].toString()))
|
|
||||||
: null,
|
|
||||||
updatedAt: map['updated_at'] != null
|
|
||||||
? (map['updated_at'] is DateTime
|
|
||||||
? (map['updated_at'] as DateTime?)
|
|
||||||
: DateTime.parse(map['updated_at'].toString()))
|
|
||||||
: null);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Map<String, dynamic> toMap(Employee model) {
|
|
||||||
return {
|
|
||||||
'id': model.id,
|
|
||||||
'first_name': model.firstName,
|
|
||||||
'last_name': model.lastName,
|
|
||||||
'salary': model.salary,
|
|
||||||
'created_at': model.createdAt?.toIso8601String(),
|
|
||||||
'updated_at': model.updatedAt?.toIso8601String()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class EmployeeFields {
|
|
||||||
static const List<String> allFields = <String>[
|
|
||||||
id,
|
|
||||||
firstName,
|
|
||||||
lastName,
|
|
||||||
salary,
|
|
||||||
createdAt,
|
|
||||||
updatedAt
|
|
||||||
];
|
|
||||||
|
|
||||||
static const String id = 'id';
|
|
||||||
|
|
||||||
static const String firstName = 'first_name';
|
|
||||||
|
|
||||||
static const String lastName = 'last_name';
|
|
||||||
|
|
||||||
static const String salary = 'salary';
|
|
||||||
|
|
||||||
static const String createdAt = 'created_at';
|
|
||||||
|
|
||||||
static const String updatedAt = 'updated_at';
|
|
||||||
}
|
|
|
@ -167,6 +167,7 @@ abstract class Query<T, Where extends QueryWhere> extends QueryBase<T> {
|
||||||
void _makeJoin(
|
void _makeJoin(
|
||||||
tableName,
|
tableName,
|
||||||
Set<String>? trampoline,
|
Set<String>? trampoline,
|
||||||
|
String? alias,
|
||||||
JoinType type,
|
JoinType type,
|
||||||
String localKey,
|
String localKey,
|
||||||
String foreignKey,
|
String foreignKey,
|
||||||
|
@ -182,7 +183,7 @@ abstract class Query<T, Where extends QueryWhere> extends QueryBase<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
var to = _compileJoin(tableName, trampoline);
|
var to = _compileJoin(tableName, trampoline);
|
||||||
var alias = _joinAlias(trampoline);
|
alias ??= _joinAlias(trampoline);
|
||||||
if (tableName is Query) {
|
if (tableName is Query) {
|
||||||
for (var field in tableName.fields) {
|
for (var field in tableName.fields) {
|
||||||
tableName.aliases[field] = '${alias}_$field';
|
tableName.aliases[field] = '${alias}_$field';
|
||||||
|
@ -199,8 +200,9 @@ abstract class Query<T, Where extends QueryWhere> extends QueryBase<T> {
|
||||||
void join(tableName, String localKey, String foreignKey,
|
void join(tableName, String localKey, String foreignKey,
|
||||||
{String op = '=',
|
{String op = '=',
|
||||||
List<String> additionalFields = const [],
|
List<String> additionalFields = const [],
|
||||||
Set<String>? trampoline}) {
|
Set<String>? trampoline,
|
||||||
_makeJoin(tableName, trampoline, JoinType.inner, localKey, foreignKey, op,
|
String? alias}) {
|
||||||
|
_makeJoin(tableName, trampoline, alias, JoinType.inner, localKey, foreignKey, op,
|
||||||
additionalFields);
|
additionalFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,8 +210,9 @@ abstract class Query<T, Where extends QueryWhere> extends QueryBase<T> {
|
||||||
void leftJoin(tableName, String localKey, String foreignKey,
|
void leftJoin(tableName, String localKey, String foreignKey,
|
||||||
{String op = '=',
|
{String op = '=',
|
||||||
List<String> additionalFields = const [],
|
List<String> additionalFields = const [],
|
||||||
Set<String>? trampoline}) {
|
Set<String>? trampoline,
|
||||||
_makeJoin(tableName, trampoline, JoinType.left, localKey, foreignKey, op,
|
String? alias}) {
|
||||||
|
_makeJoin(tableName, trampoline, alias, JoinType.left, localKey, foreignKey, op,
|
||||||
additionalFields);
|
additionalFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,8 +220,9 @@ abstract class Query<T, Where extends QueryWhere> extends QueryBase<T> {
|
||||||
void rightJoin(tableName, String localKey, String foreignKey,
|
void rightJoin(tableName, String localKey, String foreignKey,
|
||||||
{String op = '=',
|
{String op = '=',
|
||||||
List<String> additionalFields = const [],
|
List<String> additionalFields = const [],
|
||||||
Set<String>? trampoline}) {
|
Set<String>? trampoline,
|
||||||
_makeJoin(tableName, trampoline, JoinType.right, localKey, foreignKey, op,
|
String? alias}) {
|
||||||
|
_makeJoin(tableName, trampoline, alias, JoinType.right, localKey, foreignKey, op,
|
||||||
additionalFields);
|
additionalFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,8 +230,9 @@ abstract class Query<T, Where extends QueryWhere> extends QueryBase<T> {
|
||||||
void fullOuterJoin(tableName, String localKey, String foreignKey,
|
void fullOuterJoin(tableName, String localKey, String foreignKey,
|
||||||
{String op = '=',
|
{String op = '=',
|
||||||
List<String> additionalFields = const [],
|
List<String> additionalFields = const [],
|
||||||
Set<String>? trampoline}) {
|
Set<String>? trampoline,
|
||||||
_makeJoin(tableName, trampoline, JoinType.full, localKey, foreignKey, op,
|
String? alias}) {
|
||||||
|
_makeJoin(tableName, trampoline, alias, JoinType.full, localKey, foreignKey, op,
|
||||||
additionalFields);
|
additionalFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,8 +240,9 @@ abstract class Query<T, Where extends QueryWhere> extends QueryBase<T> {
|
||||||
void selfJoin(tableName, String localKey, String foreignKey,
|
void selfJoin(tableName, String localKey, String foreignKey,
|
||||||
{String op = '=',
|
{String op = '=',
|
||||||
List<String> additionalFields = const [],
|
List<String> additionalFields = const [],
|
||||||
Set<String>? trampoline}) {
|
Set<String>? trampoline,
|
||||||
_makeJoin(tableName, trampoline, JoinType.self, localKey, foreignKey, op,
|
String? alias}) {
|
||||||
|
_makeJoin(tableName, trampoline, alias, JoinType.self, localKey, foreignKey, op,
|
||||||
additionalFields);
|
additionalFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ abstract class QueryWhere {
|
||||||
final Set<QueryWhere> _and = {};
|
final Set<QueryWhere> _and = {};
|
||||||
final Set<QueryWhere> _not = {};
|
final Set<QueryWhere> _not = {};
|
||||||
final Set<QueryWhere> _or = {};
|
final Set<QueryWhere> _or = {};
|
||||||
|
final Set<String> _raw = {};
|
||||||
|
|
||||||
Iterable<SqlExpressionBuilder> get expressionBuilders;
|
Iterable<SqlExpressionBuilder> get expressionBuilders;
|
||||||
|
|
||||||
|
@ -20,6 +21,10 @@ abstract class QueryWhere {
|
||||||
_or.add(other);
|
_or.add(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void raw(String whereRaw) {
|
||||||
|
_raw.add(whereRaw);
|
||||||
|
}
|
||||||
|
|
||||||
String compile({String? tableName}) {
|
String compile({String? tableName}) {
|
||||||
var b = StringBuffer();
|
var b = StringBuffer();
|
||||||
var i = 0;
|
var i = 0;
|
||||||
|
@ -39,6 +44,11 @@ abstract class QueryWhere {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (var raw in _raw) {
|
||||||
|
if (i++ > 0) b.write(' AND ');
|
||||||
|
b.write(' ($raw)');
|
||||||
|
}
|
||||||
|
|
||||||
for (var other in _and) {
|
for (var other in _and) {
|
||||||
var sql = other.compile();
|
var sql = other.compile();
|
||||||
if (sql.isNotEmpty) b.write(' AND ($sql)');
|
if (sql.isNotEmpty) b.write(' AND ($sql)');
|
||||||
|
|
|
@ -31,5 +31,6 @@ void main() {
|
||||||
() =>
|
() =>
|
||||||
manyToManyTests(pg(['user', 'role', 'user_role']), close: closePg));
|
manyToManyTests(pg(['user', 'role', 'user_role']), close: closePg));
|
||||||
group('standalone', () => standaloneTests(pg(['car']), close: closePg));
|
group('standalone', () => standaloneTests(pg(['car']), close: closePg));
|
||||||
|
group('join', () => joinTests(pg(['person', 'person_order']), close: closePg));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
CREATE TEMPORARY TABLE "persons" (
|
||||||
|
"id" serial PRIMARY KEY,
|
||||||
|
"name" varchar(255),
|
||||||
|
"age" int,
|
||||||
|
"created_at" timestamp,
|
||||||
|
"updated_at" timestamp
|
||||||
|
);
|
|
@ -0,0 +1,9 @@
|
||||||
|
CREATE TEMPORARY TABLE "person_orders" (
|
||||||
|
"id" serial PRIMARY KEY,
|
||||||
|
"person_id" int not null,
|
||||||
|
"name" varchar(255),
|
||||||
|
"price" int,
|
||||||
|
"deleted" bool not null default false,
|
||||||
|
"created_at" timestamp,
|
||||||
|
"updated_at" timestamp
|
||||||
|
);
|
|
@ -8,3 +8,4 @@ export 'src/has_one_test.dart';
|
||||||
export 'src/many_to_many_test.dart';
|
export 'src/many_to_many_test.dart';
|
||||||
export 'src/standalone_test.dart';
|
export 'src/standalone_test.dart';
|
||||||
export 'src/performance_test.dart';
|
export 'src/performance_test.dart';
|
||||||
|
export 'src/join_test.dart';
|
||||||
|
|
81
packages/orm/angel_orm_test/lib/src/join_test.dart
Normal file
81
packages/orm/angel_orm_test/lib/src/join_test.dart
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
import 'dart:async';
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
|
import 'package:angel3_orm/angel3_orm.dart';
|
||||||
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
|
import 'models/person.dart';
|
||||||
|
import 'models/person_order.dart';
|
||||||
|
|
||||||
|
void joinTests(FutureOr<QueryExecutor> Function() createExecutor,
|
||||||
|
{FutureOr<void> Function(QueryExecutor)? close}) {
|
||||||
|
late QueryExecutor executor;
|
||||||
|
Person? originalPerson;
|
||||||
|
PersonOrder? originalOrder1;
|
||||||
|
PersonOrder? originalOrder2;
|
||||||
|
close ??= (_) => null;
|
||||||
|
|
||||||
|
setUp(() async {
|
||||||
|
executor = await createExecutor();
|
||||||
|
var query = PersonQuery()
|
||||||
|
..values.name = 'DebuggerX'
|
||||||
|
..values.age = 29;
|
||||||
|
originalPerson = (await query.insert(executor)).value;
|
||||||
|
|
||||||
|
var orderQuery = PersonOrderQuery()
|
||||||
|
..values.personId = originalPerson!.idAsInt
|
||||||
|
..values.name = 'Order1'
|
||||||
|
..values.price = 128
|
||||||
|
..values.deleted = false;
|
||||||
|
|
||||||
|
originalOrder1 = (await orderQuery.insert(executor)).value;
|
||||||
|
|
||||||
|
orderQuery = PersonOrderQuery()
|
||||||
|
..values.personId = originalPerson!.idAsInt
|
||||||
|
..values.name = 'Order2'
|
||||||
|
..values.price = 256
|
||||||
|
..values.deleted = true;
|
||||||
|
|
||||||
|
originalOrder2 = (await orderQuery.insert(executor)).value;
|
||||||
|
});
|
||||||
|
|
||||||
|
tearDown(() => close!(executor));
|
||||||
|
|
||||||
|
test('select person with last order info', () async {
|
||||||
|
var orderQuery = PersonOrderQuery();
|
||||||
|
var query = PersonWithLastOrderQuery();
|
||||||
|
query.join(
|
||||||
|
orderQuery.tableName, PersonFields.id, PersonOrderFields.personId,
|
||||||
|
alias: 'po');
|
||||||
|
query.where?.name.equals(originalPerson!.name!);
|
||||||
|
query.orderBy('po.id', descending: true);
|
||||||
|
var personWithOrderInfo = await query.getOne(executor);
|
||||||
|
expect(personWithOrderInfo.value.lastOrderName, originalOrder2?.name);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('select person with last valid order info', () async {
|
||||||
|
var orderQuery = PersonOrderQuery();
|
||||||
|
var query = PersonWithLastOrderQuery();
|
||||||
|
query.join(
|
||||||
|
orderQuery.tableName, PersonFields.id, PersonOrderFields.personId,
|
||||||
|
alias: 'po');
|
||||||
|
query.where?.name.equals(originalPerson!.name!);
|
||||||
|
query.orderBy('po.id', descending: true);
|
||||||
|
query.where?.raw('po.deleted = false');
|
||||||
|
var personWithOrderInfo = await query.getOne(executor);
|
||||||
|
expect(personWithOrderInfo.value.lastOrderName, originalOrder1?.name);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('select orders with person info', () async {
|
||||||
|
var personQuery = PersonQuery();
|
||||||
|
var query = OrderWithPersonInfoQuery();
|
||||||
|
query.join(
|
||||||
|
personQuery.tableName, PersonOrderFields.personId, PersonFields.id,
|
||||||
|
alias: 'P');
|
||||||
|
query.where?.raw("P.name = '${originalPerson?.name}'");
|
||||||
|
var orders = await query.get(executor);
|
||||||
|
expect(orders.every((element) =>
|
||||||
|
element.personName == originalPerson?.name &&
|
||||||
|
element.personAge == originalPerson?.age), true);
|
||||||
|
});
|
||||||
|
}
|
|
@ -68,8 +68,6 @@ class BookQuery extends Query<Book, BookQueryWhere> {
|
||||||
@override
|
@override
|
||||||
final BookQueryValues values = BookQueryValues();
|
final BookQueryValues values = BookQueryValues();
|
||||||
|
|
||||||
List<String> _selectedFields = [];
|
|
||||||
|
|
||||||
BookQueryWhere? _where;
|
BookQueryWhere? _where;
|
||||||
|
|
||||||
late AuthorQuery _author;
|
late AuthorQuery _author;
|
||||||
|
@ -88,7 +86,7 @@ class BookQuery extends Query<Book, BookQueryWhere> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<String> get fields {
|
List<String> get fields {
|
||||||
const _fields = [
|
return const [
|
||||||
'id',
|
'id',
|
||||||
'created_at',
|
'created_at',
|
||||||
'updated_at',
|
'updated_at',
|
||||||
|
@ -96,14 +94,6 @@ class BookQuery extends Query<Book, BookQueryWhere> {
|
||||||
'partner_author_id',
|
'partner_author_id',
|
||||||
'name'
|
'name'
|
||||||
];
|
];
|
||||||
return _selectedFields.isEmpty
|
|
||||||
? _fields
|
|
||||||
: _fields.where((field) => _selectedFields.contains(field)).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
BookQuery select(List<String> selectedFields) {
|
|
||||||
_selectedFields = selectedFields;
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -116,23 +106,23 @@ class BookQuery extends Query<Book, BookQueryWhere> {
|
||||||
return BookQueryWhere(this);
|
return BookQueryWhere(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Book> parseRow(List row) {
|
static Optional<Book> parseRow(List row) {
|
||||||
if (row.every((x) => x == null)) {
|
if (row.every((x) => x == null)) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
var model = Book(
|
var model = Book(
|
||||||
id: fields.contains('id') ? row[0].toString() : null,
|
id: row[0].toString(),
|
||||||
createdAt: fields.contains('created_at') ? (row[1] as DateTime?) : null,
|
createdAt: (row[1] as DateTime?),
|
||||||
updatedAt: fields.contains('updated_at') ? (row[2] as DateTime?) : null,
|
updatedAt: (row[2] as DateTime?),
|
||||||
name: fields.contains('name') ? (row[5] as String?) : null);
|
name: (row[5] as String?));
|
||||||
if (row.length > 6) {
|
if (row.length > 6) {
|
||||||
var modelOpt = AuthorQuery().parseRow(row.skip(6).take(4).toList());
|
var modelOpt = AuthorQuery.parseRow(row.skip(6).take(4).toList());
|
||||||
modelOpt.ifPresent((m) {
|
modelOpt.ifPresent((m) {
|
||||||
model = model.copyWith(author: m);
|
model = model.copyWith(author: m);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (row.length > 10) {
|
if (row.length > 10) {
|
||||||
var modelOpt = AuthorQuery().parseRow(row.skip(10).take(4).toList());
|
var modelOpt = AuthorQuery.parseRow(row.skip(10).take(4).toList());
|
||||||
modelOpt.ifPresent((m) {
|
modelOpt.ifPresent((m) {
|
||||||
model = model.copyWith(partnerAuthor: m);
|
model = model.copyWith(partnerAuthor: m);
|
||||||
});
|
});
|
||||||
|
@ -242,8 +232,6 @@ class AuthorQuery extends Query<Author, AuthorQueryWhere> {
|
||||||
@override
|
@override
|
||||||
final AuthorQueryValues values = AuthorQueryValues();
|
final AuthorQueryValues values = AuthorQueryValues();
|
||||||
|
|
||||||
List<String> _selectedFields = [];
|
|
||||||
|
|
||||||
AuthorQueryWhere? _where;
|
AuthorQueryWhere? _where;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -258,15 +246,7 @@ class AuthorQuery extends Query<Author, AuthorQueryWhere> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<String> get fields {
|
List<String> get fields {
|
||||||
const _fields = ['id', 'created_at', 'updated_at', 'name'];
|
return const ['id', 'created_at', 'updated_at', 'name'];
|
||||||
return _selectedFields.isEmpty
|
|
||||||
? _fields
|
|
||||||
: _fields.where((field) => _selectedFields.contains(field)).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
AuthorQuery select(List<String> selectedFields) {
|
|
||||||
_selectedFields = selectedFields;
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -279,15 +259,15 @@ class AuthorQuery extends Query<Author, AuthorQueryWhere> {
|
||||||
return AuthorQueryWhere(this);
|
return AuthorQueryWhere(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Author> parseRow(List row) {
|
static Optional<Author> parseRow(List row) {
|
||||||
if (row.every((x) => x == null)) {
|
if (row.every((x) => x == null)) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
var model = Author(
|
var model = Author(
|
||||||
id: fields.contains('id') ? row[0].toString() : null,
|
id: row[0].toString(),
|
||||||
createdAt: fields.contains('created_at') ? (row[1] as DateTime?) : null,
|
createdAt: (row[1] as DateTime?),
|
||||||
updatedAt: fields.contains('updated_at') ? (row[2] as DateTime?) : null,
|
updatedAt: (row[2] as DateTime?),
|
||||||
name: fields.contains('name') ? (row[3] as String?) : null);
|
name: (row[3] as String?));
|
||||||
return Optional.of(model);
|
return Optional.of(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,8 +40,6 @@ class CarQuery extends Query<Car, CarQueryWhere> {
|
||||||
@override
|
@override
|
||||||
final CarQueryValues values = CarQueryValues();
|
final CarQueryValues values = CarQueryValues();
|
||||||
|
|
||||||
List<String> _selectedFields = [];
|
|
||||||
|
|
||||||
CarQueryWhere? _where;
|
CarQueryWhere? _where;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -56,7 +54,7 @@ class CarQuery extends Query<Car, CarQueryWhere> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<String> get fields {
|
List<String> get fields {
|
||||||
const _fields = [
|
return const [
|
||||||
'id',
|
'id',
|
||||||
'created_at',
|
'created_at',
|
||||||
'updated_at',
|
'updated_at',
|
||||||
|
@ -65,14 +63,6 @@ class CarQuery extends Query<Car, CarQueryWhere> {
|
||||||
'family_friendly',
|
'family_friendly',
|
||||||
'recalled_at'
|
'recalled_at'
|
||||||
];
|
];
|
||||||
return _selectedFields.isEmpty
|
|
||||||
? _fields
|
|
||||||
: _fields.where((field) => _selectedFields.contains(field)).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
CarQuery select(List<String> selectedFields) {
|
|
||||||
_selectedFields = selectedFields;
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -85,21 +75,18 @@ class CarQuery extends Query<Car, CarQueryWhere> {
|
||||||
return CarQueryWhere(this);
|
return CarQueryWhere(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Car> parseRow(List row) {
|
static Optional<Car> parseRow(List row) {
|
||||||
if (row.every((x) => x == null)) {
|
if (row.every((x) => x == null)) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
var model = Car(
|
var model = Car(
|
||||||
id: fields.contains('id') ? row[0].toString() : null,
|
id: row[0].toString(),
|
||||||
createdAt: fields.contains('created_at') ? (row[1] as DateTime?) : null,
|
createdAt: (row[1] as DateTime?),
|
||||||
updatedAt: fields.contains('updated_at') ? (row[2] as DateTime?) : null,
|
updatedAt: (row[2] as DateTime?),
|
||||||
make: fields.contains('make') ? (row[3] as String?) : null,
|
make: (row[3] as String?),
|
||||||
description:
|
description: (row[4] as String?),
|
||||||
fields.contains('description') ? (row[4] as String?) : null,
|
familyFriendly: (row[5] as bool?),
|
||||||
familyFriendly:
|
recalledAt: (row[6] as DateTime?));
|
||||||
fields.contains('family_friendly') ? (row[5] as bool?) : null,
|
|
||||||
recalledAt:
|
|
||||||
fields.contains('recalled_at') ? (row[6] as DateTime?) : null);
|
|
||||||
return Optional.of(model);
|
return Optional.of(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,8 +58,6 @@ class NumbersQuery extends Query<Numbers, NumbersQueryWhere> {
|
||||||
@override
|
@override
|
||||||
final NumbersQueryValues values = NumbersQueryValues();
|
final NumbersQueryValues values = NumbersQueryValues();
|
||||||
|
|
||||||
List<String> _selectedFields = [];
|
|
||||||
|
|
||||||
NumbersQueryWhere? _where;
|
NumbersQueryWhere? _where;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -74,15 +72,7 @@ class NumbersQuery extends Query<Numbers, NumbersQueryWhere> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<String> get fields {
|
List<String> get fields {
|
||||||
const _fields = ['id', 'created_at', 'updated_at', 'two'];
|
return const ['id', 'created_at', 'updated_at', 'two'];
|
||||||
return _selectedFields.isEmpty
|
|
||||||
? _fields
|
|
||||||
: _fields.where((field) => _selectedFields.contains(field)).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
NumbersQuery select(List<String> selectedFields) {
|
|
||||||
_selectedFields = selectedFields;
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -95,15 +85,15 @@ class NumbersQuery extends Query<Numbers, NumbersQueryWhere> {
|
||||||
return NumbersQueryWhere(this);
|
return NumbersQueryWhere(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Numbers> parseRow(List row) {
|
static Optional<Numbers> parseRow(List row) {
|
||||||
if (row.every((x) => x == null)) {
|
if (row.every((x) => x == null)) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
var model = Numbers(
|
var model = Numbers(
|
||||||
id: fields.contains('id') ? row[0].toString() : null,
|
id: row[0].toString(),
|
||||||
createdAt: fields.contains('created_at') ? (row[1] as DateTime?) : null,
|
createdAt: (row[1] as DateTime?),
|
||||||
updatedAt: fields.contains('updated_at') ? (row[2] as DateTime?) : null,
|
updatedAt: (row[2] as DateTime?),
|
||||||
two: fields.contains('two') ? (row[3] as int?) : null);
|
two: (row[3] as int?));
|
||||||
return Optional.of(model);
|
return Optional.of(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,8 +163,6 @@ class AlphabetQuery extends Query<Alphabet, AlphabetQueryWhere> {
|
||||||
@override
|
@override
|
||||||
final AlphabetQueryValues values = AlphabetQueryValues();
|
final AlphabetQueryValues values = AlphabetQueryValues();
|
||||||
|
|
||||||
List<String> _selectedFields = [];
|
|
||||||
|
|
||||||
AlphabetQueryWhere? _where;
|
AlphabetQueryWhere? _where;
|
||||||
|
|
||||||
late NumbersQuery _numbers;
|
late NumbersQuery _numbers;
|
||||||
|
@ -191,15 +179,7 @@ class AlphabetQuery extends Query<Alphabet, AlphabetQueryWhere> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<String> get fields {
|
List<String> get fields {
|
||||||
const _fields = ['id', 'created_at', 'updated_at', 'value', 'numbers_id'];
|
return const ['id', 'created_at', 'updated_at', 'value', 'numbers_id'];
|
||||||
return _selectedFields.isEmpty
|
|
||||||
? _fields
|
|
||||||
: _fields.where((field) => _selectedFields.contains(field)).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
AlphabetQuery select(List<String> selectedFields) {
|
|
||||||
_selectedFields = selectedFields;
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -212,17 +192,17 @@ class AlphabetQuery extends Query<Alphabet, AlphabetQueryWhere> {
|
||||||
return AlphabetQueryWhere(this);
|
return AlphabetQueryWhere(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Alphabet> parseRow(List row) {
|
static Optional<Alphabet> parseRow(List row) {
|
||||||
if (row.every((x) => x == null)) {
|
if (row.every((x) => x == null)) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
var model = Alphabet(
|
var model = Alphabet(
|
||||||
id: fields.contains('id') ? row[0].toString() : null,
|
id: row[0].toString(),
|
||||||
createdAt: fields.contains('created_at') ? (row[1] as DateTime?) : null,
|
createdAt: (row[1] as DateTime?),
|
||||||
updatedAt: fields.contains('updated_at') ? (row[2] as DateTime?) : null,
|
updatedAt: (row[2] as DateTime?),
|
||||||
value: fields.contains('value') ? (row[3] as String?) : null);
|
value: (row[3] as String?));
|
||||||
if (row.length > 5) {
|
if (row.length > 5) {
|
||||||
var modelOpt = NumbersQuery().parseRow(row.skip(5).take(4).toList());
|
var modelOpt = NumbersQuery.parseRow(row.skip(5).take(4).toList());
|
||||||
modelOpt.ifPresent((m) {
|
modelOpt.ifPresent((m) {
|
||||||
model = model.copyWith(numbers: m);
|
model = model.copyWith(numbers: m);
|
||||||
});
|
});
|
||||||
|
|
|
@ -75,8 +75,6 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
|
||||||
@override
|
@override
|
||||||
final RoleQueryValues values = RoleQueryValues();
|
final RoleQueryValues values = RoleQueryValues();
|
||||||
|
|
||||||
List<String> _selectedFields = [];
|
|
||||||
|
|
||||||
RoleQueryWhere? _where;
|
RoleQueryWhere? _where;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -91,15 +89,7 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<String> get fields {
|
List<String> get fields {
|
||||||
const _fields = ['role'];
|
return const ['role'];
|
||||||
return _selectedFields.isEmpty
|
|
||||||
? _fields
|
|
||||||
: _fields.where((field) => _selectedFields.contains(field)).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
RoleQuery select(List<String> selectedFields) {
|
|
||||||
_selectedFields = selectedFields;
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -112,14 +102,13 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
|
||||||
return RoleQueryWhere(this);
|
return RoleQueryWhere(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Role> parseRow(List row) {
|
static Optional<Role> parseRow(List row) {
|
||||||
if (row.every((x) => x == null)) {
|
if (row.every((x) => x == null)) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
var model =
|
var model = Role(role: (row[0] as String?));
|
||||||
Role(role: fields.contains('role') ? (row[0] as String?) : null);
|
|
||||||
if (row.length > 1) {
|
if (row.length > 1) {
|
||||||
var modelOpt = UserQuery().parseRow(row.skip(1).take(3).toList());
|
var modelOpt = UserQuery.parseRow(row.skip(1).take(3).toList());
|
||||||
modelOpt.ifPresent((m) {
|
modelOpt.ifPresent((m) {
|
||||||
model = model.copyWith(users: [m]);
|
model = model.copyWith(users: [m]);
|
||||||
});
|
});
|
||||||
|
@ -239,8 +228,6 @@ class RoleUserQuery extends Query<RoleUser, RoleUserQueryWhere> {
|
||||||
@override
|
@override
|
||||||
final RoleUserQueryValues values = RoleUserQueryValues();
|
final RoleUserQueryValues values = RoleUserQueryValues();
|
||||||
|
|
||||||
List<String> _selectedFields = [];
|
|
||||||
|
|
||||||
RoleUserQueryWhere? _where;
|
RoleUserQueryWhere? _where;
|
||||||
|
|
||||||
late RoleQuery _role;
|
late RoleQuery _role;
|
||||||
|
@ -259,15 +246,7 @@ class RoleUserQuery extends Query<RoleUser, RoleUserQueryWhere> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<String> get fields {
|
List<String> get fields {
|
||||||
const _fields = ['role_role', 'user_email'];
|
return const ['role_role', 'user_email'];
|
||||||
return _selectedFields.isEmpty
|
|
||||||
? _fields
|
|
||||||
: _fields.where((field) => _selectedFields.contains(field)).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
RoleUserQuery select(List<String> selectedFields) {
|
|
||||||
_selectedFields = selectedFields;
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -280,19 +259,19 @@ class RoleUserQuery extends Query<RoleUser, RoleUserQueryWhere> {
|
||||||
return RoleUserQueryWhere(this);
|
return RoleUserQueryWhere(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<RoleUser> parseRow(List row) {
|
static Optional<RoleUser> parseRow(List row) {
|
||||||
if (row.every((x) => x == null)) {
|
if (row.every((x) => x == null)) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
var model = RoleUser();
|
var model = RoleUser();
|
||||||
if (row.length > 2) {
|
if (row.length > 2) {
|
||||||
var modelOpt = RoleQuery().parseRow(row.skip(2).take(1).toList());
|
var modelOpt = RoleQuery.parseRow(row.skip(2).take(1).toList());
|
||||||
modelOpt.ifPresent((m) {
|
modelOpt.ifPresent((m) {
|
||||||
model = model.copyWith(role: m);
|
model = model.copyWith(role: m);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (row.length > 3) {
|
if (row.length > 3) {
|
||||||
var modelOpt = UserQuery().parseRow(row.skip(3).take(3).toList());
|
var modelOpt = UserQuery.parseRow(row.skip(3).take(3).toList());
|
||||||
modelOpt.ifPresent((m) {
|
modelOpt.ifPresent((m) {
|
||||||
model = model.copyWith(user: m);
|
model = model.copyWith(user: m);
|
||||||
});
|
});
|
||||||
|
@ -371,8 +350,6 @@ class UserQuery extends Query<User, UserQueryWhere> {
|
||||||
@override
|
@override
|
||||||
final UserQueryValues values = UserQueryValues();
|
final UserQueryValues values = UserQueryValues();
|
||||||
|
|
||||||
List<String> _selectedFields = [];
|
|
||||||
|
|
||||||
UserQueryWhere? _where;
|
UserQueryWhere? _where;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -387,15 +364,7 @@ class UserQuery extends Query<User, UserQueryWhere> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<String> get fields {
|
List<String> get fields {
|
||||||
const _fields = ['email', 'name', 'password'];
|
return const ['email', 'name', 'password'];
|
||||||
return _selectedFields.isEmpty
|
|
||||||
? _fields
|
|
||||||
: _fields.where((field) => _selectedFields.contains(field)).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
UserQuery select(List<String> selectedFields) {
|
|
||||||
_selectedFields = selectedFields;
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -408,16 +377,16 @@ class UserQuery extends Query<User, UserQueryWhere> {
|
||||||
return UserQueryWhere(this);
|
return UserQueryWhere(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<User> parseRow(List row) {
|
static Optional<User> parseRow(List row) {
|
||||||
if (row.every((x) => x == null)) {
|
if (row.every((x) => x == null)) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
var model = User(
|
var model = User(
|
||||||
email: fields.contains('email') ? (row[0] as String?) : null,
|
email: (row[0] as String?),
|
||||||
name: fields.contains('name') ? (row[1] as String?) : null,
|
name: (row[1] as String?),
|
||||||
password: fields.contains('password') ? (row[2] as String?) : null);
|
password: (row[2] as String?));
|
||||||
if (row.length > 3) {
|
if (row.length > 3) {
|
||||||
var modelOpt = RoleQuery().parseRow(row.skip(3).take(1).toList());
|
var modelOpt = RoleQuery.parseRow(row.skip(3).take(1).toList());
|
||||||
modelOpt.ifPresent((m) {
|
modelOpt.ifPresent((m) {
|
||||||
model = model.copyWith(roles: [m]);
|
model = model.copyWith(roles: [m]);
|
||||||
});
|
});
|
||||||
|
|
|
@ -36,8 +36,6 @@ class FortuneQuery extends Query<Fortune, FortuneQueryWhere> {
|
||||||
@override
|
@override
|
||||||
final FortuneQueryValues values = FortuneQueryValues();
|
final FortuneQueryValues values = FortuneQueryValues();
|
||||||
|
|
||||||
List<String> _selectedFields = [];
|
|
||||||
|
|
||||||
FortuneQueryWhere? _where;
|
FortuneQueryWhere? _where;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -52,15 +50,7 @@ class FortuneQuery extends Query<Fortune, FortuneQueryWhere> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<String> get fields {
|
List<String> get fields {
|
||||||
const _fields = ['id', 'message'];
|
return const ['id', 'message'];
|
||||||
return _selectedFields.isEmpty
|
|
||||||
? _fields
|
|
||||||
: _fields.where((field) => _selectedFields.contains(field)).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
FortuneQuery select(List<String> selectedFields) {
|
|
||||||
_selectedFields = selectedFields;
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -73,13 +63,11 @@ class FortuneQuery extends Query<Fortune, FortuneQueryWhere> {
|
||||||
return FortuneQueryWhere(this);
|
return FortuneQueryWhere(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Fortune> parseRow(List row) {
|
static Optional<Fortune> parseRow(List row) {
|
||||||
if (row.every((x) => x == null)) {
|
if (row.every((x) => x == null)) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
var model = Fortune(
|
var model = Fortune(id: (row[0] as int?), message: (row[1] as String?));
|
||||||
id: fields.contains('id') ? (row[0] as int?) : null,
|
|
||||||
message: fields.contains('message') ? (row[1] as String?) : null);
|
|
||||||
return Optional.of(model);
|
return Optional.of(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,8 +38,6 @@ class HasCarQuery extends Query<HasCar, HasCarQueryWhere> {
|
||||||
@override
|
@override
|
||||||
final HasCarQueryValues values = HasCarQueryValues();
|
final HasCarQueryValues values = HasCarQueryValues();
|
||||||
|
|
||||||
List<String> _selectedFields = [];
|
|
||||||
|
|
||||||
HasCarQueryWhere? _where;
|
HasCarQueryWhere? _where;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -54,15 +52,7 @@ class HasCarQuery extends Query<HasCar, HasCarQueryWhere> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<String> get fields {
|
List<String> get fields {
|
||||||
const _fields = ['id', 'created_at', 'updated_at', 'type'];
|
return const ['id', 'created_at', 'updated_at', 'type'];
|
||||||
return _selectedFields.isEmpty
|
|
||||||
? _fields
|
|
||||||
: _fields.where((field) => _selectedFields.contains(field)).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
HasCarQuery select(List<String> selectedFields) {
|
|
||||||
_selectedFields = selectedFields;
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -75,19 +65,15 @@ class HasCarQuery extends Query<HasCar, HasCarQueryWhere> {
|
||||||
return HasCarQueryWhere(this);
|
return HasCarQueryWhere(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<HasCar> parseRow(List row) {
|
static Optional<HasCar> parseRow(List row) {
|
||||||
if (row.every((x) => x == null)) {
|
if (row.every((x) => x == null)) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
var model = HasCar(
|
var model = HasCar(
|
||||||
id: fields.contains('id') ? row[0].toString() : null,
|
id: row[0].toString(),
|
||||||
createdAt: fields.contains('created_at') ? (row[1] as DateTime?) : null,
|
createdAt: (row[1] as DateTime?),
|
||||||
updatedAt: fields.contains('updated_at') ? (row[2] as DateTime?) : null,
|
updatedAt: (row[2] as DateTime?),
|
||||||
type: fields.contains('type')
|
type: row[3] == null ? null : CarType?.values[(row[3] as int)]);
|
||||||
? row[3] == null
|
|
||||||
? null
|
|
||||||
: CarType?.values[(row[3] as int)]
|
|
||||||
: null);
|
|
||||||
return Optional.of(model);
|
return Optional.of(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,8 +38,6 @@ class HasMapQuery extends Query<HasMap, HasMapQueryWhere> {
|
||||||
@override
|
@override
|
||||||
final HasMapQueryValues values = HasMapQueryValues();
|
final HasMapQueryValues values = HasMapQueryValues();
|
||||||
|
|
||||||
List<String> _selectedFields = [];
|
|
||||||
|
|
||||||
HasMapQueryWhere? _where;
|
HasMapQueryWhere? _where;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -54,15 +52,7 @@ class HasMapQuery extends Query<HasMap, HasMapQueryWhere> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<String> get fields {
|
List<String> get fields {
|
||||||
const _fields = ['value', 'list'];
|
return const ['value', 'list'];
|
||||||
return _selectedFields.isEmpty
|
|
||||||
? _fields
|
|
||||||
: _fields.where((field) => _selectedFields.contains(field)).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
HasMapQuery select(List<String> selectedFields) {
|
|
||||||
_selectedFields = selectedFields;
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -75,15 +65,13 @@ class HasMapQuery extends Query<HasMap, HasMapQueryWhere> {
|
||||||
return HasMapQueryWhere(this);
|
return HasMapQueryWhere(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<HasMap> parseRow(List row) {
|
static Optional<HasMap> parseRow(List row) {
|
||||||
if (row.every((x) => x == null)) {
|
if (row.every((x) => x == null)) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
var model = HasMap(
|
var model = HasMap(
|
||||||
value: fields.contains('value')
|
value: (row[0] as Map<dynamic, dynamic>?),
|
||||||
? (row[0] as Map<dynamic, dynamic>?)
|
list: (row[1] as List<dynamic>?));
|
||||||
: null,
|
|
||||||
list: fields.contains('list') ? (row[1] as List<dynamic>?) : null);
|
|
||||||
return Optional.of(model);
|
return Optional.of(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,8 +66,6 @@ class LegQuery extends Query<Leg, LegQueryWhere> {
|
||||||
@override
|
@override
|
||||||
final LegQueryValues values = LegQueryValues();
|
final LegQueryValues values = LegQueryValues();
|
||||||
|
|
||||||
List<String> _selectedFields = [];
|
|
||||||
|
|
||||||
LegQueryWhere? _where;
|
LegQueryWhere? _where;
|
||||||
|
|
||||||
late FootQuery _foot;
|
late FootQuery _foot;
|
||||||
|
@ -84,15 +82,7 @@ class LegQuery extends Query<Leg, LegQueryWhere> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<String> get fields {
|
List<String> get fields {
|
||||||
const _fields = ['id', 'created_at', 'updated_at', 'name'];
|
return const ['id', 'created_at', 'updated_at', 'name'];
|
||||||
return _selectedFields.isEmpty
|
|
||||||
? _fields
|
|
||||||
: _fields.where((field) => _selectedFields.contains(field)).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
LegQuery select(List<String> selectedFields) {
|
|
||||||
_selectedFields = selectedFields;
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -105,17 +95,17 @@ class LegQuery extends Query<Leg, LegQueryWhere> {
|
||||||
return LegQueryWhere(this);
|
return LegQueryWhere(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Leg> parseRow(List row) {
|
static Optional<Leg> parseRow(List row) {
|
||||||
if (row.every((x) => x == null)) {
|
if (row.every((x) => x == null)) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
var model = Leg(
|
var model = Leg(
|
||||||
id: fields.contains('id') ? row[0].toString() : null,
|
id: row[0].toString(),
|
||||||
createdAt: fields.contains('created_at') ? (row[1] as DateTime?) : null,
|
createdAt: (row[1] as DateTime?),
|
||||||
updatedAt: fields.contains('updated_at') ? (row[2] as DateTime?) : null,
|
updatedAt: (row[2] as DateTime?),
|
||||||
name: fields.contains('name') ? (row[3] as String?) : null);
|
name: (row[3] as String?));
|
||||||
if (row.length > 4) {
|
if (row.length > 4) {
|
||||||
var modelOpt = FootQuery().parseRow(row.skip(4).take(5).toList());
|
var modelOpt = FootQuery.parseRow(row.skip(4).take(5).toList());
|
||||||
modelOpt.ifPresent((m) {
|
modelOpt.ifPresent((m) {
|
||||||
model = model.copyWith(foot: m);
|
model = model.copyWith(foot: m);
|
||||||
});
|
});
|
||||||
|
@ -197,8 +187,6 @@ class FootQuery extends Query<Foot, FootQueryWhere> {
|
||||||
@override
|
@override
|
||||||
final FootQueryValues values = FootQueryValues();
|
final FootQueryValues values = FootQueryValues();
|
||||||
|
|
||||||
List<String> _selectedFields = [];
|
|
||||||
|
|
||||||
FootQueryWhere? _where;
|
FootQueryWhere? _where;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -213,15 +201,7 @@ class FootQuery extends Query<Foot, FootQueryWhere> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<String> get fields {
|
List<String> get fields {
|
||||||
const _fields = ['id', 'created_at', 'updated_at', 'leg_id', 'n_toes'];
|
return const ['id', 'created_at', 'updated_at', 'leg_id', 'n_toes'];
|
||||||
return _selectedFields.isEmpty
|
|
||||||
? _fields
|
|
||||||
: _fields.where((field) => _selectedFields.contains(field)).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
FootQuery select(List<String> selectedFields) {
|
|
||||||
_selectedFields = selectedFields;
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -234,18 +214,16 @@ class FootQuery extends Query<Foot, FootQueryWhere> {
|
||||||
return FootQueryWhere(this);
|
return FootQueryWhere(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Foot> parseRow(List row) {
|
static Optional<Foot> parseRow(List row) {
|
||||||
if (row.every((x) => x == null)) {
|
if (row.every((x) => x == null)) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
var model = Foot(
|
var model = Foot(
|
||||||
id: fields.contains('id') ? row[0].toString() : null,
|
id: row[0].toString(),
|
||||||
createdAt: fields.contains('created_at') ? (row[1] as DateTime?) : null,
|
createdAt: (row[1] as DateTime?),
|
||||||
updatedAt: fields.contains('updated_at') ? (row[2] as DateTime?) : null,
|
updatedAt: (row[2] as DateTime?),
|
||||||
legId: fields.contains('leg_id') ? (row[3] as int?) : null,
|
legId: (row[3] as int?),
|
||||||
nToes: fields.contains('n_toes')
|
nToes: double.tryParse(row[4].toString()));
|
||||||
? double.tryParse(row[4].toString())
|
|
||||||
: null);
|
|
||||||
return Optional.of(model);
|
return Optional.of(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,8 +62,6 @@ class OrderQuery extends Query<Order, OrderQueryWhere> {
|
||||||
@override
|
@override
|
||||||
final OrderQueryValues values = OrderQueryValues();
|
final OrderQueryValues values = OrderQueryValues();
|
||||||
|
|
||||||
List<String> _selectedFields = [];
|
|
||||||
|
|
||||||
OrderQueryWhere? _where;
|
OrderQueryWhere? _where;
|
||||||
|
|
||||||
late CustomerQuery _customer;
|
late CustomerQuery _customer;
|
||||||
|
@ -80,7 +78,7 @@ class OrderQuery extends Query<Order, OrderQueryWhere> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<String> get fields {
|
List<String> get fields {
|
||||||
const _fields = [
|
return const [
|
||||||
'id',
|
'id',
|
||||||
'created_at',
|
'created_at',
|
||||||
'updated_at',
|
'updated_at',
|
||||||
|
@ -89,14 +87,6 @@ class OrderQuery extends Query<Order, OrderQueryWhere> {
|
||||||
'order_date',
|
'order_date',
|
||||||
'shipper_id'
|
'shipper_id'
|
||||||
];
|
];
|
||||||
return _selectedFields.isEmpty
|
|
||||||
? _fields
|
|
||||||
: _fields.where((field) => _selectedFields.contains(field)).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
OrderQuery select(List<String> selectedFields) {
|
|
||||||
_selectedFields = selectedFields;
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -109,19 +99,19 @@ class OrderQuery extends Query<Order, OrderQueryWhere> {
|
||||||
return OrderQueryWhere(this);
|
return OrderQueryWhere(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Order> parseRow(List row) {
|
static Optional<Order> parseRow(List row) {
|
||||||
if (row.every((x) => x == null)) {
|
if (row.every((x) => x == null)) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
var model = Order(
|
var model = Order(
|
||||||
id: fields.contains('id') ? row[0].toString() : null,
|
id: row[0].toString(),
|
||||||
createdAt: fields.contains('created_at') ? (row[1] as DateTime?) : null,
|
createdAt: (row[1] as DateTime?),
|
||||||
updatedAt: fields.contains('updated_at') ? (row[2] as DateTime?) : null,
|
updatedAt: (row[2] as DateTime?),
|
||||||
employeeId: fields.contains('employee_id') ? (row[4] as int?) : null,
|
employeeId: (row[4] as int?),
|
||||||
orderDate: fields.contains('order_date') ? (row[5] as DateTime?) : null,
|
orderDate: (row[5] as DateTime?),
|
||||||
shipperId: fields.contains('shipper_id') ? (row[6] as int?) : null);
|
shipperId: (row[6] as int?));
|
||||||
if (row.length > 7) {
|
if (row.length > 7) {
|
||||||
var modelOpt = CustomerQuery().parseRow(row.skip(7).take(3).toList());
|
var modelOpt = CustomerQuery.parseRow(row.skip(7).take(3).toList());
|
||||||
modelOpt.ifPresent((m) {
|
modelOpt.ifPresent((m) {
|
||||||
model = model.copyWith(customer: m);
|
model = model.copyWith(customer: m);
|
||||||
});
|
});
|
||||||
|
@ -241,8 +231,6 @@ class CustomerQuery extends Query<Customer, CustomerQueryWhere> {
|
||||||
@override
|
@override
|
||||||
final CustomerQueryValues values = CustomerQueryValues();
|
final CustomerQueryValues values = CustomerQueryValues();
|
||||||
|
|
||||||
List<String> _selectedFields = [];
|
|
||||||
|
|
||||||
CustomerQueryWhere? _where;
|
CustomerQueryWhere? _where;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -257,15 +245,7 @@ class CustomerQuery extends Query<Customer, CustomerQueryWhere> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<String> get fields {
|
List<String> get fields {
|
||||||
const _fields = ['id', 'created_at', 'updated_at'];
|
return const ['id', 'created_at', 'updated_at'];
|
||||||
return _selectedFields.isEmpty
|
|
||||||
? _fields
|
|
||||||
: _fields.where((field) => _selectedFields.contains(field)).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
CustomerQuery select(List<String> selectedFields) {
|
|
||||||
_selectedFields = selectedFields;
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -278,15 +258,14 @@ class CustomerQuery extends Query<Customer, CustomerQueryWhere> {
|
||||||
return CustomerQueryWhere(this);
|
return CustomerQueryWhere(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Customer> parseRow(List row) {
|
static Optional<Customer> parseRow(List row) {
|
||||||
if (row.every((x) => x == null)) {
|
if (row.every((x) => x == null)) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
var model = Customer(
|
var model = Customer(
|
||||||
id: fields.contains('id') ? row[0].toString() : null,
|
id: row[0].toString(),
|
||||||
createdAt: fields.contains('created_at') ? (row[1] as DateTime?) : null,
|
createdAt: (row[1] as DateTime?),
|
||||||
updatedAt:
|
updatedAt: (row[2] as DateTime?));
|
||||||
fields.contains('updated_at') ? (row[2] as DateTime?) : null);
|
|
||||||
return Optional.of(model);
|
return Optional.of(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
26
packages/orm/angel_orm_test/lib/src/models/person.dart
Normal file
26
packages/orm/angel_orm_test/lib/src/models/person.dart
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
library angel_orm3.generator.models.person;
|
||||||
|
|
||||||
|
import 'package:angel3_migration/angel3_migration.dart';
|
||||||
|
import 'package:angel3_orm/angel3_orm.dart';
|
||||||
|
import 'package:angel3_serialize/angel3_serialize.dart';
|
||||||
|
import 'package:optional/optional.dart';
|
||||||
|
part 'person.g.dart';
|
||||||
|
|
||||||
|
@serializable
|
||||||
|
@Orm(tableName: 'persons')
|
||||||
|
class _Person extends Model {
|
||||||
|
String? name;
|
||||||
|
int? age;
|
||||||
|
}
|
||||||
|
|
||||||
|
@serializable
|
||||||
|
@Orm(tableName: 'persons', generateMigrations: false)
|
||||||
|
class _PersonWithLastOrder {
|
||||||
|
String? name;
|
||||||
|
|
||||||
|
@Column(expression: 'po.name')
|
||||||
|
String? lastOrderName;
|
||||||
|
|
||||||
|
@Column(expression: 'po.price')
|
||||||
|
int? lastOrderPrice;
|
||||||
|
}
|
482
packages/orm/angel_orm_test/lib/src/models/person.g.dart
Normal file
482
packages/orm/angel_orm_test/lib/src/models/person.g.dart
Normal file
|
@ -0,0 +1,482 @@
|
||||||
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
|
|
||||||
|
part of angel_orm3.generator.models.person;
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// MigrationGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
class PersonMigration extends Migration {
|
||||||
|
@override
|
||||||
|
void up(Schema schema) {
|
||||||
|
schema.create('persons', (table) {
|
||||||
|
table.serial('id').primaryKey();
|
||||||
|
table.timeStamp('created_at');
|
||||||
|
table.timeStamp('updated_at');
|
||||||
|
table.varChar('name', length: 255);
|
||||||
|
table.integer('age');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void down(Schema schema) {
|
||||||
|
schema.drop('persons');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// OrmGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
class PersonQuery extends Query<Person, PersonQueryWhere> {
|
||||||
|
PersonQuery({Query? parent, Set<String>? trampoline})
|
||||||
|
: super(parent: parent) {
|
||||||
|
trampoline ??= <String>{};
|
||||||
|
trampoline.add(tableName);
|
||||||
|
_where = PersonQueryWhere(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
final PersonQueryValues values = PersonQueryValues();
|
||||||
|
|
||||||
|
PersonQueryWhere? _where;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Map<String, String> get casts {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get tableName {
|
||||||
|
return 'persons';
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<String> get fields {
|
||||||
|
return const ['id', 'created_at', 'updated_at', 'name', 'age'];
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
PersonQueryWhere? get where {
|
||||||
|
return _where;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
PersonQueryWhere newWhereClause() {
|
||||||
|
return PersonQueryWhere(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Optional<Person> parseRow(List row) {
|
||||||
|
if (row.every((x) => x == null)) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
var model = Person(
|
||||||
|
id: row[0].toString(),
|
||||||
|
createdAt: (row[1] as DateTime?),
|
||||||
|
updatedAt: (row[2] as DateTime?),
|
||||||
|
name: (row[3] as String?),
|
||||||
|
age: (row[4] as int?));
|
||||||
|
return Optional.of(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Optional<Person> deserialize(List row) {
|
||||||
|
return parseRow(row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class PersonQueryWhere extends QueryWhere {
|
||||||
|
PersonQueryWhere(PersonQuery query)
|
||||||
|
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||||
|
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||||
|
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
|
||||||
|
name = StringSqlExpressionBuilder(query, 'name'),
|
||||||
|
age = NumericSqlExpressionBuilder<int>(query, 'age');
|
||||||
|
|
||||||
|
final NumericSqlExpressionBuilder<int> id;
|
||||||
|
|
||||||
|
final DateTimeSqlExpressionBuilder createdAt;
|
||||||
|
|
||||||
|
final DateTimeSqlExpressionBuilder updatedAt;
|
||||||
|
|
||||||
|
final StringSqlExpressionBuilder name;
|
||||||
|
|
||||||
|
final NumericSqlExpressionBuilder<int> age;
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<SqlExpressionBuilder> get expressionBuilders {
|
||||||
|
return [id, createdAt, updatedAt, name, age];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class PersonQueryValues extends MapQueryValues {
|
||||||
|
@override
|
||||||
|
Map<String, String> get casts {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
String? get id {
|
||||||
|
return (values['id'] as String?);
|
||||||
|
}
|
||||||
|
|
||||||
|
set id(String? value) => values['id'] = value;
|
||||||
|
DateTime? get createdAt {
|
||||||
|
return (values['created_at'] as DateTime?);
|
||||||
|
}
|
||||||
|
|
||||||
|
set createdAt(DateTime? value) => values['created_at'] = value;
|
||||||
|
DateTime? get updatedAt {
|
||||||
|
return (values['updated_at'] as DateTime?);
|
||||||
|
}
|
||||||
|
|
||||||
|
set updatedAt(DateTime? value) => values['updated_at'] = value;
|
||||||
|
String? get name {
|
||||||
|
return (values['name'] as String?);
|
||||||
|
}
|
||||||
|
|
||||||
|
set name(String? value) => values['name'] = value;
|
||||||
|
int? get age {
|
||||||
|
return (values['age'] as int?);
|
||||||
|
}
|
||||||
|
|
||||||
|
set age(int? value) => values['age'] = value;
|
||||||
|
void copyFrom(Person model) {
|
||||||
|
createdAt = model.createdAt;
|
||||||
|
updatedAt = model.updatedAt;
|
||||||
|
name = model.name;
|
||||||
|
age = model.age;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class PersonWithLastOrderQuery
|
||||||
|
extends Query<PersonWithLastOrder, PersonWithLastOrderQueryWhere> {
|
||||||
|
PersonWithLastOrderQuery({Query? parent, Set<String>? trampoline})
|
||||||
|
: super(parent: parent) {
|
||||||
|
trampoline ??= <String>{};
|
||||||
|
trampoline.add(tableName);
|
||||||
|
expressions['last_order_name'] = 'po.name';
|
||||||
|
expressions['last_order_price'] = 'po.price';
|
||||||
|
_where = PersonWithLastOrderQueryWhere(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
final PersonWithLastOrderQueryValues values =
|
||||||
|
PersonWithLastOrderQueryValues();
|
||||||
|
|
||||||
|
PersonWithLastOrderQueryWhere? _where;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Map<String, String> get casts {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get tableName {
|
||||||
|
return 'persons';
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<String> get fields {
|
||||||
|
return const ['name', 'last_order_name', 'last_order_price'];
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
PersonWithLastOrderQueryWhere? get where {
|
||||||
|
return _where;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
PersonWithLastOrderQueryWhere newWhereClause() {
|
||||||
|
return PersonWithLastOrderQueryWhere(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Optional<PersonWithLastOrder> parseRow(List row) {
|
||||||
|
if (row.every((x) => x == null)) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
var model = PersonWithLastOrder(
|
||||||
|
name: (row[0] as String?),
|
||||||
|
lastOrderName: (row[1] as String?),
|
||||||
|
lastOrderPrice: (row[2] as int?));
|
||||||
|
return Optional.of(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Optional<PersonWithLastOrder> deserialize(List row) {
|
||||||
|
return parseRow(row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class PersonWithLastOrderQueryWhere extends QueryWhere {
|
||||||
|
PersonWithLastOrderQueryWhere(PersonWithLastOrderQuery query)
|
||||||
|
: name = StringSqlExpressionBuilder(query, 'name');
|
||||||
|
|
||||||
|
final StringSqlExpressionBuilder name;
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<SqlExpressionBuilder> get expressionBuilders {
|
||||||
|
return [name];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class PersonWithLastOrderQueryValues extends MapQueryValues {
|
||||||
|
@override
|
||||||
|
Map<String, String> get casts {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
String? get name {
|
||||||
|
return (values['name'] as String?);
|
||||||
|
}
|
||||||
|
|
||||||
|
set name(String? value) => values['name'] = value;
|
||||||
|
void copyFrom(PersonWithLastOrder model) {
|
||||||
|
name = model.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// JsonModelGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
@generatedSerializable
|
||||||
|
class Person extends _Person {
|
||||||
|
Person({this.id, this.createdAt, this.updatedAt, this.name, this.age});
|
||||||
|
|
||||||
|
/// A unique identifier corresponding to this item.
|
||||||
|
@override
|
||||||
|
String? id;
|
||||||
|
|
||||||
|
/// The time at which this item was created.
|
||||||
|
@override
|
||||||
|
DateTime? createdAt;
|
||||||
|
|
||||||
|
/// The last time at which this item was updated.
|
||||||
|
@override
|
||||||
|
DateTime? updatedAt;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String? name;
|
||||||
|
|
||||||
|
@override
|
||||||
|
int? age;
|
||||||
|
|
||||||
|
Person copyWith(
|
||||||
|
{String? id,
|
||||||
|
DateTime? createdAt,
|
||||||
|
DateTime? updatedAt,
|
||||||
|
String? name,
|
||||||
|
int? age}) {
|
||||||
|
return Person(
|
||||||
|
id: id ?? this.id,
|
||||||
|
createdAt: createdAt ?? this.createdAt,
|
||||||
|
updatedAt: updatedAt ?? this.updatedAt,
|
||||||
|
name: name ?? this.name,
|
||||||
|
age: age ?? this.age);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(other) {
|
||||||
|
return other is _Person &&
|
||||||
|
other.id == id &&
|
||||||
|
other.createdAt == createdAt &&
|
||||||
|
other.updatedAt == updatedAt &&
|
||||||
|
other.name == name &&
|
||||||
|
other.age == age;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode {
|
||||||
|
return hashObjects([id, createdAt, updatedAt, name, age]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'Person(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, name=$name, age=$age)';
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
return PersonSerializer.toMap(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@generatedSerializable
|
||||||
|
class PersonWithLastOrder extends _PersonWithLastOrder {
|
||||||
|
PersonWithLastOrder({this.name, this.lastOrderName, this.lastOrderPrice});
|
||||||
|
|
||||||
|
@override
|
||||||
|
String? name;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String? lastOrderName;
|
||||||
|
|
||||||
|
@override
|
||||||
|
int? lastOrderPrice;
|
||||||
|
|
||||||
|
PersonWithLastOrder copyWith(
|
||||||
|
{String? name, String? lastOrderName, int? lastOrderPrice}) {
|
||||||
|
return PersonWithLastOrder(
|
||||||
|
name: name ?? this.name,
|
||||||
|
lastOrderName: lastOrderName ?? this.lastOrderName,
|
||||||
|
lastOrderPrice: lastOrderPrice ?? this.lastOrderPrice);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(other) {
|
||||||
|
return other is _PersonWithLastOrder &&
|
||||||
|
other.name == name &&
|
||||||
|
other.lastOrderName == lastOrderName &&
|
||||||
|
other.lastOrderPrice == lastOrderPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode {
|
||||||
|
return hashObjects([name, lastOrderName, lastOrderPrice]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'PersonWithLastOrder(name=$name, lastOrderName=$lastOrderName, lastOrderPrice=$lastOrderPrice)';
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
return PersonWithLastOrderSerializer.toMap(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// SerializerGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
const PersonSerializer personSerializer = PersonSerializer();
|
||||||
|
|
||||||
|
class PersonEncoder extends Converter<Person, Map> {
|
||||||
|
const PersonEncoder();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Map convert(Person model) => PersonSerializer.toMap(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
class PersonDecoder extends Converter<Map, Person> {
|
||||||
|
const PersonDecoder();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Person convert(Map map) => PersonSerializer.fromMap(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
class PersonSerializer extends Codec<Person, Map> {
|
||||||
|
const PersonSerializer();
|
||||||
|
|
||||||
|
@override
|
||||||
|
PersonEncoder get encoder => const PersonEncoder();
|
||||||
|
@override
|
||||||
|
PersonDecoder get decoder => const PersonDecoder();
|
||||||
|
static Person fromMap(Map map) {
|
||||||
|
return Person(
|
||||||
|
id: map['id'] as String?,
|
||||||
|
createdAt: map['created_at'] != null
|
||||||
|
? (map['created_at'] is DateTime
|
||||||
|
? (map['created_at'] as DateTime)
|
||||||
|
: DateTime.parse(map['created_at'].toString()))
|
||||||
|
: null,
|
||||||
|
updatedAt: map['updated_at'] != null
|
||||||
|
? (map['updated_at'] is DateTime
|
||||||
|
? (map['updated_at'] as DateTime)
|
||||||
|
: DateTime.parse(map['updated_at'].toString()))
|
||||||
|
: null,
|
||||||
|
name: map['name'] as String?,
|
||||||
|
age: map['age'] as int?);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Map<String, dynamic> toMap(_Person? model) {
|
||||||
|
if (model == null) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
'id': model.id,
|
||||||
|
'created_at': model.createdAt?.toIso8601String(),
|
||||||
|
'updated_at': model.updatedAt?.toIso8601String(),
|
||||||
|
'name': model.name,
|
||||||
|
'age': model.age
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class PersonFields {
|
||||||
|
static const List<String> allFields = <String>[
|
||||||
|
id,
|
||||||
|
createdAt,
|
||||||
|
updatedAt,
|
||||||
|
name,
|
||||||
|
age
|
||||||
|
];
|
||||||
|
|
||||||
|
static const String id = 'id';
|
||||||
|
|
||||||
|
static const String createdAt = 'created_at';
|
||||||
|
|
||||||
|
static const String updatedAt = 'updated_at';
|
||||||
|
|
||||||
|
static const String name = 'name';
|
||||||
|
|
||||||
|
static const String age = 'age';
|
||||||
|
}
|
||||||
|
|
||||||
|
const PersonWithLastOrderSerializer personWithLastOrderSerializer =
|
||||||
|
PersonWithLastOrderSerializer();
|
||||||
|
|
||||||
|
class PersonWithLastOrderEncoder extends Converter<PersonWithLastOrder, Map> {
|
||||||
|
const PersonWithLastOrderEncoder();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Map convert(PersonWithLastOrder model) =>
|
||||||
|
PersonWithLastOrderSerializer.toMap(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
class PersonWithLastOrderDecoder extends Converter<Map, PersonWithLastOrder> {
|
||||||
|
const PersonWithLastOrderDecoder();
|
||||||
|
|
||||||
|
@override
|
||||||
|
PersonWithLastOrder convert(Map map) =>
|
||||||
|
PersonWithLastOrderSerializer.fromMap(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
class PersonWithLastOrderSerializer extends Codec<PersonWithLastOrder, Map> {
|
||||||
|
const PersonWithLastOrderSerializer();
|
||||||
|
|
||||||
|
@override
|
||||||
|
PersonWithLastOrderEncoder get encoder => const PersonWithLastOrderEncoder();
|
||||||
|
@override
|
||||||
|
PersonWithLastOrderDecoder get decoder => const PersonWithLastOrderDecoder();
|
||||||
|
static PersonWithLastOrder fromMap(Map map) {
|
||||||
|
return PersonWithLastOrder(
|
||||||
|
name: map['name'] as String?,
|
||||||
|
lastOrderName: map['last_order_name'] as String?,
|
||||||
|
lastOrderPrice: map['last_order_price'] as int?);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Map<String, dynamic> toMap(_PersonWithLastOrder? model) {
|
||||||
|
if (model == null) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
'name': model.name,
|
||||||
|
'last_order_name': model.lastOrderName,
|
||||||
|
'last_order_price': model.lastOrderPrice
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class PersonWithLastOrderFields {
|
||||||
|
static const List<String> allFields = <String>[
|
||||||
|
name,
|
||||||
|
lastOrderName,
|
||||||
|
lastOrderPrice
|
||||||
|
];
|
||||||
|
|
||||||
|
static const String name = 'name';
|
||||||
|
|
||||||
|
static const String lastOrderName = 'last_order_name';
|
||||||
|
|
||||||
|
static const String lastOrderPrice = 'last_order_price';
|
||||||
|
}
|
36
packages/orm/angel_orm_test/lib/src/models/person_order.dart
Normal file
36
packages/orm/angel_orm_test/lib/src/models/person_order.dart
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
library angel3_orm_generator.test.models.person_order;
|
||||||
|
|
||||||
|
import 'package:angel3_migration/angel3_migration.dart';
|
||||||
|
import 'package:angel3_orm/angel3_orm.dart';
|
||||||
|
import 'package:angel3_serialize/angel3_serialize.dart';
|
||||||
|
import 'package:optional/optional.dart';
|
||||||
|
|
||||||
|
part 'person_order.g.dart';
|
||||||
|
|
||||||
|
@orm
|
||||||
|
@serializable
|
||||||
|
abstract class _PersonOrder extends Model {
|
||||||
|
int? get personId;
|
||||||
|
|
||||||
|
String? get name;
|
||||||
|
|
||||||
|
double? get price;
|
||||||
|
|
||||||
|
bool? get deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
@serializable
|
||||||
|
@Orm(tableName: 'person_orders', generateMigrations: false)
|
||||||
|
abstract class _OrderWithPersonInfo extends Model {
|
||||||
|
String? get name;
|
||||||
|
|
||||||
|
double? get price;
|
||||||
|
|
||||||
|
bool? get deleted;
|
||||||
|
|
||||||
|
@Column(expression: 'p.name')
|
||||||
|
String? get personName;
|
||||||
|
|
||||||
|
@Column(expression: 'p.age')
|
||||||
|
int? get personAge;
|
||||||
|
}
|
686
packages/orm/angel_orm_test/lib/src/models/person_order.g.dart
Normal file
686
packages/orm/angel_orm_test/lib/src/models/person_order.g.dart
Normal file
|
@ -0,0 +1,686 @@
|
||||||
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
|
|
||||||
|
part of angel3_orm_generator.test.models.person_order;
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// MigrationGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
class PersonOrderMigration extends Migration {
|
||||||
|
@override
|
||||||
|
void up(Schema schema) {
|
||||||
|
schema.create('person_orders', (table) {
|
||||||
|
table.serial('id').primaryKey();
|
||||||
|
table.timeStamp('created_at');
|
||||||
|
table.timeStamp('updated_at');
|
||||||
|
table.integer('person_id');
|
||||||
|
table.varChar('name', length: 255);
|
||||||
|
table.declareColumn(
|
||||||
|
'price', Column(type: ColumnType('decimal'), length: 255));
|
||||||
|
table.boolean('deleted');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void down(Schema schema) {
|
||||||
|
schema.drop('person_orders');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// OrmGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
class PersonOrderQuery extends Query<PersonOrder, PersonOrderQueryWhere> {
|
||||||
|
PersonOrderQuery({Query? parent, Set<String>? trampoline})
|
||||||
|
: super(parent: parent) {
|
||||||
|
trampoline ??= <String>{};
|
||||||
|
trampoline.add(tableName);
|
||||||
|
_where = PersonOrderQueryWhere(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
final PersonOrderQueryValues values = PersonOrderQueryValues();
|
||||||
|
|
||||||
|
PersonOrderQueryWhere? _where;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Map<String, String> get casts {
|
||||||
|
return {'price': 'text'};
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get tableName {
|
||||||
|
return 'person_orders';
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<String> get fields {
|
||||||
|
return const [
|
||||||
|
'id',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
'person_id',
|
||||||
|
'name',
|
||||||
|
'price',
|
||||||
|
'deleted'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
PersonOrderQueryWhere? get where {
|
||||||
|
return _where;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
PersonOrderQueryWhere newWhereClause() {
|
||||||
|
return PersonOrderQueryWhere(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Optional<PersonOrder> parseRow(List row) {
|
||||||
|
if (row.every((x) => x == null)) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
var model = PersonOrder(
|
||||||
|
id: row[0].toString(),
|
||||||
|
createdAt: (row[1] as DateTime?),
|
||||||
|
updatedAt: (row[2] as DateTime?),
|
||||||
|
personId: (row[3] as int?),
|
||||||
|
name: (row[4] as String?),
|
||||||
|
price: double.tryParse(row[5].toString()),
|
||||||
|
deleted: (row[6] as bool?));
|
||||||
|
return Optional.of(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Optional<PersonOrder> deserialize(List row) {
|
||||||
|
return parseRow(row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class PersonOrderQueryWhere extends QueryWhere {
|
||||||
|
PersonOrderQueryWhere(PersonOrderQuery query)
|
||||||
|
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||||
|
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||||
|
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
|
||||||
|
personId = NumericSqlExpressionBuilder<int>(query, 'person_id'),
|
||||||
|
name = StringSqlExpressionBuilder(query, 'name'),
|
||||||
|
price = NumericSqlExpressionBuilder<double>(query, 'price'),
|
||||||
|
deleted = BooleanSqlExpressionBuilder(query, 'deleted');
|
||||||
|
|
||||||
|
final NumericSqlExpressionBuilder<int> id;
|
||||||
|
|
||||||
|
final DateTimeSqlExpressionBuilder createdAt;
|
||||||
|
|
||||||
|
final DateTimeSqlExpressionBuilder updatedAt;
|
||||||
|
|
||||||
|
final NumericSqlExpressionBuilder<int> personId;
|
||||||
|
|
||||||
|
final StringSqlExpressionBuilder name;
|
||||||
|
|
||||||
|
final NumericSqlExpressionBuilder<double> price;
|
||||||
|
|
||||||
|
final BooleanSqlExpressionBuilder deleted;
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<SqlExpressionBuilder> get expressionBuilders {
|
||||||
|
return [id, createdAt, updatedAt, personId, name, price, deleted];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class PersonOrderQueryValues extends MapQueryValues {
|
||||||
|
@override
|
||||||
|
Map<String, String> get casts {
|
||||||
|
return {'price': 'decimal'};
|
||||||
|
}
|
||||||
|
|
||||||
|
String? get id {
|
||||||
|
return (values['id'] as String?);
|
||||||
|
}
|
||||||
|
|
||||||
|
set id(String? value) => values['id'] = value;
|
||||||
|
DateTime? get createdAt {
|
||||||
|
return (values['created_at'] as DateTime?);
|
||||||
|
}
|
||||||
|
|
||||||
|
set createdAt(DateTime? value) => values['created_at'] = value;
|
||||||
|
DateTime? get updatedAt {
|
||||||
|
return (values['updated_at'] as DateTime?);
|
||||||
|
}
|
||||||
|
|
||||||
|
set updatedAt(DateTime? value) => values['updated_at'] = value;
|
||||||
|
int? get personId {
|
||||||
|
return (values['person_id'] as int?);
|
||||||
|
}
|
||||||
|
|
||||||
|
set personId(int? value) => values['person_id'] = value;
|
||||||
|
String? get name {
|
||||||
|
return (values['name'] as String?);
|
||||||
|
}
|
||||||
|
|
||||||
|
set name(String? value) => values['name'] = value;
|
||||||
|
double? get price {
|
||||||
|
return double.tryParse((values['price'] as String));
|
||||||
|
}
|
||||||
|
|
||||||
|
set price(double? value) => values['price'] = value.toString();
|
||||||
|
bool? get deleted {
|
||||||
|
return (values['deleted'] as bool?);
|
||||||
|
}
|
||||||
|
|
||||||
|
set deleted(bool? value) => values['deleted'] = value;
|
||||||
|
void copyFrom(PersonOrder model) {
|
||||||
|
createdAt = model.createdAt;
|
||||||
|
updatedAt = model.updatedAt;
|
||||||
|
personId = model.personId;
|
||||||
|
name = model.name;
|
||||||
|
price = model.price;
|
||||||
|
deleted = model.deleted;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class OrderWithPersonInfoQuery
|
||||||
|
extends Query<OrderWithPersonInfo, OrderWithPersonInfoQueryWhere> {
|
||||||
|
OrderWithPersonInfoQuery({Query? parent, Set<String>? trampoline})
|
||||||
|
: super(parent: parent) {
|
||||||
|
trampoline ??= <String>{};
|
||||||
|
trampoline.add(tableName);
|
||||||
|
expressions['person_name'] = 'p.name';
|
||||||
|
expressions['person_age'] = 'p.age';
|
||||||
|
_where = OrderWithPersonInfoQueryWhere(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
final OrderWithPersonInfoQueryValues values =
|
||||||
|
OrderWithPersonInfoQueryValues();
|
||||||
|
|
||||||
|
OrderWithPersonInfoQueryWhere? _where;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Map<String, String> get casts {
|
||||||
|
return {'price': 'text'};
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get tableName {
|
||||||
|
return 'person_orders';
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<String> get fields {
|
||||||
|
return const [
|
||||||
|
'id',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
'name',
|
||||||
|
'price',
|
||||||
|
'deleted',
|
||||||
|
'person_name',
|
||||||
|
'person_age'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
OrderWithPersonInfoQueryWhere? get where {
|
||||||
|
return _where;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
OrderWithPersonInfoQueryWhere newWhereClause() {
|
||||||
|
return OrderWithPersonInfoQueryWhere(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Optional<OrderWithPersonInfo> parseRow(List row) {
|
||||||
|
if (row.every((x) => x == null)) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
var model = OrderWithPersonInfo(
|
||||||
|
id: row[0].toString(),
|
||||||
|
createdAt: (row[1] as DateTime?),
|
||||||
|
updatedAt: (row[2] as DateTime?),
|
||||||
|
name: (row[3] as String?),
|
||||||
|
price: double.tryParse(row[4].toString()),
|
||||||
|
deleted: (row[5] as bool?),
|
||||||
|
personName: (row[6] as String?),
|
||||||
|
personAge: (row[7] as int?));
|
||||||
|
return Optional.of(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Optional<OrderWithPersonInfo> deserialize(List row) {
|
||||||
|
return parseRow(row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class OrderWithPersonInfoQueryWhere extends QueryWhere {
|
||||||
|
OrderWithPersonInfoQueryWhere(OrderWithPersonInfoQuery query)
|
||||||
|
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||||
|
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||||
|
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
|
||||||
|
name = StringSqlExpressionBuilder(query, 'name'),
|
||||||
|
price = NumericSqlExpressionBuilder<double>(query, 'price'),
|
||||||
|
deleted = BooleanSqlExpressionBuilder(query, 'deleted');
|
||||||
|
|
||||||
|
final NumericSqlExpressionBuilder<int> id;
|
||||||
|
|
||||||
|
final DateTimeSqlExpressionBuilder createdAt;
|
||||||
|
|
||||||
|
final DateTimeSqlExpressionBuilder updatedAt;
|
||||||
|
|
||||||
|
final StringSqlExpressionBuilder name;
|
||||||
|
|
||||||
|
final NumericSqlExpressionBuilder<double> price;
|
||||||
|
|
||||||
|
final BooleanSqlExpressionBuilder deleted;
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<SqlExpressionBuilder> get expressionBuilders {
|
||||||
|
return [id, createdAt, updatedAt, name, price, deleted];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class OrderWithPersonInfoQueryValues extends MapQueryValues {
|
||||||
|
@override
|
||||||
|
Map<String, String> get casts {
|
||||||
|
return {'price': 'decimal'};
|
||||||
|
}
|
||||||
|
|
||||||
|
String? get id {
|
||||||
|
return (values['id'] as String?);
|
||||||
|
}
|
||||||
|
|
||||||
|
set id(String? value) => values['id'] = value;
|
||||||
|
DateTime? get createdAt {
|
||||||
|
return (values['created_at'] as DateTime?);
|
||||||
|
}
|
||||||
|
|
||||||
|
set createdAt(DateTime? value) => values['created_at'] = value;
|
||||||
|
DateTime? get updatedAt {
|
||||||
|
return (values['updated_at'] as DateTime?);
|
||||||
|
}
|
||||||
|
|
||||||
|
set updatedAt(DateTime? value) => values['updated_at'] = value;
|
||||||
|
String? get name {
|
||||||
|
return (values['name'] as String?);
|
||||||
|
}
|
||||||
|
|
||||||
|
set name(String? value) => values['name'] = value;
|
||||||
|
double? get price {
|
||||||
|
return double.tryParse((values['price'] as String));
|
||||||
|
}
|
||||||
|
|
||||||
|
set price(double? value) => values['price'] = value.toString();
|
||||||
|
bool? get deleted {
|
||||||
|
return (values['deleted'] as bool?);
|
||||||
|
}
|
||||||
|
|
||||||
|
set deleted(bool? value) => values['deleted'] = value;
|
||||||
|
void copyFrom(OrderWithPersonInfo model) {
|
||||||
|
createdAt = model.createdAt;
|
||||||
|
updatedAt = model.updatedAt;
|
||||||
|
name = model.name;
|
||||||
|
price = model.price;
|
||||||
|
deleted = model.deleted;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// JsonModelGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
@generatedSerializable
|
||||||
|
class PersonOrder extends _PersonOrder {
|
||||||
|
PersonOrder(
|
||||||
|
{this.id,
|
||||||
|
this.createdAt,
|
||||||
|
this.updatedAt,
|
||||||
|
this.personId,
|
||||||
|
this.name,
|
||||||
|
this.price,
|
||||||
|
this.deleted});
|
||||||
|
|
||||||
|
/// A unique identifier corresponding to this item.
|
||||||
|
@override
|
||||||
|
String? id;
|
||||||
|
|
||||||
|
/// The time at which this item was created.
|
||||||
|
@override
|
||||||
|
DateTime? createdAt;
|
||||||
|
|
||||||
|
/// The last time at which this item was updated.
|
||||||
|
@override
|
||||||
|
DateTime? updatedAt;
|
||||||
|
|
||||||
|
@override
|
||||||
|
int? personId;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String? name;
|
||||||
|
|
||||||
|
@override
|
||||||
|
double? price;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool? deleted;
|
||||||
|
|
||||||
|
PersonOrder copyWith(
|
||||||
|
{String? id,
|
||||||
|
DateTime? createdAt,
|
||||||
|
DateTime? updatedAt,
|
||||||
|
int? personId,
|
||||||
|
String? name,
|
||||||
|
double? price,
|
||||||
|
bool? deleted}) {
|
||||||
|
return PersonOrder(
|
||||||
|
id: id ?? this.id,
|
||||||
|
createdAt: createdAt ?? this.createdAt,
|
||||||
|
updatedAt: updatedAt ?? this.updatedAt,
|
||||||
|
personId: personId ?? this.personId,
|
||||||
|
name: name ?? this.name,
|
||||||
|
price: price ?? this.price,
|
||||||
|
deleted: deleted ?? this.deleted);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(other) {
|
||||||
|
return other is _PersonOrder &&
|
||||||
|
other.id == id &&
|
||||||
|
other.createdAt == createdAt &&
|
||||||
|
other.updatedAt == updatedAt &&
|
||||||
|
other.personId == personId &&
|
||||||
|
other.name == name &&
|
||||||
|
other.price == price &&
|
||||||
|
other.deleted == deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode {
|
||||||
|
return hashObjects(
|
||||||
|
[id, createdAt, updatedAt, personId, name, price, deleted]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'PersonOrder(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, personId=$personId, name=$name, price=$price, deleted=$deleted)';
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
return PersonOrderSerializer.toMap(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@generatedSerializable
|
||||||
|
class OrderWithPersonInfo extends _OrderWithPersonInfo {
|
||||||
|
OrderWithPersonInfo(
|
||||||
|
{this.id,
|
||||||
|
this.createdAt,
|
||||||
|
this.updatedAt,
|
||||||
|
this.name,
|
||||||
|
this.price,
|
||||||
|
this.deleted,
|
||||||
|
this.personName,
|
||||||
|
this.personAge});
|
||||||
|
|
||||||
|
/// A unique identifier corresponding to this item.
|
||||||
|
@override
|
||||||
|
String? id;
|
||||||
|
|
||||||
|
/// The time at which this item was created.
|
||||||
|
@override
|
||||||
|
DateTime? createdAt;
|
||||||
|
|
||||||
|
/// The last time at which this item was updated.
|
||||||
|
@override
|
||||||
|
DateTime? updatedAt;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String? name;
|
||||||
|
|
||||||
|
@override
|
||||||
|
double? price;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool? deleted;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String? personName;
|
||||||
|
|
||||||
|
@override
|
||||||
|
int? personAge;
|
||||||
|
|
||||||
|
OrderWithPersonInfo copyWith(
|
||||||
|
{String? id,
|
||||||
|
DateTime? createdAt,
|
||||||
|
DateTime? updatedAt,
|
||||||
|
String? name,
|
||||||
|
double? price,
|
||||||
|
bool? deleted,
|
||||||
|
String? personName,
|
||||||
|
int? personAge}) {
|
||||||
|
return OrderWithPersonInfo(
|
||||||
|
id: id ?? this.id,
|
||||||
|
createdAt: createdAt ?? this.createdAt,
|
||||||
|
updatedAt: updatedAt ?? this.updatedAt,
|
||||||
|
name: name ?? this.name,
|
||||||
|
price: price ?? this.price,
|
||||||
|
deleted: deleted ?? this.deleted,
|
||||||
|
personName: personName ?? this.personName,
|
||||||
|
personAge: personAge ?? this.personAge);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(other) {
|
||||||
|
return other is _OrderWithPersonInfo &&
|
||||||
|
other.id == id &&
|
||||||
|
other.createdAt == createdAt &&
|
||||||
|
other.updatedAt == updatedAt &&
|
||||||
|
other.name == name &&
|
||||||
|
other.price == price &&
|
||||||
|
other.deleted == deleted &&
|
||||||
|
other.personName == personName &&
|
||||||
|
other.personAge == personAge;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode {
|
||||||
|
return hashObjects([
|
||||||
|
id,
|
||||||
|
createdAt,
|
||||||
|
updatedAt,
|
||||||
|
name,
|
||||||
|
price,
|
||||||
|
deleted,
|
||||||
|
personName,
|
||||||
|
personAge
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'OrderWithPersonInfo(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, name=$name, price=$price, deleted=$deleted, personName=$personName, personAge=$personAge)';
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
return OrderWithPersonInfoSerializer.toMap(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// SerializerGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
const PersonOrderSerializer personOrderSerializer = PersonOrderSerializer();
|
||||||
|
|
||||||
|
class PersonOrderEncoder extends Converter<PersonOrder, Map> {
|
||||||
|
const PersonOrderEncoder();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Map convert(PersonOrder model) => PersonOrderSerializer.toMap(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
class PersonOrderDecoder extends Converter<Map, PersonOrder> {
|
||||||
|
const PersonOrderDecoder();
|
||||||
|
|
||||||
|
@override
|
||||||
|
PersonOrder convert(Map map) => PersonOrderSerializer.fromMap(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
class PersonOrderSerializer extends Codec<PersonOrder, Map> {
|
||||||
|
const PersonOrderSerializer();
|
||||||
|
|
||||||
|
@override
|
||||||
|
PersonOrderEncoder get encoder => const PersonOrderEncoder();
|
||||||
|
@override
|
||||||
|
PersonOrderDecoder get decoder => const PersonOrderDecoder();
|
||||||
|
static PersonOrder fromMap(Map map) {
|
||||||
|
return PersonOrder(
|
||||||
|
id: map['id'] as String?,
|
||||||
|
createdAt: map['created_at'] != null
|
||||||
|
? (map['created_at'] is DateTime
|
||||||
|
? (map['created_at'] as DateTime)
|
||||||
|
: DateTime.parse(map['created_at'].toString()))
|
||||||
|
: null,
|
||||||
|
updatedAt: map['updated_at'] != null
|
||||||
|
? (map['updated_at'] is DateTime
|
||||||
|
? (map['updated_at'] as DateTime)
|
||||||
|
: DateTime.parse(map['updated_at'].toString()))
|
||||||
|
: null,
|
||||||
|
personId: map['person_id'] as int?,
|
||||||
|
name: map['name'] as String?,
|
||||||
|
price: map['price'] as double?,
|
||||||
|
deleted: map['deleted'] as bool?);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Map<String, dynamic> toMap(_PersonOrder? model) {
|
||||||
|
if (model == null) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
'id': model.id,
|
||||||
|
'created_at': model.createdAt?.toIso8601String(),
|
||||||
|
'updated_at': model.updatedAt?.toIso8601String(),
|
||||||
|
'person_id': model.personId,
|
||||||
|
'name': model.name,
|
||||||
|
'price': model.price,
|
||||||
|
'deleted': model.deleted
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class PersonOrderFields {
|
||||||
|
static const List<String> allFields = <String>[
|
||||||
|
id,
|
||||||
|
createdAt,
|
||||||
|
updatedAt,
|
||||||
|
personId,
|
||||||
|
name,
|
||||||
|
price,
|
||||||
|
deleted
|
||||||
|
];
|
||||||
|
|
||||||
|
static const String id = 'id';
|
||||||
|
|
||||||
|
static const String createdAt = 'created_at';
|
||||||
|
|
||||||
|
static const String updatedAt = 'updated_at';
|
||||||
|
|
||||||
|
static const String personId = 'person_id';
|
||||||
|
|
||||||
|
static const String name = 'name';
|
||||||
|
|
||||||
|
static const String price = 'price';
|
||||||
|
|
||||||
|
static const String deleted = 'deleted';
|
||||||
|
}
|
||||||
|
|
||||||
|
const OrderWithPersonInfoSerializer orderWithPersonInfoSerializer =
|
||||||
|
OrderWithPersonInfoSerializer();
|
||||||
|
|
||||||
|
class OrderWithPersonInfoEncoder extends Converter<OrderWithPersonInfo, Map> {
|
||||||
|
const OrderWithPersonInfoEncoder();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Map convert(OrderWithPersonInfo model) =>
|
||||||
|
OrderWithPersonInfoSerializer.toMap(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
class OrderWithPersonInfoDecoder extends Converter<Map, OrderWithPersonInfo> {
|
||||||
|
const OrderWithPersonInfoDecoder();
|
||||||
|
|
||||||
|
@override
|
||||||
|
OrderWithPersonInfo convert(Map map) =>
|
||||||
|
OrderWithPersonInfoSerializer.fromMap(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
class OrderWithPersonInfoSerializer extends Codec<OrderWithPersonInfo, Map> {
|
||||||
|
const OrderWithPersonInfoSerializer();
|
||||||
|
|
||||||
|
@override
|
||||||
|
OrderWithPersonInfoEncoder get encoder => const OrderWithPersonInfoEncoder();
|
||||||
|
@override
|
||||||
|
OrderWithPersonInfoDecoder get decoder => const OrderWithPersonInfoDecoder();
|
||||||
|
static OrderWithPersonInfo fromMap(Map map) {
|
||||||
|
return OrderWithPersonInfo(
|
||||||
|
id: map['id'] as String?,
|
||||||
|
createdAt: map['created_at'] != null
|
||||||
|
? (map['created_at'] is DateTime
|
||||||
|
? (map['created_at'] as DateTime)
|
||||||
|
: DateTime.parse(map['created_at'].toString()))
|
||||||
|
: null,
|
||||||
|
updatedAt: map['updated_at'] != null
|
||||||
|
? (map['updated_at'] is DateTime
|
||||||
|
? (map['updated_at'] as DateTime)
|
||||||
|
: DateTime.parse(map['updated_at'].toString()))
|
||||||
|
: null,
|
||||||
|
name: map['name'] as String?,
|
||||||
|
price: map['price'] as double?,
|
||||||
|
deleted: map['deleted'] as bool?,
|
||||||
|
personName: map['person_name'] as String?,
|
||||||
|
personAge: map['person_age'] as int?);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Map<String, dynamic> toMap(_OrderWithPersonInfo? model) {
|
||||||
|
if (model == null) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
'id': model.id,
|
||||||
|
'created_at': model.createdAt?.toIso8601String(),
|
||||||
|
'updated_at': model.updatedAt?.toIso8601String(),
|
||||||
|
'name': model.name,
|
||||||
|
'price': model.price,
|
||||||
|
'deleted': model.deleted,
|
||||||
|
'person_name': model.personName,
|
||||||
|
'person_age': model.personAge
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class OrderWithPersonInfoFields {
|
||||||
|
static const List<String> allFields = <String>[
|
||||||
|
id,
|
||||||
|
createdAt,
|
||||||
|
updatedAt,
|
||||||
|
name,
|
||||||
|
price,
|
||||||
|
deleted,
|
||||||
|
personName,
|
||||||
|
personAge
|
||||||
|
];
|
||||||
|
|
||||||
|
static const String id = 'id';
|
||||||
|
|
||||||
|
static const String createdAt = 'created_at';
|
||||||
|
|
||||||
|
static const String updatedAt = 'updated_at';
|
||||||
|
|
||||||
|
static const String name = 'name';
|
||||||
|
|
||||||
|
static const String price = 'price';
|
||||||
|
|
||||||
|
static const String deleted = 'deleted';
|
||||||
|
|
||||||
|
static const String personName = 'person_name';
|
||||||
|
|
||||||
|
static const String personAge = 'person_age';
|
||||||
|
}
|
|
@ -65,8 +65,6 @@ class TreeQuery extends Query<Tree, TreeQueryWhere> {
|
||||||
@override
|
@override
|
||||||
final TreeQueryValues values = TreeQueryValues();
|
final TreeQueryValues values = TreeQueryValues();
|
||||||
|
|
||||||
List<String> _selectedFields = [];
|
|
||||||
|
|
||||||
TreeQueryWhere? _where;
|
TreeQueryWhere? _where;
|
||||||
|
|
||||||
late FruitQuery _fruits;
|
late FruitQuery _fruits;
|
||||||
|
@ -83,15 +81,7 @@ class TreeQuery extends Query<Tree, TreeQueryWhere> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<String> get fields {
|
List<String> get fields {
|
||||||
const _fields = ['id', 'created_at', 'updated_at', 'rings'];
|
return const ['id', 'created_at', 'updated_at', 'rings'];
|
||||||
return _selectedFields.isEmpty
|
|
||||||
? _fields
|
|
||||||
: _fields.where((field) => _selectedFields.contains(field)).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
TreeQuery select(List<String> selectedFields) {
|
|
||||||
_selectedFields = selectedFields;
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -104,17 +94,17 @@ class TreeQuery extends Query<Tree, TreeQueryWhere> {
|
||||||
return TreeQueryWhere(this);
|
return TreeQueryWhere(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Tree> parseRow(List row) {
|
static Optional<Tree> parseRow(List row) {
|
||||||
if (row.every((x) => x == null)) {
|
if (row.every((x) => x == null)) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
var model = Tree(
|
var model = Tree(
|
||||||
id: fields.contains('id') ? row[0].toString() : null,
|
id: row[0].toString(),
|
||||||
createdAt: fields.contains('created_at') ? (row[1] as DateTime?) : null,
|
createdAt: (row[1] as DateTime?),
|
||||||
updatedAt: fields.contains('updated_at') ? (row[2] as DateTime?) : null,
|
updatedAt: (row[2] as DateTime?),
|
||||||
rings: fields.contains('rings') ? (row[3] as int?) : null);
|
rings: (row[3] as int?));
|
||||||
if (row.length > 4) {
|
if (row.length > 4) {
|
||||||
var modelOpt = FruitQuery().parseRow(row.skip(4).take(5).toList());
|
var modelOpt = FruitQuery.parseRow(row.skip(4).take(5).toList());
|
||||||
modelOpt.ifPresent((m) {
|
modelOpt.ifPresent((m) {
|
||||||
model = model.copyWith(fruits: [m]);
|
model = model.copyWith(fruits: [m]);
|
||||||
});
|
});
|
||||||
|
@ -250,8 +240,6 @@ class FruitQuery extends Query<Fruit, FruitQueryWhere> {
|
||||||
@override
|
@override
|
||||||
final FruitQueryValues values = FruitQueryValues();
|
final FruitQueryValues values = FruitQueryValues();
|
||||||
|
|
||||||
List<String> _selectedFields = [];
|
|
||||||
|
|
||||||
FruitQueryWhere? _where;
|
FruitQueryWhere? _where;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -266,21 +254,7 @@ class FruitQuery extends Query<Fruit, FruitQueryWhere> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<String> get fields {
|
List<String> get fields {
|
||||||
const _fields = [
|
return const ['id', 'created_at', 'updated_at', 'tree_id', 'common_name'];
|
||||||
'id',
|
|
||||||
'created_at',
|
|
||||||
'updated_at',
|
|
||||||
'tree_id',
|
|
||||||
'common_name'
|
|
||||||
];
|
|
||||||
return _selectedFields.isEmpty
|
|
||||||
? _fields
|
|
||||||
: _fields.where((field) => _selectedFields.contains(field)).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
FruitQuery select(List<String> selectedFields) {
|
|
||||||
_selectedFields = selectedFields;
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -293,17 +267,16 @@ class FruitQuery extends Query<Fruit, FruitQueryWhere> {
|
||||||
return FruitQueryWhere(this);
|
return FruitQueryWhere(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Fruit> parseRow(List row) {
|
static Optional<Fruit> parseRow(List row) {
|
||||||
if (row.every((x) => x == null)) {
|
if (row.every((x) => x == null)) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
var model = Fruit(
|
var model = Fruit(
|
||||||
id: fields.contains('id') ? row[0].toString() : null,
|
id: row[0].toString(),
|
||||||
createdAt: fields.contains('created_at') ? (row[1] as DateTime?) : null,
|
createdAt: (row[1] as DateTime?),
|
||||||
updatedAt: fields.contains('updated_at') ? (row[2] as DateTime?) : null,
|
updatedAt: (row[2] as DateTime?),
|
||||||
treeId: fields.contains('tree_id') ? (row[3] as int?) : null,
|
treeId: (row[3] as int?),
|
||||||
commonName:
|
commonName: (row[4] as String?));
|
||||||
fields.contains('common_name') ? (row[4] as String?) : null);
|
|
||||||
return Optional.of(model);
|
return Optional.of(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -116,8 +116,6 @@ class UnorthodoxQuery extends Query<Unorthodox, UnorthodoxQueryWhere> {
|
||||||
@override
|
@override
|
||||||
final UnorthodoxQueryValues values = UnorthodoxQueryValues();
|
final UnorthodoxQueryValues values = UnorthodoxQueryValues();
|
||||||
|
|
||||||
List<String> _selectedFields = [];
|
|
||||||
|
|
||||||
UnorthodoxQueryWhere? _where;
|
UnorthodoxQueryWhere? _where;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -132,15 +130,7 @@ class UnorthodoxQuery extends Query<Unorthodox, UnorthodoxQueryWhere> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<String> get fields {
|
List<String> get fields {
|
||||||
const _fields = ['name'];
|
return const ['name'];
|
||||||
return _selectedFields.isEmpty
|
|
||||||
? _fields
|
|
||||||
: _fields.where((field) => _selectedFields.contains(field)).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
UnorthodoxQuery select(List<String> selectedFields) {
|
|
||||||
_selectedFields = selectedFields;
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -153,12 +143,11 @@ class UnorthodoxQuery extends Query<Unorthodox, UnorthodoxQueryWhere> {
|
||||||
return UnorthodoxQueryWhere(this);
|
return UnorthodoxQueryWhere(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Unorthodox> parseRow(List row) {
|
static Optional<Unorthodox> parseRow(List row) {
|
||||||
if (row.every((x) => x == null)) {
|
if (row.every((x) => x == null)) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
var model =
|
var model = Unorthodox(name: (row[0] as String?));
|
||||||
Unorthodox(name: fields.contains('name') ? (row[0] as String?) : null);
|
|
||||||
return Optional.of(model);
|
return Optional.of(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,8 +221,6 @@ class WeirdJoinQuery extends Query<WeirdJoin, WeirdJoinQueryWhere> {
|
||||||
@override
|
@override
|
||||||
final WeirdJoinQueryValues values = WeirdJoinQueryValues();
|
final WeirdJoinQueryValues values = WeirdJoinQueryValues();
|
||||||
|
|
||||||
List<String> _selectedFields = [];
|
|
||||||
|
|
||||||
WeirdJoinQueryWhere? _where;
|
WeirdJoinQueryWhere? _where;
|
||||||
|
|
||||||
late UnorthodoxQuery _unorthodox;
|
late UnorthodoxQuery _unorthodox;
|
||||||
|
@ -254,15 +241,7 @@ class WeirdJoinQuery extends Query<WeirdJoin, WeirdJoinQueryWhere> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<String> get fields {
|
List<String> get fields {
|
||||||
const _fields = ['id', 'join_name'];
|
return const ['id', 'join_name'];
|
||||||
return _selectedFields.isEmpty
|
|
||||||
? _fields
|
|
||||||
: _fields.where((field) => _selectedFields.contains(field)).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
WeirdJoinQuery select(List<String> selectedFields) {
|
|
||||||
_selectedFields = selectedFields;
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -275,31 +254,31 @@ class WeirdJoinQuery extends Query<WeirdJoin, WeirdJoinQueryWhere> {
|
||||||
return WeirdJoinQueryWhere(this);
|
return WeirdJoinQueryWhere(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<WeirdJoin> parseRow(List row) {
|
static Optional<WeirdJoin> parseRow(List row) {
|
||||||
if (row.every((x) => x == null)) {
|
if (row.every((x) => x == null)) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
var model = WeirdJoin(id: fields.contains('id') ? (row[0] as int?) : null);
|
var model = WeirdJoin(id: (row[0] as int?));
|
||||||
if (row.length > 2) {
|
if (row.length > 2) {
|
||||||
var modelOpt = UnorthodoxQuery().parseRow(row.skip(2).take(1).toList());
|
var modelOpt = UnorthodoxQuery.parseRow(row.skip(2).take(1).toList());
|
||||||
modelOpt.ifPresent((m) {
|
modelOpt.ifPresent((m) {
|
||||||
model = model.copyWith(unorthodox: m);
|
model = model.copyWith(unorthodox: m);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (row.length > 3) {
|
if (row.length > 3) {
|
||||||
var modelOpt = SongQuery().parseRow(row.skip(3).take(5).toList());
|
var modelOpt = SongQuery.parseRow(row.skip(3).take(5).toList());
|
||||||
modelOpt.ifPresent((m) {
|
modelOpt.ifPresent((m) {
|
||||||
model = model.copyWith(song: m);
|
model = model.copyWith(song: m);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (row.length > 8) {
|
if (row.length > 8) {
|
||||||
var modelOpt = NumbaQuery().parseRow(row.skip(8).take(2).toList());
|
var modelOpt = NumbaQuery.parseRow(row.skip(8).take(2).toList());
|
||||||
modelOpt.ifPresent((m) {
|
modelOpt.ifPresent((m) {
|
||||||
model = model.copyWith(numbas: [m]);
|
model = model.copyWith(numbas: [m]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (row.length > 10) {
|
if (row.length > 10) {
|
||||||
var modelOpt = FooQuery().parseRow(row.skip(10).take(1).toList());
|
var modelOpt = FooQuery.parseRow(row.skip(10).take(1).toList());
|
||||||
modelOpt.ifPresent((m) {
|
modelOpt.ifPresent((m) {
|
||||||
model = model.copyWith(foos: [m]);
|
model = model.copyWith(foos: [m]);
|
||||||
});
|
});
|
||||||
|
@ -437,8 +416,6 @@ class SongQuery extends Query<Song, SongQueryWhere> {
|
||||||
@override
|
@override
|
||||||
final SongQueryValues values = SongQueryValues();
|
final SongQueryValues values = SongQueryValues();
|
||||||
|
|
||||||
List<String> _selectedFields = [];
|
|
||||||
|
|
||||||
SongQueryWhere? _where;
|
SongQueryWhere? _where;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -453,21 +430,7 @@ class SongQuery extends Query<Song, SongQueryWhere> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<String> get fields {
|
List<String> get fields {
|
||||||
const _fields = [
|
return const ['id', 'created_at', 'updated_at', 'weird_join_id', 'title'];
|
||||||
'id',
|
|
||||||
'created_at',
|
|
||||||
'updated_at',
|
|
||||||
'weird_join_id',
|
|
||||||
'title'
|
|
||||||
];
|
|
||||||
return _selectedFields.isEmpty
|
|
||||||
? _fields
|
|
||||||
: _fields.where((field) => _selectedFields.contains(field)).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
SongQuery select(List<String> selectedFields) {
|
|
||||||
_selectedFields = selectedFields;
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -480,16 +443,16 @@ class SongQuery extends Query<Song, SongQueryWhere> {
|
||||||
return SongQueryWhere(this);
|
return SongQueryWhere(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Song> parseRow(List row) {
|
static Optional<Song> parseRow(List row) {
|
||||||
if (row.every((x) => x == null)) {
|
if (row.every((x) => x == null)) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
var model = Song(
|
var model = Song(
|
||||||
id: fields.contains('id') ? row[0].toString() : null,
|
id: row[0].toString(),
|
||||||
createdAt: fields.contains('created_at') ? (row[1] as DateTime?) : null,
|
createdAt: (row[1] as DateTime?),
|
||||||
updatedAt: fields.contains('updated_at') ? (row[2] as DateTime?) : null,
|
updatedAt: (row[2] as DateTime?),
|
||||||
weirdJoinId: fields.contains('weird_join_id') ? (row[3] as int?) : null,
|
weirdJoinId: (row[3] as int?),
|
||||||
title: fields.contains('title') ? (row[4] as String?) : null);
|
title: (row[4] as String?));
|
||||||
return Optional.of(model);
|
return Optional.of(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -572,8 +535,6 @@ class NumbaQuery extends Query<Numba, NumbaQueryWhere> {
|
||||||
@override
|
@override
|
||||||
final NumbaQueryValues values = NumbaQueryValues();
|
final NumbaQueryValues values = NumbaQueryValues();
|
||||||
|
|
||||||
List<String> _selectedFields = [];
|
|
||||||
|
|
||||||
NumbaQueryWhere? _where;
|
NumbaQueryWhere? _where;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -588,15 +549,7 @@ class NumbaQuery extends Query<Numba, NumbaQueryWhere> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<String> get fields {
|
List<String> get fields {
|
||||||
const _fields = ['i', 'parent'];
|
return const ['i', 'parent'];
|
||||||
return _selectedFields.isEmpty
|
|
||||||
? _fields
|
|
||||||
: _fields.where((field) => _selectedFields.contains(field)).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
NumbaQuery select(List<String> selectedFields) {
|
|
||||||
_selectedFields = selectedFields;
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -609,13 +562,11 @@ class NumbaQuery extends Query<Numba, NumbaQueryWhere> {
|
||||||
return NumbaQueryWhere(this);
|
return NumbaQueryWhere(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Numba> parseRow(List row) {
|
static Optional<Numba> parseRow(List row) {
|
||||||
if (row.every((x) => x == null)) {
|
if (row.every((x) => x == null)) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
var model = Numba(
|
var model = Numba(i: (row[0] as int?), parent: (row[1] as int?));
|
||||||
i: fields.contains('i') ? (row[0] as int?) : null,
|
|
||||||
parent: fields.contains('parent') ? (row[1] as int?) : null);
|
|
||||||
return Optional.of(model);
|
return Optional.of(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -678,8 +629,6 @@ class FooQuery extends Query<Foo, FooQueryWhere> {
|
||||||
@override
|
@override
|
||||||
final FooQueryValues values = FooQueryValues();
|
final FooQueryValues values = FooQueryValues();
|
||||||
|
|
||||||
List<String> _selectedFields = [];
|
|
||||||
|
|
||||||
FooQueryWhere? _where;
|
FooQueryWhere? _where;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -694,15 +643,7 @@ class FooQuery extends Query<Foo, FooQueryWhere> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<String> get fields {
|
List<String> get fields {
|
||||||
const _fields = ['bar'];
|
return const ['bar'];
|
||||||
return _selectedFields.isEmpty
|
|
||||||
? _fields
|
|
||||||
: _fields.where((field) => _selectedFields.contains(field)).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
FooQuery select(List<String> selectedFields) {
|
|
||||||
_selectedFields = selectedFields;
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -715,13 +656,13 @@ class FooQuery extends Query<Foo, FooQueryWhere> {
|
||||||
return FooQueryWhere(this);
|
return FooQueryWhere(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Foo> parseRow(List row) {
|
static Optional<Foo> parseRow(List row) {
|
||||||
if (row.every((x) => x == null)) {
|
if (row.every((x) => x == null)) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
var model = Foo(bar: fields.contains('bar') ? (row[0] as String?) : null);
|
var model = Foo(bar: (row[0] as String?));
|
||||||
if (row.length > 1) {
|
if (row.length > 1) {
|
||||||
var modelOpt = WeirdJoinQuery().parseRow(row.skip(1).take(2).toList());
|
var modelOpt = WeirdJoinQuery.parseRow(row.skip(1).take(2).toList());
|
||||||
modelOpt.ifPresent((m) {
|
modelOpt.ifPresent((m) {
|
||||||
model = model.copyWith(weirdJoins: [m]);
|
model = model.copyWith(weirdJoins: [m]);
|
||||||
});
|
});
|
||||||
|
@ -843,8 +784,6 @@ class FooPivotQuery extends Query<FooPivot, FooPivotQueryWhere> {
|
||||||
@override
|
@override
|
||||||
final FooPivotQueryValues values = FooPivotQueryValues();
|
final FooPivotQueryValues values = FooPivotQueryValues();
|
||||||
|
|
||||||
List<String> _selectedFields = [];
|
|
||||||
|
|
||||||
FooPivotQueryWhere? _where;
|
FooPivotQueryWhere? _where;
|
||||||
|
|
||||||
late WeirdJoinQuery _weirdJoin;
|
late WeirdJoinQuery _weirdJoin;
|
||||||
|
@ -863,15 +802,7 @@ class FooPivotQuery extends Query<FooPivot, FooPivotQueryWhere> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<String> get fields {
|
List<String> get fields {
|
||||||
const _fields = ['weird_join_id', 'foo_bar'];
|
return const ['weird_join_id', 'foo_bar'];
|
||||||
return _selectedFields.isEmpty
|
|
||||||
? _fields
|
|
||||||
: _fields.where((field) => _selectedFields.contains(field)).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
FooPivotQuery select(List<String> selectedFields) {
|
|
||||||
_selectedFields = selectedFields;
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -884,19 +815,19 @@ class FooPivotQuery extends Query<FooPivot, FooPivotQueryWhere> {
|
||||||
return FooPivotQueryWhere(this);
|
return FooPivotQueryWhere(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<FooPivot> parseRow(List row) {
|
static Optional<FooPivot> parseRow(List row) {
|
||||||
if (row.every((x) => x == null)) {
|
if (row.every((x) => x == null)) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
var model = FooPivot();
|
var model = FooPivot();
|
||||||
if (row.length > 2) {
|
if (row.length > 2) {
|
||||||
var modelOpt = WeirdJoinQuery().parseRow(row.skip(2).take(2).toList());
|
var modelOpt = WeirdJoinQuery.parseRow(row.skip(2).take(2).toList());
|
||||||
modelOpt.ifPresent((m) {
|
modelOpt.ifPresent((m) {
|
||||||
model = model.copyWith(weirdJoin: m);
|
model = model.copyWith(weirdJoin: m);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (row.length > 4) {
|
if (row.length > 4) {
|
||||||
var modelOpt = FooQuery().parseRow(row.skip(4).take(1).toList());
|
var modelOpt = FooQuery.parseRow(row.skip(4).take(1).toList());
|
||||||
modelOpt.ifPresent((m) {
|
modelOpt.ifPresent((m) {
|
||||||
model = model.copyWith(foo: m);
|
model = model.copyWith(foo: m);
|
||||||
});
|
});
|
||||||
|
|
|
@ -77,8 +77,6 @@ class UserQuery extends Query<User, UserQueryWhere> {
|
||||||
@override
|
@override
|
||||||
final UserQueryValues values = UserQueryValues();
|
final UserQueryValues values = UserQueryValues();
|
||||||
|
|
||||||
List<String> _selectedFields = [];
|
|
||||||
|
|
||||||
UserQueryWhere? _where;
|
UserQueryWhere? _where;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -93,7 +91,7 @@ class UserQuery extends Query<User, UserQueryWhere> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<String> get fields {
|
List<String> get fields {
|
||||||
const _fields = [
|
return const [
|
||||||
'id',
|
'id',
|
||||||
'created_at',
|
'created_at',
|
||||||
'updated_at',
|
'updated_at',
|
||||||
|
@ -101,14 +99,6 @@ class UserQuery extends Query<User, UserQueryWhere> {
|
||||||
'password',
|
'password',
|
||||||
'email'
|
'email'
|
||||||
];
|
];
|
||||||
return _selectedFields.isEmpty
|
|
||||||
? _fields
|
|
||||||
: _fields.where((field) => _selectedFields.contains(field)).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
UserQuery select(List<String> selectedFields) {
|
|
||||||
_selectedFields = selectedFields;
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -121,19 +111,19 @@ class UserQuery extends Query<User, UserQueryWhere> {
|
||||||
return UserQueryWhere(this);
|
return UserQueryWhere(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<User> parseRow(List row) {
|
static Optional<User> parseRow(List row) {
|
||||||
if (row.every((x) => x == null)) {
|
if (row.every((x) => x == null)) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
var model = User(
|
var model = User(
|
||||||
id: fields.contains('id') ? row[0].toString() : null,
|
id: row[0].toString(),
|
||||||
createdAt: fields.contains('created_at') ? (row[1] as DateTime?) : null,
|
createdAt: (row[1] as DateTime?),
|
||||||
updatedAt: fields.contains('updated_at') ? (row[2] as DateTime?) : null,
|
updatedAt: (row[2] as DateTime?),
|
||||||
username: fields.contains('username') ? (row[3] as String?) : null,
|
username: (row[3] as String?),
|
||||||
password: fields.contains('password') ? (row[4] as String?) : null,
|
password: (row[4] as String?),
|
||||||
email: fields.contains('email') ? (row[5] as String?) : null);
|
email: (row[5] as String?));
|
||||||
if (row.length > 6) {
|
if (row.length > 6) {
|
||||||
var modelOpt = RoleQuery().parseRow(row.skip(6).take(4).toList());
|
var modelOpt = RoleQuery.parseRow(row.skip(6).take(4).toList());
|
||||||
modelOpt.ifPresent((m) {
|
modelOpt.ifPresent((m) {
|
||||||
model = model.copyWith(roles: [m]);
|
model = model.copyWith(roles: [m]);
|
||||||
});
|
});
|
||||||
|
@ -305,8 +295,6 @@ class RoleUserQuery extends Query<RoleUser, RoleUserQueryWhere> {
|
||||||
@override
|
@override
|
||||||
final RoleUserQueryValues values = RoleUserQueryValues();
|
final RoleUserQueryValues values = RoleUserQueryValues();
|
||||||
|
|
||||||
List<String> _selectedFields = [];
|
|
||||||
|
|
||||||
RoleUserQueryWhere? _where;
|
RoleUserQueryWhere? _where;
|
||||||
|
|
||||||
late RoleQuery _role;
|
late RoleQuery _role;
|
||||||
|
@ -325,15 +313,7 @@ class RoleUserQuery extends Query<RoleUser, RoleUserQueryWhere> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<String> get fields {
|
List<String> get fields {
|
||||||
const _fields = ['role_id', 'user_id'];
|
return const ['role_id', 'user_id'];
|
||||||
return _selectedFields.isEmpty
|
|
||||||
? _fields
|
|
||||||
: _fields.where((field) => _selectedFields.contains(field)).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
RoleUserQuery select(List<String> selectedFields) {
|
|
||||||
_selectedFields = selectedFields;
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -346,19 +326,19 @@ class RoleUserQuery extends Query<RoleUser, RoleUserQueryWhere> {
|
||||||
return RoleUserQueryWhere(this);
|
return RoleUserQueryWhere(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<RoleUser> parseRow(List row) {
|
static Optional<RoleUser> parseRow(List row) {
|
||||||
if (row.every((x) => x == null)) {
|
if (row.every((x) => x == null)) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
var model = RoleUser();
|
var model = RoleUser();
|
||||||
if (row.length > 2) {
|
if (row.length > 2) {
|
||||||
var modelOpt = RoleQuery().parseRow(row.skip(2).take(4).toList());
|
var modelOpt = RoleQuery.parseRow(row.skip(2).take(4).toList());
|
||||||
modelOpt.ifPresent((m) {
|
modelOpt.ifPresent((m) {
|
||||||
model = model.copyWith(role: m);
|
model = model.copyWith(role: m);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (row.length > 6) {
|
if (row.length > 6) {
|
||||||
var modelOpt = UserQuery().parseRow(row.skip(6).take(6).toList());
|
var modelOpt = UserQuery.parseRow(row.skip(6).take(6).toList());
|
||||||
modelOpt.ifPresent((m) {
|
modelOpt.ifPresent((m) {
|
||||||
model = model.copyWith(user: m);
|
model = model.copyWith(user: m);
|
||||||
});
|
});
|
||||||
|
@ -444,8 +424,6 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
|
||||||
@override
|
@override
|
||||||
final RoleQueryValues values = RoleQueryValues();
|
final RoleQueryValues values = RoleQueryValues();
|
||||||
|
|
||||||
List<String> _selectedFields = [];
|
|
||||||
|
|
||||||
RoleQueryWhere? _where;
|
RoleQueryWhere? _where;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -460,15 +438,7 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<String> get fields {
|
List<String> get fields {
|
||||||
const _fields = ['id', 'created_at', 'updated_at', 'name'];
|
return const ['id', 'created_at', 'updated_at', 'name'];
|
||||||
return _selectedFields.isEmpty
|
|
||||||
? _fields
|
|
||||||
: _fields.where((field) => _selectedFields.contains(field)).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
RoleQuery select(List<String> selectedFields) {
|
|
||||||
_selectedFields = selectedFields;
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -481,17 +451,17 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
|
||||||
return RoleQueryWhere(this);
|
return RoleQueryWhere(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Role> parseRow(List row) {
|
static Optional<Role> parseRow(List row) {
|
||||||
if (row.every((x) => x == null)) {
|
if (row.every((x) => x == null)) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
var model = Role(
|
var model = Role(
|
||||||
id: fields.contains('id') ? row[0].toString() : null,
|
id: row[0].toString(),
|
||||||
createdAt: fields.contains('created_at') ? (row[1] as DateTime?) : null,
|
createdAt: (row[1] as DateTime?),
|
||||||
updatedAt: fields.contains('updated_at') ? (row[2] as DateTime?) : null,
|
updatedAt: (row[2] as DateTime?),
|
||||||
name: fields.contains('name') ? (row[3] as String?) : null);
|
name: (row[3] as String?));
|
||||||
if (row.length > 4) {
|
if (row.length > 4) {
|
||||||
var modelOpt = UserQuery().parseRow(row.skip(4).take(6).toList());
|
var modelOpt = UserQuery.parseRow(row.skip(4).take(6).toList());
|
||||||
modelOpt.ifPresent((m) {
|
modelOpt.ifPresent((m) {
|
||||||
model = model.copyWith(users: [m]);
|
model = model.copyWith(users: [m]);
|
||||||
});
|
});
|
||||||
|
|
|
@ -35,8 +35,6 @@ class WorldQuery extends Query<World, WorldQueryWhere> {
|
||||||
@override
|
@override
|
||||||
final WorldQueryValues values = WorldQueryValues();
|
final WorldQueryValues values = WorldQueryValues();
|
||||||
|
|
||||||
List<String> _selectedFields = [];
|
|
||||||
|
|
||||||
WorldQueryWhere? _where;
|
WorldQueryWhere? _where;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -51,15 +49,7 @@ class WorldQuery extends Query<World, WorldQueryWhere> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<String> get fields {
|
List<String> get fields {
|
||||||
const _fields = ['id', 'random_number'];
|
return const ['id', 'random_number'];
|
||||||
return _selectedFields.isEmpty
|
|
||||||
? _fields
|
|
||||||
: _fields.where((field) => _selectedFields.contains(field)).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
WorldQuery select(List<String> selectedFields) {
|
|
||||||
_selectedFields = selectedFields;
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -72,14 +62,11 @@ class WorldQuery extends Query<World, WorldQueryWhere> {
|
||||||
return WorldQueryWhere(this);
|
return WorldQueryWhere(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<World> parseRow(List row) {
|
static Optional<World> parseRow(List row) {
|
||||||
if (row.every((x) => x == null)) {
|
if (row.every((x) => x == null)) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
var model = World(
|
var model = World(id: (row[0] as int?), randomNumber: (row[1] as int?));
|
||||||
id: fields.contains('id') ? (row[0] as int?) : null,
|
|
||||||
randomNumber:
|
|
||||||
fields.contains('random_number') ? (row[1] as int?) : null);
|
|
||||||
return Optional.of(model);
|
return Optional.of(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue