mirror of https://github.com/AMT-Cheif/drift.git
173 lines
5.2 KiB
Dart
173 lines
5.2 KiB
Dart
// GENERATED CODE - DO NOT MODIFY BY HAND
|
|
|
|
part of 'database.dart';
|
|
|
|
// **************************************************************************
|
|
// MoorGenerator
|
|
// **************************************************************************
|
|
|
|
// ignore_for_file: unnecessary_brace_in_string_interps, unnecessary_this
|
|
class User extends DataClass implements Insertable<User> {
|
|
final int id;
|
|
final String name;
|
|
User({@required this.id, @required this.name});
|
|
factory User.fromData(Map<String, dynamic> data, GeneratedDatabase db,
|
|
{String prefix}) {
|
|
final effectivePrefix = prefix ?? '';
|
|
final intType = db.typeSystem.forDartType<int>();
|
|
final stringType = db.typeSystem.forDartType<String>();
|
|
return User(
|
|
id: intType.mapFromDatabaseResponse(data['${effectivePrefix}id']),
|
|
name: stringType.mapFromDatabaseResponse(data['${effectivePrefix}name']),
|
|
);
|
|
}
|
|
factory User.fromJson(Map<String, dynamic> json,
|
|
{ValueSerializer serializer}) {
|
|
serializer ??= moorRuntimeOptions.defaultSerializer;
|
|
return User(
|
|
id: serializer.fromJson<int>(json['id']),
|
|
name: serializer.fromJson<String>(json['name']),
|
|
);
|
|
}
|
|
@override
|
|
Map<String, dynamic> toJson({ValueSerializer serializer}) {
|
|
serializer ??= moorRuntimeOptions.defaultSerializer;
|
|
return <String, dynamic>{
|
|
'id': serializer.toJson<int>(id),
|
|
'name': serializer.toJson<String>(name),
|
|
};
|
|
}
|
|
|
|
@override
|
|
UsersCompanion createCompanion(bool nullToAbsent) {
|
|
return UsersCompanion(
|
|
id: id == null && nullToAbsent ? const Value.absent() : Value(id),
|
|
name: name == null && nullToAbsent ? const Value.absent() : Value(name),
|
|
);
|
|
}
|
|
|
|
User copyWith({int id, String name}) => User(
|
|
id: id ?? this.id,
|
|
name: name ?? this.name,
|
|
);
|
|
@override
|
|
String toString() {
|
|
return (StringBuffer('User(')
|
|
..write('id: $id, ')
|
|
..write('name: $name')
|
|
..write(')'))
|
|
.toString();
|
|
}
|
|
|
|
@override
|
|
int get hashCode => $mrjf($mrjc(id.hashCode, name.hashCode));
|
|
@override
|
|
bool operator ==(dynamic other) =>
|
|
identical(this, other) ||
|
|
(other is User && other.id == this.id && other.name == this.name);
|
|
}
|
|
|
|
class UsersCompanion extends UpdateCompanion<User> {
|
|
final Value<int> id;
|
|
final Value<String> name;
|
|
const UsersCompanion({
|
|
this.id = const Value.absent(),
|
|
this.name = const Value.absent(),
|
|
});
|
|
UsersCompanion.insert({
|
|
this.id = const Value.absent(),
|
|
@required String name,
|
|
}) : name = Value(name);
|
|
UsersCompanion copyWith({Value<int> id, Value<String> name}) {
|
|
return UsersCompanion(
|
|
id: id ?? this.id,
|
|
name: name ?? this.name,
|
|
);
|
|
}
|
|
}
|
|
|
|
class Users extends Table with TableInfo<Users, User> {
|
|
final GeneratedDatabase _db;
|
|
final String _alias;
|
|
Users(this._db, [this._alias]);
|
|
final VerificationMeta _idMeta = const VerificationMeta('id');
|
|
GeneratedIntColumn _id;
|
|
GeneratedIntColumn get id => _id ??= _constructId();
|
|
GeneratedIntColumn _constructId() {
|
|
return GeneratedIntColumn('id', $tableName, false,
|
|
declaredAsPrimaryKey: true,
|
|
hasAutoIncrement: true,
|
|
$customConstraints: 'NOT NULL PRIMARY KEY AUTOINCREMENT');
|
|
}
|
|
|
|
final VerificationMeta _nameMeta = const VerificationMeta('name');
|
|
GeneratedTextColumn _name;
|
|
GeneratedTextColumn get name => _name ??= _constructName();
|
|
GeneratedTextColumn _constructName() {
|
|
return GeneratedTextColumn('name', $tableName, false,
|
|
$customConstraints: 'NOT NULL');
|
|
}
|
|
|
|
@override
|
|
List<GeneratedColumn> get $columns => [id, name];
|
|
@override
|
|
Users get asDslTable => this;
|
|
@override
|
|
String get $tableName => _alias ?? 'users';
|
|
@override
|
|
final String actualTableName = 'users';
|
|
@override
|
|
VerificationContext validateIntegrity(UsersCompanion d,
|
|
{bool isInserting = false}) {
|
|
final context = VerificationContext();
|
|
if (d.id.present) {
|
|
context.handle(_idMeta, id.isAcceptableValue(d.id.value, _idMeta));
|
|
}
|
|
if (d.name.present) {
|
|
context.handle(
|
|
_nameMeta, name.isAcceptableValue(d.name.value, _nameMeta));
|
|
} else if (isInserting) {
|
|
context.missing(_nameMeta);
|
|
}
|
|
return context;
|
|
}
|
|
|
|
@override
|
|
Set<GeneratedColumn> get $primaryKey => {id};
|
|
@override
|
|
User map(Map<String, dynamic> data, {String tablePrefix}) {
|
|
final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : null;
|
|
return User.fromData(data, _db, prefix: effectivePrefix);
|
|
}
|
|
|
|
@override
|
|
Map<String, Variable> entityToSql(UsersCompanion d) {
|
|
final map = <String, Variable>{};
|
|
if (d.id.present) {
|
|
map['id'] = Variable<int>(d.id.value);
|
|
}
|
|
if (d.name.present) {
|
|
map['name'] = Variable<String>(d.name.value);
|
|
}
|
|
return map;
|
|
}
|
|
|
|
@override
|
|
Users createAlias(String alias) {
|
|
return Users(_db, alias);
|
|
}
|
|
|
|
@override
|
|
bool get dontWriteConstraints => true;
|
|
}
|
|
|
|
abstract class _$Database extends GeneratedDatabase {
|
|
_$Database(QueryExecutor e) : super(SqlTypeSystem.defaultInstance, e);
|
|
Users _users;
|
|
Users get users => _users ??= Users(this);
|
|
@override
|
|
Iterable<TableInfo> get allTables => allSchemaEntities.whereType<TableInfo>();
|
|
@override
|
|
List<DatabaseSchemaEntity> get allSchemaEntities => [users];
|
|
}
|