mirror of https://github.com/AMT-Cheif/drift.git
176 lines
5.1 KiB
Dart
176 lines
5.1 KiB
Dart
// ignore_for_file: type=lint
|
|
import 'package:drift/drift.dart' as i0;
|
|
import 'package:with_built_value/tables.drift.dart' as i1;
|
|
|
|
class Users extends i0.Table with i0.TableInfo<Users, i1.User> {
|
|
@override
|
|
final i0.GeneratedDatabase attachedDatabase;
|
|
final String? _alias;
|
|
Users(this.attachedDatabase, [this._alias]);
|
|
static const i0.VerificationMeta _idMeta = const i0.VerificationMeta('id');
|
|
late final i0.GeneratedColumn<int> id = i0.GeneratedColumn<int>(
|
|
'id', aliasedName, false,
|
|
hasAutoIncrement: true,
|
|
type: i0.DriftSqlType.int,
|
|
requiredDuringInsert: false,
|
|
$customConstraints: 'NOT NULL PRIMARY KEY AUTOINCREMENT');
|
|
static const i0.VerificationMeta _nameMeta =
|
|
const i0.VerificationMeta('name');
|
|
late final i0.GeneratedColumn<String> name = i0.GeneratedColumn<String>(
|
|
'name', aliasedName, false,
|
|
type: i0.DriftSqlType.string,
|
|
requiredDuringInsert: true,
|
|
$customConstraints: 'NOT NULL');
|
|
@override
|
|
List<i0.GeneratedColumn> get $columns => [id, name];
|
|
@override
|
|
String get aliasedName => _alias ?? actualTableName;
|
|
@override
|
|
String get actualTableName => $name;
|
|
static const String $name = 'users';
|
|
@override
|
|
i0.VerificationContext validateIntegrity(i0.Insertable<i1.User> instance,
|
|
{bool isInserting = false}) {
|
|
final context = i0.VerificationContext();
|
|
final data = instance.toColumns(true);
|
|
if (data.containsKey('id')) {
|
|
context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta));
|
|
}
|
|
if (data.containsKey('name')) {
|
|
context.handle(
|
|
_nameMeta, name.isAcceptableOrUnknown(data['name']!, _nameMeta));
|
|
} else if (isInserting) {
|
|
context.missing(_nameMeta);
|
|
}
|
|
return context;
|
|
}
|
|
|
|
@override
|
|
Set<i0.GeneratedColumn> get $primaryKey => {id};
|
|
@override
|
|
i1.User map(Map<String, dynamic> data, {String? tablePrefix}) {
|
|
final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';
|
|
return i1.User(
|
|
id: attachedDatabase.typeMapping
|
|
.read(i0.DriftSqlType.int, data['${effectivePrefix}id'])!,
|
|
name: attachedDatabase.typeMapping
|
|
.read(i0.DriftSqlType.string, data['${effectivePrefix}name'])!,
|
|
);
|
|
}
|
|
|
|
@override
|
|
Users createAlias(String alias) {
|
|
return Users(attachedDatabase, alias);
|
|
}
|
|
|
|
@override
|
|
bool get dontWriteConstraints => true;
|
|
}
|
|
|
|
class User extends i0.DataClass implements i0.Insertable<i1.User> {
|
|
final int id;
|
|
final String name;
|
|
const User({required this.id, required this.name});
|
|
@override
|
|
Map<String, i0.Expression> toColumns(bool nullToAbsent) {
|
|
final map = <String, i0.Expression>{};
|
|
map['id'] = i0.Variable<int>(id);
|
|
map['name'] = i0.Variable<String>(name);
|
|
return map;
|
|
}
|
|
|
|
i1.UsersCompanion toCompanion(bool nullToAbsent) {
|
|
return i1.UsersCompanion(
|
|
id: i0.Value(id),
|
|
name: i0.Value(name),
|
|
);
|
|
}
|
|
|
|
factory User.fromJson(Map<String, dynamic> json,
|
|
{i0.ValueSerializer? serializer}) {
|
|
serializer ??= i0.driftRuntimeOptions.defaultSerializer;
|
|
return User(
|
|
id: serializer.fromJson<int>(json['id']),
|
|
name: serializer.fromJson<String>(json['name']),
|
|
);
|
|
}
|
|
@override
|
|
Map<String, dynamic> toJson({i0.ValueSerializer? serializer}) {
|
|
serializer ??= i0.driftRuntimeOptions.defaultSerializer;
|
|
return <String, dynamic>{
|
|
'id': serializer.toJson<int>(id),
|
|
'name': serializer.toJson<String>(name),
|
|
};
|
|
}
|
|
|
|
i1.User copyWith({int? id, String? name}) => i1.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 => Object.hash(id, name);
|
|
@override
|
|
bool operator ==(Object other) =>
|
|
identical(this, other) ||
|
|
(other is i1.User && other.id == this.id && other.name == this.name);
|
|
}
|
|
|
|
class UsersCompanion extends i0.UpdateCompanion<i1.User> {
|
|
final i0.Value<int> id;
|
|
final i0.Value<String> name;
|
|
const UsersCompanion({
|
|
this.id = const i0.Value.absent(),
|
|
this.name = const i0.Value.absent(),
|
|
});
|
|
UsersCompanion.insert({
|
|
this.id = const i0.Value.absent(),
|
|
required String name,
|
|
}) : name = i0.Value(name);
|
|
static i0.Insertable<i1.User> custom({
|
|
i0.Expression<int>? id,
|
|
i0.Expression<String>? name,
|
|
}) {
|
|
return i0.RawValuesInsertable({
|
|
if (id != null) 'id': id,
|
|
if (name != null) 'name': name,
|
|
});
|
|
}
|
|
|
|
i1.UsersCompanion copyWith({i0.Value<int>? id, i0.Value<String>? name}) {
|
|
return i1.UsersCompanion(
|
|
id: id ?? this.id,
|
|
name: name ?? this.name,
|
|
);
|
|
}
|
|
|
|
@override
|
|
Map<String, i0.Expression> toColumns(bool nullToAbsent) {
|
|
final map = <String, i0.Expression>{};
|
|
if (id.present) {
|
|
map['id'] = i0.Variable<int>(id.value);
|
|
}
|
|
if (name.present) {
|
|
map['name'] = i0.Variable<String>(name.value);
|
|
}
|
|
return map;
|
|
}
|
|
|
|
@override
|
|
String toString() {
|
|
return (StringBuffer('UsersCompanion(')
|
|
..write('id: $id, ')
|
|
..write('name: $name')
|
|
..write(')'))
|
|
.toString();
|
|
}
|
|
}
|