Updated ORM test

This commit is contained in:
thomashii 2022-01-08 14:36:42 +08:00
parent c2faa16768
commit 44fc43a9e2
16 changed files with 549 additions and 191 deletions

View file

@ -24,6 +24,7 @@ jobs:
sdk: "2.15.1"
- id: angel3_framework_upgrade
name: angel3_framework; Upgrade depedencies
working-directory: packages/framework
run: dart pub upgrade
@ -53,6 +54,7 @@ jobs:
# Angel3 ORM
- id: angel3_orm_upgrade
name: angel3_orm; Upgrade depedencies
working-directory: packages/orm/angel_orm
run: dart pub upgrade
@ -67,29 +69,35 @@ jobs:
# Angel3 ORM Generator
- id: angel3_orm_generator_upgrade
name: angel3_orm_generator; Upgrade depedencies
working-directory: packages/orm/angel_orm_generator
run: dart pub upgrade
- name: angel3_generator_orm; Verify formatting
- name: angel3_orm_generator; Verify formatting
working-directory: packages/orm/angel_orm_generator
run: dart format --output=none --set-exit-if-changed .
# Consider passing '--fatal-infos' for slightly stricter analysis.
- name: angel3_generator_orm; Analyze source code
- name: angel3_orm_generator; Analyze source code
working-directory: packages/orm/angel_orm_generator
run: dart analyze .
# Angel3 ORM Test
- id: angel3_orm_test_upgrade
name: angel3_orm_test; Upgrade depedencies
working-directory: packages/orm/angel_orm_test
run: dart pub upgrade
- name: angel3_test_orm; Verify formatting
- name: angel3_orm_test; Run orm code generator
working-directory: packages/orm/angel_orm_test
run: dart run build_runner build --delete-conflicting-outputs
- name: angel3_orm_test; Verify formatting
working-directory: packages/orm/angel_orm_test
run: dart format --output=none --set-exit-if-changed .
# Consider passing '--fatal-infos' for slightly stricter analysis.
- name: angel3_test_orm; Analyze source code
- name: angel3_orm_test; Analyze source code
working-directory: packages/orm/angel_orm_test
run: dart analyze .

View file

