Merge pull request #43 from debuggerx01/master

Add 'where.raw(String whereSql)'
This commit is contained in:
Thomas Hii 2022-01-08 13:33:39 +08:00 committed by GitHub
commit 8adb18662d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 1797 additions and 689 deletions

View file

@ -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);
}
}

View file

@ -1,18 +1,19 @@
import 'dart:async';
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 'main.g.dart';
part 'main.serializer.g.dart';
void main() async {
var query = EmployeeQuery()
..where?.firstName.equals('Rich')
..where?.lastName.equals('Person')
..where?.raw('COM.deleted = false')
..orWhere((w) => w.salary.greaterThanOrEqualTo(75000))
..join('companies', 'company_id', 'id');
..join('companies', 'company_id', 'id', alias: 'COM');
var richPerson = await query.getOne(_FakeExecutor());
if (richPerson.isPresent) {
@ -31,7 +32,7 @@ class _FakeExecutor extends QueryExecutor {
print(
'_FakeExecutor received query: $query and values: $substitutionValues');
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;
}
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;
}

View file

@ -2,6 +2,171 @@
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
// **************************************************************************
@ -10,63 +175,154 @@ part of 'main.dart';
class Employee extends _Employee {
Employee(
{this.id,
this.createdAt,
this.updatedAt,
this.firstName,
this.lastName,
this.salary,
this.createdAt,
this.updatedAt});
this.salary});
/// 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
final String? id;
String? firstName;
@override
final String? firstName;
String? lastName;
@override
final String? lastName;
@override
final double? salary;
@override
final DateTime? createdAt;
@override
final DateTime? updatedAt;
double? salary;
Employee copyWith(
{String? id,
DateTime? createdAt,
DateTime? updatedAt,
String? firstName,
String? lastName,
double? salary,
DateTime? createdAt,
DateTime? updatedAt}) {
double? salary}) {
return Employee(
id: id ?? this.id,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
firstName: firstName ?? this.firstName,
lastName: lastName ?? this.lastName,
salary: salary ?? this.salary,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt);
salary: salary ?? this.salary);
}
@override
bool operator ==(other) {
return other is _Employee &&
other.id == id &&
other.createdAt == createdAt &&
other.updatedAt == updatedAt &&
other.firstName == firstName &&
other.lastName == lastName &&
other.salary == salary &&
other.createdAt == createdAt &&
other.updatedAt == updatedAt;
other.salary == salary;
}
@override
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() {
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';
}

View file

@ -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';
}

View file

