platform/angel_orm_generator/test/models/user.g.dart

951 lines
23 KiB
Dart
Raw Normal View History

2019-02-07 03:38:34 +00:00
// GENERATED CODE - DO NOT MODIFY BY HAND
part of angel_orm_generator.test.models.user;
// **************************************************************************
// MigrationGenerator
// **************************************************************************
class UserMigration extends Migration {
@override
up(Schema schema) {
schema.create('users', (table) {
table.serial('id')..primaryKey();
table.varChar('username');
table.varChar('password');
table.varChar('email');
table.timeStamp('created_at');
table.timeStamp('updated_at');
});
}
@override
down(Schema schema) {
2019-04-08 04:03:41 +00:00
schema.drop('users', cascade: true);
2019-02-07 03:38:34 +00:00
}
}
class RoleUserMigration extends Migration {
@override
up(Schema schema) {
schema.create('role_users', (table) {
table.integer('role_id').references('roles', 'id');
table.integer('user_id').references('users', 'id');
});
}
@override
down(Schema schema) {
schema.drop('role_users');
}
}
class RoleMigration extends Migration {
@override
up(Schema schema) {
schema.create('roles', (table) {
table.serial('id')..primaryKey();
table.varChar('name');
table.timeStamp('created_at');
table.timeStamp('updated_at');
});
}
@override
down(Schema schema) {
2019-04-08 04:03:41 +00:00
schema.drop('roles', cascade: true);
2019-02-07 03:38:34 +00:00
}
}
// **************************************************************************
// OrmGenerator
// **************************************************************************
class UserQuery extends Query<User, UserQueryWhere> {
UserQuery({Set<String> trampoline}) {
trampoline ??= Set();
trampoline.add(tableName);
_where = UserQueryWhere(this);
2019-04-02 23:05:13 +00:00
leftJoin(RoleUserQuery(trampoline: trampoline), 'id', 'user_id',
additionalFields: const ['id', 'name', 'created_at', 'updated_at'],
trampoline: trampoline);
2019-02-07 03:38:34 +00:00
}
@override
final UserQueryValues values = UserQueryValues();
UserQueryWhere _where;
@override
get casts {
return {};
}
@override
get tableName {
return 'users';
}
@override
get fields {
return const [
'id',
'username',
'password',
'email',
'created_at',
'updated_at'
];
}
@override
UserQueryWhere get where {
return _where;
}
@override
UserQueryWhere newWhereClause() {
return UserQueryWhere(this);
}
static User parseRow(List row) {
if (row.every((x) => x == null)) return null;
var model = User(
id: row[0].toString(),
username: (row[1] as String),
password: (row[2] as String),
email: (row[3] as String),
createdAt: (row[4] as DateTime),
updatedAt: (row[5] as DateTime));
2019-04-02 23:05:13 +00:00
if (row.length > 6) {
model = model.copyWith(
roles: [RoleQuery.parseRow(row.skip(6).toList())]
.where((x) => x != null)
.toList());
}
2019-02-07 03:38:34 +00:00
return model;
}
@override
deserialize(List row) {
return parseRow(row);
}
2019-04-02 23:05:13 +00:00
@override
bool canCompile(trampoline) {
return (!(trampoline.contains('users') &&
trampoline.contains('role_users')));
}
@override
get(QueryExecutor executor) {
return super.get(executor).then((result) {
return result.fold<List<User>>([], (out, model) {
var idx = out.indexWhere((m) => m.id == model.id);
if (idx == -1) {
return out..add(model);
} else {
var l = out[idx];
return out
..[idx] = l.copyWith(
roles: List<_Role>.from(l.roles ?? [])
..addAll(model.roles ?? []));
}
});
});
}
@override
update(QueryExecutor executor) {
return super.update(executor).then((result) {
return result.fold<List<User>>([], (out, model) {
var idx = out.indexWhere((m) => m.id == model.id);
if (idx == -1) {
return out..add(model);
} else {
var l = out[idx];
return out
..[idx] = l.copyWith(
roles: List<_Role>.from(l.roles ?? [])
..addAll(model.roles ?? []));
}
});
});
}
@override
delete(QueryExecutor executor) {
return super.delete(executor).then((result) {
return result.fold<List<User>>([], (out, model) {
var idx = out.indexWhere((m) => m.id == model.id);
if (idx == -1) {
return out..add(model);
} else {
var l = out[idx];
return out
..[idx] = l.copyWith(
roles: List<_Role>.from(l.roles ?? [])
..addAll(model.roles ?? []));
}
});
});
}
2019-02-07 03:38:34 +00:00
}
class UserQueryWhere extends QueryWhere {
UserQueryWhere(UserQuery query)
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
username = StringSqlExpressionBuilder(query, 'username'),
password = StringSqlExpressionBuilder(query, 'password'),
email = StringSqlExpressionBuilder(query, 'email'),
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
final NumericSqlExpressionBuilder<int> id;
final StringSqlExpressionBuilder username;
final StringSqlExpressionBuilder password;
final StringSqlExpressionBuilder email;
final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt;
@override
get expressionBuilders {
return [id, username, password, email, createdAt, updatedAt];
}
}
class UserQueryValues extends MapQueryValues {
@override
get casts {
return {};
}
2019-04-03 09:57:27 +00:00
String get id {
return (values['id'] as String);
2019-02-07 03:38:34 +00:00
}
2019-04-03 09:57:27 +00:00
set id(String value) => values['id'] = value;
2019-02-07 03:38:34 +00:00
String get username {
return (values['username'] as String);
}
set username(String value) => values['username'] = value;
String get password {
return (values['password'] as String);
}
set password(String value) => values['password'] = value;
String get email {
return (values['email'] as String);
}
set email(String value) => values['email'] = 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;
void copyFrom(User model) {
username = model.username;
password = model.password;
email = model.email;
createdAt = model.createdAt;
updatedAt = model.updatedAt;
}
}
class RoleUserQuery extends Query<RoleUser, RoleUserQueryWhere> {
RoleUserQuery({Set<String> trampoline}) {
trampoline ??= Set();
trampoline.add(tableName);
_where = RoleUserQueryWhere(this);
leftJoin('roles', 'role_id', 'id',
2019-04-02 23:05:13 +00:00
additionalFields: const ['id', 'name', 'created_at', 'updated_at'],
trampoline: trampoline);
leftJoin('users', 'user_id', 'id',
additionalFields: const [
'id',
'username',
'password',
'email',
'created_at',
'updated_at'
],
trampoline: trampoline);
2019-02-07 03:38:34 +00:00
}
@override
final RoleUserQueryValues values = RoleUserQueryValues();
RoleUserQueryWhere _where;
@override
get casts {
return {};
}
@override
get tableName {
return 'role_users';
}
@override
get fields {
2019-04-02 23:05:13 +00:00
return const ['role_id', 'user_id'];
2019-02-07 03:38:34 +00:00
}
@override
RoleUserQueryWhere get where {
return _where;
}
@override
RoleUserQueryWhere newWhereClause() {
return RoleUserQueryWhere(this);
}
static RoleUser parseRow(List row) {
if (row.every((x) => x == null)) return null;
2019-04-02 23:05:13 +00:00
var model = RoleUser();
if (row.length > 2) {
model = model.copyWith(role: RoleQuery.parseRow(row.skip(2).toList()));
2019-02-07 03:38:34 +00:00
}
2019-04-02 23:05:13 +00:00
if (row.length > 6) {
model = model.copyWith(user: UserQuery.parseRow(row.skip(6).toList()));
2019-02-07 03:38:34 +00:00
}
return model;
}
@override
deserialize(List row) {
return parseRow(row);
}
}
class RoleUserQueryWhere extends QueryWhere {
RoleUserQueryWhere(RoleUserQuery query)
2019-04-02 23:05:13 +00:00
: roleId = NumericSqlExpressionBuilder<int>(query, 'role_id'),
userId = NumericSqlExpressionBuilder<int>(query, 'user_id');
2019-02-07 03:38:34 +00:00
final NumericSqlExpressionBuilder<int> roleId;
final NumericSqlExpressionBuilder<int> userId;
@override
get expressionBuilders {
2019-04-02 23:05:13 +00:00
return [roleId, userId];
2019-02-07 03:38:34 +00:00
}
}
class RoleUserQueryValues extends MapQueryValues {
@override
get casts {
return {};
}
int get roleId {
return (values['role_id'] as int);
}
set roleId(int value) => values['role_id'] = value;
int get userId {
return (values['user_id'] as int);
}
set userId(int value) => values['user_id'] = value;
void copyFrom(RoleUser model) {
if (model.role != null) {
2019-04-03 09:57:27 +00:00
values['role_id'] = model.role.id;
2019-02-07 03:38:34 +00:00
}
if (model.user != null) {
2019-04-03 09:57:27 +00:00
values['user_id'] = model.user.id;
2019-02-07 03:38:34 +00:00
}
}
}
class RoleQuery extends Query<Role, RoleQueryWhere> {
RoleQuery({Set<String> trampoline}) {
trampoline ??= Set();
trampoline.add(tableName);
_where = RoleQueryWhere(this);
2019-04-02 23:05:13 +00:00
leftJoin(RoleUserQuery(trampoline: trampoline), 'id', 'role_id',
additionalFields: const [
'id',
'username',
'password',
'email',
'created_at',
'updated_at'
],
trampoline: trampoline);
2019-02-07 03:38:34 +00:00
}
@override
final RoleQueryValues values = RoleQueryValues();
RoleQueryWhere _where;
@override
get casts {
return {};
}
@override
get tableName {
return 'roles';
}
@override
get fields {
return const ['id', 'name', 'created_at', 'updated_at'];
}
@override
RoleQueryWhere get where {
return _where;
}
@override
RoleQueryWhere newWhereClause() {
return RoleQueryWhere(this);
}
static Role parseRow(List row) {
if (row.every((x) => x == null)) return null;
var model = Role(
id: row[0].toString(),
name: (row[1] as String),
createdAt: (row[2] as DateTime),
updatedAt: (row[3] as DateTime));
2019-04-02 23:05:13 +00:00
if (row.length > 4) {
model = model.copyWith(
users: [UserQuery.parseRow(row.skip(4).toList())]
.where((x) => x != null)
.toList());
}
2019-02-07 03:38:34 +00:00
return model;
}
@override
deserialize(List row) {
return parseRow(row);
}
2019-04-02 23:05:13 +00:00
@override
bool canCompile(trampoline) {
return (!(trampoline.contains('roles') &&
trampoline.contains('role_users')));
}
@override
get(QueryExecutor executor) {
return super.get(executor).then((result) {
return result.fold<List<Role>>([], (out, model) {
var idx = out.indexWhere((m) => m.id == model.id);
if (idx == -1) {
return out..add(model);
} else {
var l = out[idx];
return out
..[idx] = l.copyWith(
users: List<_User>.from(l.users ?? [])
..addAll(model.users ?? []));
}
});
});
}
@override
update(QueryExecutor executor) {
return super.update(executor).then((result) {
return result.fold<List<Role>>([], (out, model) {
var idx = out.indexWhere((m) => m.id == model.id);
if (idx == -1) {
return out..add(model);
} else {
var l = out[idx];
return out
..[idx] = l.copyWith(
users: List<_User>.from(l.users ?? [])
..addAll(model.users ?? []));
}
});
});
}
@override
delete(QueryExecutor executor) {
return super.delete(executor).then((result) {
return result.fold<List<Role>>([], (out, model) {
var idx = out.indexWhere((m) => m.id == model.id);
if (idx == -1) {
return out..add(model);
} else {
var l = out[idx];
return out
..[idx] = l.copyWith(
users: List<_User>.from(l.users ?? [])
..addAll(model.users ?? []));
}
});
});
}
2019-02-07 03:38:34 +00:00
}
class RoleQueryWhere extends QueryWhere {
RoleQueryWhere(RoleQuery query)
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
name = StringSqlExpressionBuilder(query, 'name'),
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
final NumericSqlExpressionBuilder<int> id;
final StringSqlExpressionBuilder name;
final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt;
@override
get expressionBuilders {
return [id, name, createdAt, updatedAt];
}
}
class RoleQueryValues extends MapQueryValues {
@override
get casts {
return {};
}
2019-04-03 09:57:27 +00:00
String get id {
return (values['id'] as String);
2019-02-07 03:38:34 +00:00
}
2019-04-03 09:57:27 +00:00
set id(String value) => values['id'] = value;
2019-02-07 03:38:34 +00:00
String get name {
return (values['name'] as String);
}
set name(String value) => values['name'] = 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;
void copyFrom(Role model) {
name = model.name;
createdAt = model.createdAt;
updatedAt = model.updatedAt;
}
}
// **************************************************************************
// JsonModelGenerator
// **************************************************************************
@generatedSerializable
class User extends _User {
User(
{this.id,
2019-04-08 04:03:41 +00:00
@required this.username,
@required this.password,
@required this.email,
@required List<_Role> roles,
2019-02-07 03:38:34 +00:00
this.createdAt,
this.updatedAt})
: this.roles = new List.unmodifiable(roles ?? []);
@override
final String id;
@override
final String username;
@override
final String password;
@override
final String email;
@override
final List<_Role> roles;
@override
final DateTime createdAt;
@override
final DateTime updatedAt;
User copyWith(
{String id,
String username,
String password,
String email,
List<_Role> roles,
DateTime createdAt,
DateTime updatedAt}) {
return new User(
id: id ?? this.id,
username: username ?? this.username,
password: password ?? this.password,
email: email ?? this.email,
roles: roles ?? this.roles,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt);
}
bool operator ==(other) {
return other is _User &&
other.id == id &&
other.username == username &&
other.password == password &&
other.email == email &&
const ListEquality<_Role>(const DefaultEquality<_Role>())
.equals(other.roles, roles) &&
other.createdAt == createdAt &&
other.updatedAt == updatedAt;
}
@override
int get hashCode {
return hashObjects(
[id, username, password, email, roles, createdAt, updatedAt]);
}
Map<String, dynamic> toJson() {
return UserSerializer.toMap(this);
}
}
@generatedSerializable
2019-04-02 23:05:13 +00:00
class RoleUser implements _RoleUser {
2019-04-08 04:03:41 +00:00
const RoleUser({@required this.role, @required this.user});
2019-02-07 03:38:34 +00:00
@override
final _Role role;
@override
final _User user;
2019-04-02 23:05:13 +00:00
RoleUser copyWith({_Role role, _User user}) {
return new RoleUser(role: role ?? this.role, user: user ?? this.user);
2019-02-07 03:38:34 +00:00
}
bool operator ==(other) {
2019-04-02 23:05:13 +00:00
return other is _RoleUser && other.role == role && other.user == user;
2019-02-07 03:38:34 +00:00
}
@override
int get hashCode {
2019-04-02 23:05:13 +00:00
return hashObjects([role, user]);
2019-02-07 03:38:34 +00:00
}
Map<String, dynamic> toJson() {
return RoleUserSerializer.toMap(this);
}
}
@generatedSerializable
class Role extends _Role {
2019-04-08 04:03:41 +00:00
Role(
{this.id,
@required this.name,
@required List<_User> users,
this.createdAt,
this.updatedAt})
2019-02-07 03:38:34 +00:00
: this.users = new List.unmodifiable(users ?? []);
@override
final String id;
@override
final String name;
@override
final List<_User> users;
@override
final DateTime createdAt;
@override
final DateTime updatedAt;
Role copyWith(
{String id,
String name,
List<_User> users,
DateTime createdAt,
DateTime updatedAt}) {
return new Role(
id: id ?? this.id,
name: name ?? this.name,
users: users ?? this.users,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt);
}
bool operator ==(other) {
return other is _Role &&
other.id == id &&
other.name == name &&
const ListEquality<_User>(const DefaultEquality<_User>())
.equals(other.users, users) &&
other.createdAt == createdAt &&
other.updatedAt == updatedAt;
}
@override
int get hashCode {
return hashObjects([id, name, users, createdAt, updatedAt]);
}
Map<String, dynamic> toJson() {
return RoleSerializer.toMap(this);
}
}
// **************************************************************************
// SerializerGenerator
// **************************************************************************
abstract class UserSerializer {
static User fromMap(Map map) {
2019-04-08 04:03:41 +00:00
if (map['username'] == null) {
throw new FormatException("Missing required field 'username' on User.");
}
if (map['password'] == null) {
throw new FormatException("Missing required field 'password' on User.");
}
if (map['email'] == null) {
throw new FormatException("Missing required field 'email' on User.");
}
if (map['roles'] == null) {
throw new FormatException("Missing required field 'roles' on User.");
}
2019-02-07 03:38:34 +00:00
return new User(
id: map['id'] as String,
username: map['username'] as String,
password: map['password'] as String,
email: map['email'] as String,
roles: map['roles'] is Iterable
? new List.unmodifiable(
((map['roles'] as Iterable).where((x) => x is Map))
.cast<Map>()
.map(RoleSerializer.fromMap))
: null,
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(_User model) {
if (model == null) {
return null;
}
2019-04-08 04:03:41 +00:00
if (model.username == null) {
throw new FormatException("Missing required field 'username' on User.");
}
if (model.password == null) {
throw new FormatException("Missing required field 'password' on User.");
}
if (model.email == null) {
throw new FormatException("Missing required field 'email' on User.");
}
if (model.roles == null) {
throw new FormatException("Missing required field 'roles' on User.");
}
2019-02-07 03:38:34 +00:00
return {
'id': model.id,
'username': model.username,
'password': model.password,
'email': model.email,
'roles': model.roles?.map((m) => RoleSerializer.toMap(m))?.toList(),
'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String()
};
}
}
abstract class UserFields {
static const List<String> allFields = <String>[
id,
username,
password,
email,
roles,
createdAt,
updatedAt
];
static const String id = 'id';
static const String username = 'username';
static const String password = 'password';
static const String email = 'email';
static const String roles = 'roles';
static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at';
}
abstract class RoleUserSerializer {
static RoleUser fromMap(Map map) {
2019-04-08 04:03:41 +00:00
if (map['role'] == null) {
throw new FormatException("Missing required field 'role' on RoleUser.");
}
if (map['user'] == null) {
throw new FormatException("Missing required field 'user' on RoleUser.");
}
2019-02-07 03:38:34 +00:00
return new RoleUser(
role: map['role'] != null
? RoleSerializer.fromMap(map['role'] as Map)
: null,
user: map['user'] != null
? UserSerializer.fromMap(map['user'] as Map)
: null);
}
static Map<String, dynamic> toMap(_RoleUser model) {
if (model == null) {
return null;
}
2019-04-08 04:03:41 +00:00
if (model.role == null) {
throw new FormatException("Missing required field 'role' on RoleUser.");
}
if (model.user == null) {
throw new FormatException("Missing required field 'user' on RoleUser.");
}
2019-02-07 03:38:34 +00:00
return {
'role': RoleSerializer.toMap(model.role),
2019-04-02 23:05:13 +00:00
'user': UserSerializer.toMap(model.user)
2019-02-07 03:38:34 +00:00
};
}
}
abstract class RoleUserFields {
2019-04-02 23:05:13 +00:00
static const List<String> allFields = <String>[role, user];
2019-02-07 03:38:34 +00:00
static const String role = 'role';
static const String user = 'user';
}
abstract class RoleSerializer {
static Role fromMap(Map map) {
2019-04-08 04:03:41 +00:00
if (map['name'] == null) {
throw new FormatException("Missing required field 'name' on Role.");
}
if (map['users'] == null) {
throw new FormatException("Missing required field 'users' on Role.");
}
2019-02-07 03:38:34 +00:00
return new Role(
id: map['id'] as String,
name: map['name'] as String,
users: map['users'] is Iterable
? new List.unmodifiable(
((map['users'] as Iterable).where((x) => x is Map))
.cast<Map>()
.map(UserSerializer.fromMap))
: null,
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(_Role model) {
if (model == null) {
return null;
}
2019-04-08 04:03:41 +00:00
if (model.name == null) {
throw new FormatException("Missing required field 'name' on Role.");
}
if (model.users == null) {
throw new FormatException("Missing required field 'users' on Role.");
}
2019-02-07 03:38:34 +00:00
return {
'id': model.id,
'name': model.name,
'users': model.users?.map((m) => UserSerializer.toMap(m))?.toList(),
'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String()
};
}
}
abstract class RoleFields {
static const List<String> allFields = <String>[
id,
name,
users,
createdAt,
updatedAt
];
static const String id = 'id';
static const String name = 'name';
static const String users = 'users';
static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at';
}