@ -68,6 +68,8 @@ class BookQuery extends Query<Book, BookQueryWhere> {
@override
final BookQueryValues values = BookQueryValues();
List<String> _selectedFields = [];
BookQueryWhere? _where;
late AuthorQuery _author;
@ -86,7 +88,7 @@ class BookQuery extends Query<Book, BookQueryWhere> {
@override
List<String> get fields {
return const [
const _fields = [
'id',
'created_at',
'updated_at',
@ -94,6 +96,14 @@ class BookQuery extends Query<Book, BookQueryWhere> {
'partner_author_id',
'name'
];
return _selectedFields.isEmpty
? _fields
: _fields.where((field) => _selectedFields.contains(field)).toList();
}
BookQuery select(List<String> selectedFields) {
_selectedFields = selectedFields;
return this;
}
@override
@ -106,23 +116,23 @@ class BookQuery extends Query<Book, BookQueryWhere> {
return BookQueryWhere(this);
}
static Optional<Book> parseRow(List row) {
Optional<Book> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = Book(
id: row[0].toString(),
createdAt: (row[1] as DateTime?),
updatedAt: (row[2] as DateTime?),
name: (row[5] as String?));
id: fields.contains('id') ? row[0].toString() : null,
createdAt: fields.contains('created_at') ? (row[1] as DateTime?) : null,
updatedAt: fields.contains('updated_at') ? (row[2] as DateTime?) : null,
name: fields.contains('name') ? (row[5] as String?) : null);
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) {
model = model.copyWith(author: m);
});
}
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) {
model = model.copyWith(partnerAuthor: m);
});
@ -232,6 +242,8 @@ class AuthorQuery extends Query<Author, AuthorQueryWhere> {
@override
final AuthorQueryValues values = AuthorQueryValues();
List<String> _selectedFields = [];
AuthorQueryWhere? _where;
@override
@ -246,7 +258,15 @@ class AuthorQuery extends Query<Author, AuthorQueryWhere> {
@override
List<String> get fields {
return const ['id', 'created_at', 'updated_at', 'name'];
const _fields = ['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
@ -259,15 +279,15 @@ class AuthorQuery extends Query<Author, AuthorQueryWhere> {
return AuthorQueryWhere(this);
}
static Optional<Author> parseRow(List row) {
Optional<Author> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = Author(
id: row[0].toString(),
createdAt: (row[1] as DateTime?),
updatedAt: (row[2] as DateTime?),
name: (row[3] as String?));
id: fields.contains('id') ? row[0].toString() : null,
createdAt: fields.contains('created_at') ? (row[1] as DateTime?) : null,
updatedAt: fields.contains('updated_at') ? (row[2] as DateTime?) : null,
name: fields.contains('name') ? (row[3] as String?) : null);
return Optional.of(model);
}

View file

@ -40,6 +40,8 @@ class CarQuery extends Query<Car, CarQueryWhere> {
@override
final CarQueryValues values = CarQueryValues();
List<String> _selectedFields = [];
CarQueryWhere? _where;
@override
@ -54,7 +56,7 @@ class CarQuery extends Query<Car, CarQueryWhere> {
@override
List<String> get fields {
return const [
const _fields = [
'id',
'created_at',
'updated_at',
@ -63,6 +65,14 @@ class CarQuery extends Query<Car, CarQueryWhere> {
'family_friendly',
'recalled_at'
];
return _selectedFields.isEmpty
? _fields
: _fields.where((field) => _selectedFields.contains(field)).toList();
}
CarQuery select(List<String> selectedFields) {
_selectedFields = selectedFields;
return this;
}
@override
@ -75,18 +85,21 @@ class CarQuery extends Query<Car, CarQueryWhere> {
return CarQueryWhere(this);
}
static Optional<Car> parseRow(List row) {
Optional<Car> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = Car(
id: row[0].toString(),
createdAt: (row[1] as DateTime?),
updatedAt: (row[2] as DateTime?),
make: (row[3] as String?),
description: (row[4] as String?),
familyFriendly: (row[5] as bool?),
recalledAt: (row[6] as DateTime?));
id: fields.contains('id') ? row[0].toString() : null,
createdAt: fields.contains('created_at') ? (row[1] as DateTime?) : null,
updatedAt: fields.contains('updated_at') ? (row[2] as DateTime?) : null,
make: fields.contains('make') ? (row[3] as String?) : null,
description:
fields.contains('description') ? (row[4] as String?) : null,
familyFriendly:
fields.contains('family_friendly') ? (row[5] as bool?) : null,
recalledAt:
fields.contains('recalled_at') ? (row[6] as DateTime?) : null);
return Optional.of(model);
}

View file

@ -58,6 +58,8 @@ class NumbersQuery extends Query<Numbers, NumbersQueryWhere> {
@override
final NumbersQueryValues values = NumbersQueryValues();
List<String> _selectedFields = [];
NumbersQueryWhere? _where;
@override
@ -72,7 +74,15 @@ class NumbersQuery extends Query<Numbers, NumbersQueryWhere> {
@override
List<String> get fields {
return const ['id', 'created_at', 'updated_at', 'two'];
const _fields = ['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
@ -85,15 +95,15 @@ class NumbersQuery extends Query<Numbers, NumbersQueryWhere> {
return NumbersQueryWhere(this);
}
static Optional<Numbers> parseRow(List row) {
Optional<Numbers> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = Numbers(
id: row[0].toString(),
createdAt: (row[1] as DateTime?),
updatedAt: (row[2] as DateTime?),
two: (row[3] as int?));
id: fields.contains('id') ? row[0].toString() : null,
createdAt: fields.contains('created_at') ? (row[1] as DateTime?) : null,
updatedAt: fields.contains('updated_at') ? (row[2] as DateTime?) : null,
two: fields.contains('two') ? (row[3] as int?) : null);
return Optional.of(model);
}
@ -163,6 +173,8 @@ class AlphabetQuery extends Query<Alphabet, AlphabetQueryWhere> {
@override
final AlphabetQueryValues values = AlphabetQueryValues();
List<String> _selectedFields = [];
AlphabetQueryWhere? _where;
late NumbersQuery _numbers;
@ -179,7 +191,15 @@ class AlphabetQuery extends Query<Alphabet, AlphabetQueryWhere> {
@override
List<String> get fields {
return const ['id', 'created_at', 'updated_at', 'value', 'numbers_id'];
const _fields = ['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
@ -192,17 +212,17 @@ class AlphabetQuery extends Query<Alphabet, AlphabetQueryWhere> {
return AlphabetQueryWhere(this);
}
static Optional<Alphabet> parseRow(List row) {
Optional<Alphabet> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = Alphabet(
id: row[0].toString(),
createdAt: (row[1] as DateTime?),
updatedAt: (row[2] as DateTime?),
value: (row[3] as String?));
id: fields.contains('id') ? row[0].toString() : null,
createdAt: fields.contains('created_at') ? (row[1] as DateTime?) : null,
updatedAt: fields.contains('updated_at') ? (row[2] as DateTime?) : null,
value: fields.contains('value') ? (row[3] as String?) : null);
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) {
model = model.copyWith(numbers: m);
});

View file

@ -75,6 +75,8 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
@override
final RoleQueryValues values = RoleQueryValues();
List<String> _selectedFields = [];
RoleQueryWhere? _where;
@override
@ -89,7 +91,15 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
@override
List<String> get fields {
return const ['role'];
const _fields = ['role'];
return _selectedFields.isEmpty
? _fields
: _fields.where((field) => _selectedFields.contains(field)).toList();
}
RoleQuery select(List<String> selectedFields) {
_selectedFields = selectedFields;
return this;
}
@override
@ -102,13 +112,14 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
return RoleQueryWhere(this);
}
static Optional<Role> parseRow(List row) {
Optional<Role> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = Role(role: (row[0] as String?));
var model =
Role(role: fields.contains('role') ? (row[0] as String?) : null);
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) {
model = model.copyWith(users: [m]);
});
@ -228,6 +239,8 @@ class RoleUserQuery extends Query<RoleUser, RoleUserQueryWhere> {
@override
final RoleUserQueryValues values = RoleUserQueryValues();
List<String> _selectedFields = [];
RoleUserQueryWhere? _where;
late RoleQuery _role;
@ -246,7 +259,15 @@ class RoleUserQuery extends Query<RoleUser, RoleUserQueryWhere> {
@override
List<String> get fields {
return const ['role_role', 'user_email'];
const _fields = ['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
@ -259,19 +280,19 @@ class RoleUserQuery extends Query<RoleUser, RoleUserQueryWhere> {
return RoleUserQueryWhere(this);
}
static Optional<RoleUser> parseRow(List row) {
Optional<RoleUser> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = RoleUser();
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) {
model = model.copyWith(role: m);
});
}
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) {
model = model.copyWith(user: m);
});
@ -350,6 +371,8 @@ class UserQuery extends Query<User, UserQueryWhere> {
@override
final UserQueryValues values = UserQueryValues();
List<String> _selectedFields = [];
UserQueryWhere? _where;
@override
@ -364,7 +387,15 @@ class UserQuery extends Query<User, UserQueryWhere> {
@override
List<String> get fields {
return const ['email', 'name', 'password'];
const _fields = ['email', 'name', 'password'];
return _selectedFields.isEmpty
? _fields
: _fields.where((field) => _selectedFields.contains(field)).toList();
}
UserQuery select(List<String> selectedFields) {
_selectedFields = selectedFields;
return this;
}
@override
@ -377,16 +408,16 @@ class UserQuery extends Query<User, UserQueryWhere> {
return UserQueryWhere(this);
}
static Optional<User> parseRow(List row) {
Optional<User> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = User(
email: (row[0] as String?),
name: (row[1] as String?),
password: (row[2] as String?));
email: fields.contains('email') ? (row[0] as String?) : null,
name: fields.contains('name') ? (row[1] as String?) : null,
password: fields.contains('password') ? (row[2] as String?) : null);
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) {
model = model.copyWith(roles: [m]);
});

View file

@ -36,6 +36,8 @@ class FortuneQuery extends Query<Fortune, FortuneQueryWhere> {
@override
final FortuneQueryValues values = FortuneQueryValues();
List<String> _selectedFields = [];
FortuneQueryWhere? _where;
@override
@ -50,7 +52,15 @@ class FortuneQuery extends Query<Fortune, FortuneQueryWhere> {
@override
List<String> get fields {
return const ['id', 'message'];
const _fields = ['id', 'message'];
return _selectedFields.isEmpty
? _fields
: _fields.where((field) => _selectedFields.contains(field)).toList();
}
FortuneQuery select(List<String> selectedFields) {
_selectedFields = selectedFields;
return this;
}
@override
@ -63,11 +73,13 @@ class FortuneQuery extends Query<Fortune, FortuneQueryWhere> {
return FortuneQueryWhere(this);
}
static Optional<Fortune> parseRow(List row) {
Optional<Fortune> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = Fortune(id: (row[0] as int?), message: (row[1] as String?));
var model = Fortune(
id: fields.contains('id') ? (row[0] as int?) : null,
message: fields.contains('message') ? (row[1] as String?) : null);
return Optional.of(model);
}

View file

@ -38,6 +38,8 @@ class HasCarQuery extends Query<HasCar, HasCarQueryWhere> {
@override
final HasCarQueryValues values = HasCarQueryValues();
List<String> _selectedFields = [];
HasCarQueryWhere? _where;
@override
@ -52,7 +54,15 @@ class HasCarQuery extends Query<HasCar, HasCarQueryWhere> {
@override
List<String> get fields {
return const ['id', 'created_at', 'updated_at', 'type'];
const _fields = ['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
@ -65,15 +75,19 @@ class HasCarQuery extends Query<HasCar, HasCarQueryWhere> {
return HasCarQueryWhere(this);
}
static Optional<HasCar> parseRow(List row) {
Optional<HasCar> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = HasCar(
id: row[0].toString(),
createdAt: (row[1] as DateTime?),
updatedAt: (row[2] as DateTime?),
type: row[3] == null ? null : CarType?.values[(row[3] as int)]);
id: fields.contains('id') ? row[0].toString() : null,
createdAt: fields.contains('created_at') ? (row[1] as DateTime?) : null,
updatedAt: fields.contains('updated_at') ? (row[2] as DateTime?) : null,
type: fields.contains('type')
? row[3] == null
? null
: CarType?.values[(row[3] as int)]
: null);
return Optional.of(model);
}

View file

@ -38,6 +38,8 @@ class HasMapQuery extends Query<HasMap, HasMapQueryWhere> {
@override
final HasMapQueryValues values = HasMapQueryValues();
List<String> _selectedFields = [];
HasMapQueryWhere? _where;
@override
@ -52,7 +54,15 @@ class HasMapQuery extends Query<HasMap, HasMapQueryWhere> {
@override
List<String> get fields {
return const ['value', 'list'];
const _fields = ['value', 'list'];
return _selectedFields.isEmpty
? _fields
: _fields.where((field) => _selectedFields.contains(field)).toList();
}
HasMapQuery select(List<String> selectedFields) {
_selectedFields = selectedFields;
return this;
}
@override
@ -65,13 +75,15 @@ class HasMapQuery extends Query<HasMap, HasMapQueryWhere> {
return HasMapQueryWhere(this);
}
static Optional<HasMap> parseRow(List row) {
Optional<HasMap> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = HasMap(
value: (row[0] as Map<dynamic, dynamic>?),
list: (row[1] as List<dynamic>?));
value: fields.contains('value')
? (row[0] as Map<dynamic, dynamic>?)
: null,
list: fields.contains('list') ? (row[1] as List<dynamic>?) : null);
return Optional.of(model);
}

View file

@ -66,6 +66,8 @@ class LegQuery extends Query<Leg, LegQueryWhere> {
@override
final LegQueryValues values = LegQueryValues();
List<String> _selectedFields = [];
LegQueryWhere? _where;
late FootQuery _foot;
@ -82,7 +84,15 @@ class LegQuery extends Query<Leg, LegQueryWhere> {
@override
List<String> get fields {
return const ['id', 'created_at', 'updated_at', 'name'];
const _fields = ['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
@ -95,17 +105,17 @@ class LegQuery extends Query<Leg, LegQueryWhere> {
return LegQueryWhere(this);
}
static Optional<Leg> parseRow(List row) {
Optional<Leg> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = Leg(
id: row[0].toString(),
createdAt: (row[1] as DateTime?),
updatedAt: (row[2] as DateTime?),
name: (row[3] as String?));
id: fields.contains('id') ? row[0].toString() : null,
createdAt: fields.contains('created_at') ? (row[1] as DateTime?) : null,
updatedAt: fields.contains('updated_at') ? (row[2] as DateTime?) : null,
name: fields.contains('name') ? (row[3] as String?) : null);
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) {
model = model.copyWith(foot: m);
});
@ -187,6 +197,8 @@ class FootQuery extends Query<Foot, FootQueryWhere> {
@override
final FootQueryValues values = FootQueryValues();
List<String> _selectedFields = [];
FootQueryWhere? _where;
@override
@ -201,7 +213,15 @@ class FootQuery extends Query<Foot, FootQueryWhere> {
@override
List<String> get fields {
return const ['id', 'created_at', 'updated_at', 'leg_id', 'n_toes'];
const _fields = ['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
@ -214,16 +234,18 @@ class FootQuery extends Query<Foot, FootQueryWhere> {
return FootQueryWhere(this);
}
static Optional<Foot> parseRow(List row) {
Optional<Foot> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = Foot(
id: row[0].toString(),
createdAt: (row[1] as DateTime?),
updatedAt: (row[2] as DateTime?),
legId: (row[3] as int?),
nToes: double.tryParse(row[4].toString()));
id: fields.contains('id') ? row[0].toString() : null,
createdAt: fields.contains('created_at') ? (row[1] as DateTime?) : null,
updatedAt: fields.contains('updated_at') ? (row[2] as DateTime?) : null,
legId: fields.contains('leg_id') ? (row[3] as int?) : null,
nToes: fields.contains('n_toes')
? double.tryParse(row[4].toString())
: null);
return Optional.of(model);
}

View file

@ -62,6 +62,8 @@ class OrderQuery extends Query<Order, OrderQueryWhere> {
@override
final OrderQueryValues values = OrderQueryValues();
List<String> _selectedFields = [];
OrderQueryWhere? _where;
late CustomerQuery _customer;
@ -78,7 +80,7 @@ class OrderQuery extends Query<Order, OrderQueryWhere> {
@override
List<String> get fields {
return const [
const _fields = [
'id',
'created_at',
'updated_at',
@ -87,6 +89,14 @@ class OrderQuery extends Query<Order, OrderQueryWhere> {
'order_date',
'shipper_id'
];
return _selectedFields.isEmpty
? _fields
: _fields.where((field) => _selectedFields.contains(field)).toList();
}
OrderQuery select(List<String> selectedFields) {
_selectedFields = selectedFields;
return this;
}
@override
@ -99,19 +109,19 @@ class OrderQuery extends Query<Order, OrderQueryWhere> {
return OrderQueryWhere(this);
}
static Optional<Order> parseRow(List row) {
Optional<Order> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = Order(
id: row[0].toString(),
createdAt: (row[1] as DateTime?),
updatedAt: (row[2] as DateTime?),
employeeId: (row[4] as int?),
orderDate: (row[5] as DateTime?),
shipperId: (row[6] as int?));
id: fields.contains('id') ? row[0].toString() : null,
createdAt: fields.contains('created_at') ? (row[1] as DateTime?) : null,
updatedAt: fields.contains('updated_at') ? (row[2] as DateTime?) : null,
employeeId: fields.contains('employee_id') ? (row[4] as int?) : null,
orderDate: fields.contains('order_date') ? (row[5] as DateTime?) : null,
shipperId: fields.contains('shipper_id') ? (row[6] as int?) : null);
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) {
model = model.copyWith(customer: m);
});
@ -231,6 +241,8 @@ class CustomerQuery extends Query<Customer, CustomerQueryWhere> {
@override
final CustomerQueryValues values = CustomerQueryValues();
List<String> _selectedFields = [];
CustomerQueryWhere? _where;
@override
@ -245,7 +257,15 @@ class CustomerQuery extends Query<Customer, CustomerQueryWhere> {
@override
List<String> get fields {
return const ['id', 'created_at', 'updated_at'];
const _fields = ['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
@ -258,14 +278,15 @@ class CustomerQuery extends Query<Customer, CustomerQueryWhere> {
return CustomerQueryWhere(this);
}
static Optional<Customer> parseRow(List row) {
Optional<Customer> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = Customer(
id: row[0].toString(),
createdAt: (row[1] as DateTime?),
updatedAt: (row[2] as DateTime?));
id: fields.contains('id') ? row[0].toString() : null,
createdAt: fields.contains('created_at') ? (row[1] as DateTime?) : null,
updatedAt:
fields.contains('updated_at') ? (row[2] as DateTime?) : null);
return Optional.of(model);
}

View file

@ -39,6 +39,8 @@ class PersonQuery extends Query<Person, PersonQueryWhere> {
@override
final PersonQueryValues values = PersonQueryValues();
List<String> _selectedFields = [];
PersonQueryWhere? _where;
@override
@ -53,7 +55,15 @@ class PersonQuery extends Query<Person, PersonQueryWhere> {
@override
List<String> get fields {
return const ['id', 'created_at', 'updated_at', 'name', 'age'];
const _fields = ['id', 'created_at', 'updated_at', 'name', 'age'];
return _selectedFields.isEmpty
? _fields
: _fields.where((field) => _selectedFields.contains(field)).toList();
}
PersonQuery select(List<String> selectedFields) {
_selectedFields = selectedFields;
return this;
}
@override
@ -66,16 +76,16 @@ class PersonQuery extends Query<Person, PersonQueryWhere> {
return PersonQueryWhere(this);
}
static Optional<Person> parseRow(List row) {
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?));
id: fields.contains('id') ? row[0].toString() : null,
createdAt: fields.contains('created_at') ? (row[1] as DateTime?) : null,
updatedAt: fields.contains('updated_at') ? (row[2] as DateTime?) : null,
name: fields.contains('name') ? (row[3] as String?) : null,
age: fields.contains('age') ? (row[4] as int?) : null);
return Optional.of(model);
}
@ -163,6 +173,8 @@ class PersonWithLastOrderQuery
final PersonWithLastOrderQueryValues values =
PersonWithLastOrderQueryValues();
List<String> _selectedFields = [];
PersonWithLastOrderQueryWhere? _where;
@override
@ -177,7 +189,15 @@ class PersonWithLastOrderQuery
@override
List<String> get fields {
return const ['name', 'last_order_name', 'last_order_price'];
const _fields = ['name', 'last_order_name', 'last_order_price'];
return _selectedFields.isEmpty
? _fields
: _fields.where((field) => _selectedFields.contains(field)).toList();
}
PersonWithLastOrderQuery select(List<String> selectedFields) {
_selectedFields = selectedFields;
return this;
}
@override
@ -190,14 +210,16 @@ class PersonWithLastOrderQuery
return PersonWithLastOrderQueryWhere(this);
}
static Optional<PersonWithLastOrder> parseRow(List row) {
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?));
name: fields.contains('name') ? (row[0] as String?) : null,
lastOrderName:
fields.contains('last_order_name') ? (row[1] as String?) : null,
lastOrderPrice:
fields.contains('last_order_price') ? (row[2] as int?) : null);
return Optional.of(model);
}

View file

@ -42,6 +42,8 @@ class PersonOrderQuery extends Query<PersonOrder, PersonOrderQueryWhere> {
@override
final PersonOrderQueryValues values = PersonOrderQueryValues();
List<String> _selectedFields = [];
PersonOrderQueryWhere? _where;
@override
@ -56,7 +58,7 @@ class PersonOrderQuery extends Query<PersonOrder, PersonOrderQueryWhere> {
@override
List<String> get fields {
return const [
const _fields = [
'id',
'created_at',
'updated_at',
@ -65,6 +67,14 @@ class PersonOrderQuery extends Query<PersonOrder, PersonOrderQueryWhere> {
'price',
'deleted'
];
return _selectedFields.isEmpty
? _fields
: _fields.where((field) => _selectedFields.contains(field)).toList();
}
PersonOrderQuery select(List<String> selectedFields) {
_selectedFields = selectedFields;
return this;
}
@override
@ -77,18 +87,20 @@ class PersonOrderQuery extends Query<PersonOrder, PersonOrderQueryWhere> {
return PersonOrderQueryWhere(this);
}
static Optional<PersonOrder> parseRow(List row) {
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?));
id: fields.contains('id') ? row[0].toString() : null,
createdAt: fields.contains('created_at') ? (row[1] as DateTime?) : null,
updatedAt: fields.contains('updated_at') ? (row[2] as DateTime?) : null,
personId: fields.contains('person_id') ? (row[3] as int?) : null,
name: fields.contains('name') ? (row[4] as String?) : null,
price: fields.contains('price')
? double.tryParse(row[5].toString())
: null,
deleted: fields.contains('deleted') ? (row[6] as bool?) : null);
return Optional.of(model);
}
@ -194,6 +206,8 @@ class OrderWithPersonInfoQuery
final OrderWithPersonInfoQueryValues values =
OrderWithPersonInfoQueryValues();
List<String> _selectedFields = [];
OrderWithPersonInfoQueryWhere? _where;
@override
@ -208,7 +222,7 @@ class OrderWithPersonInfoQuery
@override
List<String> get fields {
return const [
const _fields = [
'id',
'created_at',
'updated_at',
@ -218,6 +232,14 @@ class OrderWithPersonInfoQuery
'person_name',
'person_age'
];
return _selectedFields.isEmpty
? _fields
: _fields.where((field) => _selectedFields.contains(field)).toList();
}
OrderWithPersonInfoQuery select(List<String> selectedFields) {
_selectedFields = selectedFields;
return this;
}
@override
@ -230,19 +252,21 @@ class OrderWithPersonInfoQuery
return OrderWithPersonInfoQueryWhere(this);
}
static Optional<OrderWithPersonInfo> parseRow(List row) {
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?));
id: fields.contains('id') ? row[0].toString() : null,
createdAt: fields.contains('created_at') ? (row[1] as DateTime?) : null,
updatedAt: fields.contains('updated_at') ? (row[2] as DateTime?) : null,
name: fields.contains('name') ? (row[3] as String?) : null,
price: fields.contains('price')
? double.tryParse(row[4].toString())
: null,
deleted: fields.contains('deleted') ? (row[5] as bool?) : null,
personName: fields.contains('person_name') ? (row[6] as String?) : null,
personAge: fields.contains('person_age') ? (row[7] as int?) : null);
return Optional.of(model);
}

View file

@ -65,6 +65,8 @@ class TreeQuery extends Query<Tree, TreeQueryWhere> {
@override
final TreeQueryValues values = TreeQueryValues();
List<String> _selectedFields = [];
TreeQueryWhere? _where;
late FruitQuery _fruits;
@ -81,7 +83,15 @@ class TreeQuery extends Query<Tree, TreeQueryWhere> {
@override
List<String> get fields {
return const ['id', 'created_at', 'updated_at', 'rings'];
const _fields = ['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
@ -94,17 +104,17 @@ class TreeQuery extends Query<Tree, TreeQueryWhere> {
return TreeQueryWhere(this);
}
static Optional<Tree> parseRow(List row) {
Optional<Tree> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = Tree(
id: row[0].toString(),
createdAt: (row[1] as DateTime?),
updatedAt: (row[2] as DateTime?),
rings: (row[3] as int?));
id: fields.contains('id') ? row[0].toString() : null,
createdAt: fields.contains('created_at') ? (row[1] as DateTime?) : null,
updatedAt: fields.contains('updated_at') ? (row[2] as DateTime?) : null,
rings: fields.contains('rings') ? (row[3] as int?) : null);
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) {
model = model.copyWith(fruits: [m]);
});
@ -240,6 +250,8 @@ class FruitQuery extends Query<Fruit, FruitQueryWhere> {
@override
final FruitQueryValues values = FruitQueryValues();
List<String> _selectedFields = [];
FruitQueryWhere? _where;
@override
@ -254,7 +266,21 @@ class FruitQuery extends Query<Fruit, FruitQueryWhere> {
@override
List<String> get fields {
return const ['id', 'created_at', 'updated_at', 'tree_id', 'common_name'];
const _fields = [
'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
@ -267,16 +293,17 @@ class FruitQuery extends Query<Fruit, FruitQueryWhere> {
return FruitQueryWhere(this);
}
static Optional<Fruit> parseRow(List row) {
Optional<Fruit> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = Fruit(
id: row[0].toString(),
createdAt: (row[1] as DateTime?),
updatedAt: (row[2] as DateTime?),
treeId: (row[3] as int?),
commonName: (row[4] as String?));
id: fields.contains('id') ? row[0].toString() : null,
createdAt: fields.contains('created_at') ? (row[1] as DateTime?) : null,
updatedAt: fields.contains('updated_at') ? (row[2] as DateTime?) : null,
treeId: fields.contains('tree_id') ? (row[3] as int?) : null,
commonName:
fields.contains('common_name') ? (row[4] as String?) : null);
return Optional.of(model);
}

View file

@ -116,6 +116,8 @@ class UnorthodoxQuery extends Query<Unorthodox, UnorthodoxQueryWhere> {
@override
final UnorthodoxQueryValues values = UnorthodoxQueryValues();
List<String> _selectedFields = [];
UnorthodoxQueryWhere? _where;
@override
@ -130,7 +132,15 @@ class UnorthodoxQuery extends Query<Unorthodox, UnorthodoxQueryWhere> {
@override
List<String> get fields {
return const ['name'];
const _fields = ['name'];
return _selectedFields.isEmpty
? _fields
: _fields.where((field) => _selectedFields.contains(field)).toList();
}
UnorthodoxQuery select(List<String> selectedFields) {
_selectedFields = selectedFields;
return this;
}
@override
@ -143,11 +153,12 @@ class UnorthodoxQuery extends Query<Unorthodox, UnorthodoxQueryWhere> {
return UnorthodoxQueryWhere(this);
}
static Optional<Unorthodox> parseRow(List row) {
Optional<Unorthodox> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = Unorthodox(name: (row[0] as String?));
var model =
Unorthodox(name: fields.contains('name') ? (row[0] as String?) : null);
return Optional.of(model);
}
@ -221,6 +232,8 @@ class WeirdJoinQuery extends Query<WeirdJoin, WeirdJoinQueryWhere> {
@override
final WeirdJoinQueryValues values = WeirdJoinQueryValues();
List<String> _selectedFields = [];
WeirdJoinQueryWhere? _where;
late UnorthodoxQuery _unorthodox;
@ -241,7 +254,15 @@ class WeirdJoinQuery extends Query<WeirdJoin, WeirdJoinQueryWhere> {
@override
List<String> get fields {
return const ['id', 'join_name'];
const _fields = ['id', 'join_name'];
return _selectedFields.isEmpty
? _fields
: _fields.where((field) => _selectedFields.contains(field)).toList();
}
WeirdJoinQuery select(List<String> selectedFields) {
_selectedFields = selectedFields;
return this;
}
@override
@ -254,31 +275,31 @@ class WeirdJoinQuery extends Query<WeirdJoin, WeirdJoinQueryWhere> {
return WeirdJoinQueryWhere(this);
}
static Optional<WeirdJoin> parseRow(List row) {
Optional<WeirdJoin> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = WeirdJoin(id: (row[0] as int?));
var model = WeirdJoin(id: fields.contains('id') ? (row[0] as int?) : null);
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) {
model = model.copyWith(unorthodox: m);
});
}
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) {
model = model.copyWith(song: m);
});
}
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) {
model = model.copyWith(numbas: [m]);
});
}
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) {
model = model.copyWith(foos: [m]);
});
@ -416,6 +437,8 @@ class SongQuery extends Query<Song, SongQueryWhere> {
@override
final SongQueryValues values = SongQueryValues();
List<String> _selectedFields = [];
SongQueryWhere? _where;
@override
@ -430,7 +453,21 @@ class SongQuery extends Query<Song, SongQueryWhere> {
@override
List<String> get fields {
return const ['id', 'created_at', 'updated_at', 'weird_join_id', 'title'];
const _fields = [
'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
@ -443,16 +480,16 @@ class SongQuery extends Query<Song, SongQueryWhere> {
return SongQueryWhere(this);
}
static Optional<Song> parseRow(List row) {
Optional<Song> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = Song(
id: row[0].toString(),
createdAt: (row[1] as DateTime?),
updatedAt: (row[2] as DateTime?),
weirdJoinId: (row[3] as int?),
title: (row[4] as String?));
id: fields.contains('id') ? row[0].toString() : null,
createdAt: fields.contains('created_at') ? (row[1] as DateTime?) : null,
updatedAt: fields.contains('updated_at') ? (row[2] as DateTime?) : null,
weirdJoinId: fields.contains('weird_join_id') ? (row[3] as int?) : null,
title: fields.contains('title') ? (row[4] as String?) : null);
return Optional.of(model);
}
@ -535,6 +572,8 @@ class NumbaQuery extends Query<Numba, NumbaQueryWhere> {
@override
final NumbaQueryValues values = NumbaQueryValues();
List<String> _selectedFields = [];
NumbaQueryWhere? _where;
@override
@ -549,7 +588,15 @@ class NumbaQuery extends Query<Numba, NumbaQueryWhere> {
@override
List<String> get fields {
return const ['i', 'parent'];
const _fields = ['i', 'parent'];
return _selectedFields.isEmpty
? _fields
: _fields.where((field) => _selectedFields.contains(field)).toList();
}
NumbaQuery select(List<String> selectedFields) {
_selectedFields = selectedFields;
return this;
}
@override
@ -562,11 +609,13 @@ class NumbaQuery extends Query<Numba, NumbaQueryWhere> {
return NumbaQueryWhere(this);
}
static Optional<Numba> parseRow(List row) {
Optional<Numba> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = Numba(i: (row[0] as int?), parent: (row[1] as int?));
var model = Numba(
i: fields.contains('i') ? (row[0] as int?) : null,
parent: fields.contains('parent') ? (row[1] as int?) : null);
return Optional.of(model);
}
@ -629,6 +678,8 @@ class FooQuery extends Query<Foo, FooQueryWhere> {
@override
final FooQueryValues values = FooQueryValues();
List<String> _selectedFields = [];
FooQueryWhere? _where;
@override
@ -643,7 +694,15 @@ class FooQuery extends Query<Foo, FooQueryWhere> {
@override
List<String> get fields {
return const ['bar'];
const _fields = ['bar'];
return _selectedFields.isEmpty
? _fields
: _fields.where((field) => _selectedFields.contains(field)).toList();
}
FooQuery select(List<String> selectedFields) {
_selectedFields = selectedFields;
return this;
}
@override
@ -656,13 +715,13 @@ class FooQuery extends Query<Foo, FooQueryWhere> {
return FooQueryWhere(this);
}
static Optional<Foo> parseRow(List row) {
Optional<Foo> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = Foo(bar: (row[0] as String?));
var model = Foo(bar: fields.contains('bar') ? (row[0] as String?) : null);
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) {
model = model.copyWith(weirdJoins: [m]);
});
@ -784,6 +843,8 @@ class FooPivotQuery extends Query<FooPivot, FooPivotQueryWhere> {
@override
final FooPivotQueryValues values = FooPivotQueryValues();
List<String> _selectedFields = [];
FooPivotQueryWhere? _where;
late WeirdJoinQuery _weirdJoin;
@ -802,7 +863,15 @@ class FooPivotQuery extends Query<FooPivot, FooPivotQueryWhere> {
@override
List<String> get fields {
return const ['weird_join_id', 'foo_bar'];
const _fields = ['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
@ -815,19 +884,19 @@ class FooPivotQuery extends Query<FooPivot, FooPivotQueryWhere> {
return FooPivotQueryWhere(this);
}
static Optional<FooPivot> parseRow(List row) {
Optional<FooPivot> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = FooPivot();
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) {
model = model.copyWith(weirdJoin: m);
});
}
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) {
model = model.copyWith(foo: m);
});

View file

@ -77,6 +77,8 @@ class UserQuery extends Query<User, UserQueryWhere> {
@override
final UserQueryValues values = UserQueryValues();
List<String> _selectedFields = [];
UserQueryWhere? _where;
@override
@ -91,7 +93,7 @@ class UserQuery extends Query<User, UserQueryWhere> {
@override
List<String> get fields {
return const [
const _fields = [
'id',
'created_at',
'updated_at',
@ -99,6 +101,14 @@ class UserQuery extends Query<User, UserQueryWhere> {
'password',
'email'
];
return _selectedFields.isEmpty
? _fields
: _fields.where((field) => _selectedFields.contains(field)).toList();
}
UserQuery select(List<String> selectedFields) {
_selectedFields = selectedFields;
return this;
}
@override
@ -111,19 +121,19 @@ class UserQuery extends Query<User, UserQueryWhere> {
return UserQueryWhere(this);
}
static Optional<User> parseRow(List row) {
Optional<User> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = User(
id: row[0].toString(),
createdAt: (row[1] as DateTime?),
updatedAt: (row[2] as DateTime?),
username: (row[3] as String?),
password: (row[4] as String?),
email: (row[5] as String?));
id: fields.contains('id') ? row[0].toString() : null,
createdAt: fields.contains('created_at') ? (row[1] as DateTime?) : null,
updatedAt: fields.contains('updated_at') ? (row[2] as DateTime?) : null,
username: fields.contains('username') ? (row[3] as String?) : null,
password: fields.contains('password') ? (row[4] as String?) : null,
email: fields.contains('email') ? (row[5] as String?) : null);
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) {
model = model.copyWith(roles: [m]);
});
@ -295,6 +305,8 @@ class RoleUserQuery extends Query<RoleUser, RoleUserQueryWhere> {
@override
final RoleUserQueryValues values = RoleUserQueryValues();
List<String> _selectedFields = [];
RoleUserQueryWhere? _where;
late RoleQuery _role;
@ -313,7 +325,15 @@ class RoleUserQuery extends Query<RoleUser, RoleUserQueryWhere> {
@override
List<String> get fields {
return const ['role_id', 'user_id'];
const _fields = ['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
@ -326,19 +346,19 @@ class RoleUserQuery extends Query<RoleUser, RoleUserQueryWhere> {
return RoleUserQueryWhere(this);
}
static Optional<RoleUser> parseRow(List row) {
Optional<RoleUser> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = RoleUser();
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) {
model = model.copyWith(role: m);
});
}
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) {
model = model.copyWith(user: m);
});
@ -424,6 +444,8 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
@override
final RoleQueryValues values = RoleQueryValues();
List<String> _selectedFields = [];
RoleQueryWhere? _where;
@override
@ -438,7 +460,15 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
@override
List<String> get fields {
return const ['id', 'created_at', 'updated_at', 'name'];
const _fields = ['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
@ -451,17 +481,17 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
return RoleQueryWhere(this);
}
static Optional<Role> parseRow(List row) {
Optional<Role> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = Role(
id: row[0].toString(),
createdAt: (row[1] as DateTime?),
updatedAt: (row[2] as DateTime?),
name: (row[3] as String?));
id: fields.contains('id') ? row[0].toString() : null,
createdAt: fields.contains('created_at') ? (row[1] as DateTime?) : null,
updatedAt: fields.contains('updated_at') ? (row[2] as DateTime?) : null,
name: fields.contains('name') ? (row[3] as String?) : null);
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) {
model = model.copyWith(users: [m]);
});

View file

@ -35,6 +35,8 @@ class WorldQuery extends Query<World, WorldQueryWhere> {
@override
final WorldQueryValues values = WorldQueryValues();
List<String> _selectedFields = [];
WorldQueryWhere? _where;
@override
@ -49,7 +51,15 @@ class WorldQuery extends Query<World, WorldQueryWhere> {
@override
List<String> get fields {
return const ['id', 'random_number'];
const _fields = ['id', 'random_number'];
return _selectedFields.isEmpty
? _fields
: _fields.where((field) => _selectedFields.contains(field)).toList();
}
WorldQuery select(List<String> selectedFields) {
_selectedFields = selectedFields;
return this;
}
@override
@ -62,11 +72,14 @@ class WorldQuery extends Query<World, WorldQueryWhere> {
return WorldQueryWhere(this);
}
static Optional<World> parseRow(List row) {
Optional<World> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = World(id: (row[0] as int?), randomNumber: (row[1] as int?));
var model = World(
id: fields.contains('id') ? (row[0] as int?) : null,
randomNumber:
fields.contains('random_number') ? (row[1] as int?) : null);
return Optional.of(model);
}