@ -167,6 +167,7 @@ abstract class Query<T, Where extends QueryWhere> extends QueryBase<T> {
void _makeJoin(
tableName,
Set<String>? trampoline,
String? alias,
JoinType type,
String localKey,
String foreignKey,
@ -182,7 +183,7 @@ abstract class Query<T, Where extends QueryWhere> extends QueryBase<T> {
}
var to = _compileJoin(tableName, trampoline);
var alias = _joinAlias(trampoline);
alias ??= _joinAlias(trampoline);
if (tableName is Query) {
for (var field in tableName.fields) {
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,
{String op = '=',
List<String> additionalFields = const [],
Set<String>? trampoline}) {
_makeJoin(tableName, trampoline, JoinType.inner, localKey, foreignKey, op,
Set<String>? trampoline,
String? alias}) {
_makeJoin(tableName, trampoline, alias, JoinType.inner, localKey, foreignKey, op,
additionalFields);
}
@ -208,8 +210,9 @@ abstract class Query<T, Where extends QueryWhere> extends QueryBase<T> {
void leftJoin(tableName, String localKey, String foreignKey,
{String op = '=',
List<String> additionalFields = const [],
Set<String>? trampoline}) {
_makeJoin(tableName, trampoline, JoinType.left, localKey, foreignKey, op,
Set<String>? trampoline,
String? alias}) {
_makeJoin(tableName, trampoline, alias, JoinType.left, localKey, foreignKey, op,
additionalFields);
}
@ -217,8 +220,9 @@ abstract class Query<T, Where extends QueryWhere> extends QueryBase<T> {
void rightJoin(tableName, String localKey, String foreignKey,
{String op = '=',
List<String> additionalFields = const [],
Set<String>? trampoline}) {
_makeJoin(tableName, trampoline, JoinType.right, localKey, foreignKey, op,
Set<String>? trampoline,
String? alias}) {
_makeJoin(tableName, trampoline, alias, JoinType.right, localKey, foreignKey, op,
additionalFields);
}
@ -226,8 +230,9 @@ abstract class Query<T, Where extends QueryWhere> extends QueryBase<T> {
void fullOuterJoin(tableName, String localKey, String foreignKey,
{String op = '=',
List<String> additionalFields = const [],
Set<String>? trampoline}) {
_makeJoin(tableName, trampoline, JoinType.full, localKey, foreignKey, op,
Set<String>? trampoline,
String? alias}) {
_makeJoin(tableName, trampoline, alias, JoinType.full, localKey, foreignKey, op,
additionalFields);
}
@ -235,8 +240,9 @@ abstract class Query<T, Where extends QueryWhere> extends QueryBase<T> {
void selfJoin(tableName, String localKey, String foreignKey,
{String op = '=',
List<String> additionalFields = const [],
Set<String>? trampoline}) {
_makeJoin(tableName, trampoline, JoinType.self, localKey, foreignKey, op,
Set<String>? trampoline,
String? alias}) {
_makeJoin(tableName, trampoline, alias, JoinType.self, localKey, foreignKey, op,
additionalFields);
}

View file

@ -5,6 +5,7 @@ abstract class QueryWhere {
final Set<QueryWhere> _and = {};
final Set<QueryWhere> _not = {};
final Set<QueryWhere> _or = {};
final Set<String> _raw = {};
Iterable<SqlExpressionBuilder> get expressionBuilders;
@ -20,6 +21,10 @@ abstract class QueryWhere {
_or.add(other);
}
void raw(String whereRaw) {
_raw.add(whereRaw);
}
String compile({String? tableName}) {
var b = StringBuffer();
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) {
var sql = other.compile();
if (sql.isNotEmpty) b.write(' AND ($sql)');

View file

@ -31,5 +31,6 @@ void main() {
() =>
manyToManyTests(pg(['user', 'role', 'user_role']), close: closePg));
group('standalone', () => standaloneTests(pg(['car']), close: closePg));
group('join', () => joinTests(pg(['person', 'person_order']), close: closePg));
});
}

View file

@ -0,0 +1,7 @@
CREATE TEMPORARY TABLE "persons" (
"id" serial PRIMARY KEY,
"name" varchar(255),
"age" int,
"created_at" timestamp,
"updated_at" timestamp
);

View file

@ -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
);

View file

@ -8,3 +8,4 @@ export 'src/has_one_test.dart';
export 'src/many_to_many_test.dart';
export 'src/standalone_test.dart';
export 'src/performance_test.dart';
export 'src/join_test.dart';

View 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);
});
}

View file

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

View file

@ -40,8 +40,6 @@ class CarQuery extends Query<Car, CarQueryWhere> {
@override
final CarQueryValues values = CarQueryValues();
List<String> _selectedFields = [];
CarQueryWhere? _where;
@override
@ -56,7 +54,7 @@ class CarQuery extends Query<Car, CarQueryWhere> {
@override
List<String> get fields {
const _fields = [
return const [
'id',
'created_at',
'updated_at',
@ -65,14 +63,6 @@ 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
@ -85,21 +75,18 @@ class CarQuery extends Query<Car, CarQueryWhere> {
return CarQueryWhere(this);
}
Optional<Car> parseRow(List row) {
static Optional<Car> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = Car(
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);
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?));
return Optional.of(model);
}

View file

@ -58,8 +58,6 @@ class NumbersQuery extends Query<Numbers, NumbersQueryWhere> {
@override
final NumbersQueryValues values = NumbersQueryValues();
List<String> _selectedFields = [];
NumbersQueryWhere? _where;
@override
@ -74,15 +72,7 @@ class NumbersQuery extends Query<Numbers, NumbersQueryWhere> {
@override
List<String> get fields {
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;
return const ['id', 'created_at', 'updated_at', 'two'];
}
@override
@ -95,15 +85,15 @@ class NumbersQuery extends Query<Numbers, NumbersQueryWhere> {
return NumbersQueryWhere(this);
}
Optional<Numbers> parseRow(List row) {
static Optional<Numbers> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = Numbers(
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);
id: row[0].toString(),
createdAt: (row[1] as DateTime?),
updatedAt: (row[2] as DateTime?),
two: (row[3] as int?));
return Optional.of(model);
}
@ -173,8 +163,6 @@ class AlphabetQuery extends Query<Alphabet, AlphabetQueryWhere> {
@override
final AlphabetQueryValues values = AlphabetQueryValues();
List<String> _selectedFields = [];
AlphabetQueryWhere? _where;
late NumbersQuery _numbers;
@ -191,15 +179,7 @@ class AlphabetQuery extends Query<Alphabet, AlphabetQueryWhere> {
@override
List<String> get fields {
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;
return const ['id', 'created_at', 'updated_at', 'value', 'numbers_id'];
}
@override
@ -212,17 +192,17 @@ class AlphabetQuery extends Query<Alphabet, AlphabetQueryWhere> {
return AlphabetQueryWhere(this);
}
Optional<Alphabet> parseRow(List row) {
static Optional<Alphabet> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = Alphabet(
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);
id: row[0].toString(),
createdAt: (row[1] as DateTime?),
updatedAt: (row[2] as DateTime?),
value: (row[3] as String?));
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,8 +75,6 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
@override
final RoleQueryValues values = RoleQueryValues();
List<String> _selectedFields = [];
RoleQueryWhere? _where;
@override
@ -91,15 +89,7 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
@override
List<String> get fields {
const _fields = ['role'];
return _selectedFields.isEmpty
? _fields
: _fields.where((field) => _selectedFields.contains(field)).toList();
}
RoleQuery select(List<String> selectedFields) {
_selectedFields = selectedFields;
return this;
return const ['role'];
}
@override
@ -112,14 +102,13 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
return RoleQueryWhere(this);
}
Optional<Role> parseRow(List row) {
static Optional<Role> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model =
Role(role: fields.contains('role') ? (row[0] as String?) : null);
var model = Role(role: (row[0] as String?));
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]);
});
@ -239,8 +228,6 @@ class RoleUserQuery extends Query<RoleUser, RoleUserQueryWhere> {
@override
final RoleUserQueryValues values = RoleUserQueryValues();
List<String> _selectedFields = [];
RoleUserQueryWhere? _where;
late RoleQuery _role;
@ -259,15 +246,7 @@ class RoleUserQuery extends Query<RoleUser, RoleUserQueryWhere> {
@override
List<String> get fields {
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;
return const ['role_role', 'user_email'];
}
@override
@ -280,19 +259,19 @@ class RoleUserQuery extends Query<RoleUser, RoleUserQueryWhere> {
return RoleUserQueryWhere(this);
}
Optional<RoleUser> parseRow(List row) {
static 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);
});
@ -371,8 +350,6 @@ class UserQuery extends Query<User, UserQueryWhere> {
@override
final UserQueryValues values = UserQueryValues();
List<String> _selectedFields = [];
UserQueryWhere? _where;
@override
@ -387,15 +364,7 @@ class UserQuery extends Query<User, UserQueryWhere> {
@override
List<String> get fields {
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;
return const ['email', 'name', 'password'];
}
@override
@ -408,16 +377,16 @@ class UserQuery extends Query<User, UserQueryWhere> {
return UserQueryWhere(this);
}
Optional<User> parseRow(List row) {
static Optional<User> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = User(
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);
email: (row[0] as String?),
name: (row[1] as String?),
password: (row[2] as String?));
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,8 +36,6 @@ class FortuneQuery extends Query<Fortune, FortuneQueryWhere> {
@override
final FortuneQueryValues values = FortuneQueryValues();
List<String> _selectedFields = [];
FortuneQueryWhere? _where;
@override
@ -52,15 +50,7 @@ class FortuneQuery extends Query<Fortune, FortuneQueryWhere> {
@override
List<String> get fields {
const _fields = ['id', 'message'];
return _selectedFields.isEmpty
? _fields
: _fields.where((field) => _selectedFields.contains(field)).toList();
}
FortuneQuery select(List<String> selectedFields) {
_selectedFields = selectedFields;
return this;
return const ['id', 'message'];
}
@override
@ -73,13 +63,11 @@ class FortuneQuery extends Query<Fortune, FortuneQueryWhere> {
return FortuneQueryWhere(this);
}
Optional<Fortune> parseRow(List row) {
static Optional<Fortune> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = Fortune(
id: fields.contains('id') ? (row[0] as int?) : null,
message: fields.contains('message') ? (row[1] as String?) : null);
var model = Fortune(id: (row[0] as int?), message: (row[1] as String?));
return Optional.of(model);
}

View file

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

View file

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

View file

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

View file

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

View 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;
}

View 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';
}

View 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;
}

View 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';
}

View file

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

View file

@ -116,8 +116,6 @@ class UnorthodoxQuery extends Query<Unorthodox, UnorthodoxQueryWhere> {
@override
final UnorthodoxQueryValues values = UnorthodoxQueryValues();
List<String> _selectedFields = [];
UnorthodoxQueryWhere? _where;
@override
@ -132,15 +130,7 @@ class UnorthodoxQuery extends Query<Unorthodox, UnorthodoxQueryWhere> {
@override
List<String> get fields {
const _fields = ['name'];
return _selectedFields.isEmpty
? _fields
: _fields.where((field) => _selectedFields.contains(field)).toList();
}
UnorthodoxQuery select(List<String> selectedFields) {
_selectedFields = selectedFields;
return this;
return const ['name'];
}
@override
@ -153,12 +143,11 @@ class UnorthodoxQuery extends Query<Unorthodox, UnorthodoxQueryWhere> {
return UnorthodoxQueryWhere(this);
}
Optional<Unorthodox> parseRow(List row) {
static Optional<Unorthodox> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model =
Unorthodox(name: fields.contains('name') ? (row[0] as String?) : null);
var model = Unorthodox(name: (row[0] as String?));
return Optional.of(model);
}
@ -232,8 +221,6 @@ class WeirdJoinQuery extends Query<WeirdJoin, WeirdJoinQueryWhere> {
@override
final WeirdJoinQueryValues values = WeirdJoinQueryValues();
List<String> _selectedFields = [];
WeirdJoinQueryWhere? _where;
late UnorthodoxQuery _unorthodox;
@ -254,15 +241,7 @@ class WeirdJoinQuery extends Query<WeirdJoin, WeirdJoinQueryWhere> {
@override
List<String> get fields {
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;
return const ['id', 'join_name'];
}
@override
@ -275,31 +254,31 @@ class WeirdJoinQuery extends Query<WeirdJoin, WeirdJoinQueryWhere> {
return WeirdJoinQueryWhere(this);
}
Optional<WeirdJoin> parseRow(List row) {
static Optional<WeirdJoin> parseRow(List row) {
if (row.every((x) => x == null)) {
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) {
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]);
});
@ -437,8 +416,6 @@ class SongQuery extends Query<Song, SongQueryWhere> {
@override
final SongQueryValues values = SongQueryValues();
List<String> _selectedFields = [];
SongQueryWhere? _where;
@override
@ -453,21 +430,7 @@ class SongQuery extends Query<Song, SongQueryWhere> {
@override
List<String> get fields {
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;
return const ['id', 'created_at', 'updated_at', 'weird_join_id', 'title'];
}
@override
@ -480,16 +443,16 @@ class SongQuery extends Query<Song, SongQueryWhere> {
return SongQueryWhere(this);
}
Optional<Song> parseRow(List row) {
static Optional<Song> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = Song(
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);
id: row[0].toString(),
createdAt: (row[1] as DateTime?),
updatedAt: (row[2] as DateTime?),
weirdJoinId: (row[3] as int?),
title: (row[4] as String?));
return Optional.of(model);
}
@ -572,8 +535,6 @@ class NumbaQuery extends Query<Numba, NumbaQueryWhere> {
@override
final NumbaQueryValues values = NumbaQueryValues();
List<String> _selectedFields = [];
NumbaQueryWhere? _where;
@override
@ -588,15 +549,7 @@ class NumbaQuery extends Query<Numba, NumbaQueryWhere> {
@override
List<String> get fields {
const _fields = ['i', 'parent'];
return _selectedFields.isEmpty
? _fields
: _fields.where((field) => _selectedFields.contains(field)).toList();
}
NumbaQuery select(List<String> selectedFields) {
_selectedFields = selectedFields;
return this;
return const ['i', 'parent'];
}
@override
@ -609,13 +562,11 @@ class NumbaQuery extends Query<Numba, NumbaQueryWhere> {
return NumbaQueryWhere(this);
}
Optional<Numba> parseRow(List row) {
static Optional<Numba> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = Numba(
i: fields.contains('i') ? (row[0] as int?) : null,
parent: fields.contains('parent') ? (row[1] as int?) : null);
var model = Numba(i: (row[0] as int?), parent: (row[1] as int?));
return Optional.of(model);
}
@ -678,8 +629,6 @@ class FooQuery extends Query<Foo, FooQueryWhere> {
@override
final FooQueryValues values = FooQueryValues();
List<String> _selectedFields = [];
FooQueryWhere? _where;
@override
@ -694,15 +643,7 @@ class FooQuery extends Query<Foo, FooQueryWhere> {
@override
List<String> get fields {
const _fields = ['bar'];
return _selectedFields.isEmpty
? _fields
: _fields.where((field) => _selectedFields.contains(field)).toList();
}
FooQuery select(List<String> selectedFields) {
_selectedFields = selectedFields;
return this;
return const ['bar'];
}
@override
@ -715,13 +656,13 @@ class FooQuery extends Query<Foo, FooQueryWhere> {
return FooQueryWhere(this);
}
Optional<Foo> parseRow(List row) {
static Optional<Foo> parseRow(List row) {
if (row.every((x) => x == null)) {
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) {
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]);
});
@ -843,8 +784,6 @@ class FooPivotQuery extends Query<FooPivot, FooPivotQueryWhere> {
@override
final FooPivotQueryValues values = FooPivotQueryValues();
List<String> _selectedFields = [];
FooPivotQueryWhere? _where;
late WeirdJoinQuery _weirdJoin;
@ -863,15 +802,7 @@ class FooPivotQuery extends Query<FooPivot, FooPivotQueryWhere> {
@override
List<String> get fields {
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;
return const ['weird_join_id', 'foo_bar'];
}
@override
@ -884,19 +815,19 @@ class FooPivotQuery extends Query<FooPivot, FooPivotQueryWhere> {
return FooPivotQueryWhere(this);
}
Optional<FooPivot> parseRow(List row) {
static 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,8 +77,6 @@ class UserQuery extends Query<User, UserQueryWhere> {
@override
final UserQueryValues values = UserQueryValues();
List<String> _selectedFields = [];
UserQueryWhere? _where;
@override
@ -93,7 +91,7 @@ class UserQuery extends Query<User, UserQueryWhere> {
@override
List<String> get fields {
const _fields = [
return const [
'id',
'created_at',
'updated_at',
@ -101,14 +99,6 @@ 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
@ -121,19 +111,19 @@ class UserQuery extends Query<User, UserQueryWhere> {
return UserQueryWhere(this);
}
Optional<User> parseRow(List row) {
static Optional<User> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = User(
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);
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?));
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]);
});
@ -305,8 +295,6 @@ class RoleUserQuery extends Query<RoleUser, RoleUserQueryWhere> {
@override
final RoleUserQueryValues values = RoleUserQueryValues();
List<String> _selectedFields = [];
RoleUserQueryWhere? _where;
late RoleQuery _role;
@ -325,15 +313,7 @@ class RoleUserQuery extends Query<RoleUser, RoleUserQueryWhere> {
@override
List<String> get fields {
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;
return const ['role_id', 'user_id'];
}
@override
@ -346,19 +326,19 @@ class RoleUserQuery extends Query<RoleUser, RoleUserQueryWhere> {
return RoleUserQueryWhere(this);
}
Optional<RoleUser> parseRow(List row) {
static 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);
});
@ -444,8 +424,6 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
@override
final RoleQueryValues values = RoleQueryValues();
List<String> _selectedFields = [];
RoleQueryWhere? _where;
@override
@ -460,15 +438,7 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
@override
List<String> get fields {
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;
return const ['id', 'created_at', 'updated_at', 'name'];
}
@override
@ -481,17 +451,17 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
return RoleQueryWhere(this);
}
Optional<Role> parseRow(List row) {
static Optional<Role> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = Role(
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);
id: row[0].toString(),
createdAt: (row[1] as DateTime?),
updatedAt: (row[2] as DateTime?),
name: (row[3] as String?));
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,8 +35,6 @@ class WorldQuery extends Query<World, WorldQueryWhere> {
@override
final WorldQueryValues values = WorldQueryValues();
List<String> _selectedFields = [];
WorldQueryWhere? _where;
@override
@ -51,15 +49,7 @@ class WorldQuery extends Query<World, WorldQueryWhere> {
@override
List<String> get fields {
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;
return const ['id', 'random_number'];
}
@override
@ -72,14 +62,11 @@ class WorldQuery extends Query<World, WorldQueryWhere> {
return WorldQueryWhere(this);
}
Optional<World> parseRow(List row) {
static Optional<World> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = World(
id: fields.contains('id') ? (row[0] as int?) : null,
randomNumber:
fields.contains('random_number') ? (row[1] as int?) : null);
var model = World(id: (row[0] as int?), randomNumber: (row[1] as int?));
return Optional.of(model);
}