mirror of https://github.com/AMT-Cheif/drift.git
454 lines
14 KiB
Dart
454 lines
14 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 TodoEntry extends DataClass implements Insertable<TodoEntry> {
|
|
final int id;
|
|
final String content;
|
|
final DateTime targetDate;
|
|
final int category;
|
|
TodoEntry(
|
|
{@required this.id,
|
|
@required this.content,
|
|
this.targetDate,
|
|
this.category});
|
|
factory TodoEntry.fromData(Map<String, dynamic> data, GeneratedDatabase db,
|
|
{String prefix}) {
|
|
final effectivePrefix = prefix ?? '';
|
|
final intType = db.typeSystem.forDartType<int>();
|
|
final stringType = db.typeSystem.forDartType<String>();
|
|
final dateTimeType = db.typeSystem.forDartType<DateTime>();
|
|
return TodoEntry(
|
|
id: intType.mapFromDatabaseResponse(data['${effectivePrefix}id']),
|
|
content:
|
|
stringType.mapFromDatabaseResponse(data['${effectivePrefix}content']),
|
|
targetDate: dateTimeType
|
|
.mapFromDatabaseResponse(data['${effectivePrefix}target_date']),
|
|
category:
|
|
intType.mapFromDatabaseResponse(data['${effectivePrefix}category']),
|
|
);
|
|
}
|
|
factory TodoEntry.fromJson(Map<String, dynamic> json,
|
|
{ValueSerializer serializer}) {
|
|
serializer ??= moorRuntimeOptions.defaultSerializer;
|
|
return TodoEntry(
|
|
id: serializer.fromJson<int>(json['id']),
|
|
content: serializer.fromJson<String>(json['content']),
|
|
targetDate: serializer.fromJson<DateTime>(json['targetDate']),
|
|
category: serializer.fromJson<int>(json['category']),
|
|
);
|
|
}
|
|
@override
|
|
Map<String, dynamic> toJson({ValueSerializer serializer}) {
|
|
serializer ??= moorRuntimeOptions.defaultSerializer;
|
|
return <String, dynamic>{
|
|
'id': serializer.toJson<int>(id),
|
|
'content': serializer.toJson<String>(content),
|
|
'targetDate': serializer.toJson<DateTime>(targetDate),
|
|
'category': serializer.toJson<int>(category),
|
|
};
|
|
}
|
|
|
|
@override
|
|
TodosCompanion createCompanion(bool nullToAbsent) {
|
|
return TodosCompanion(
|
|
id: id == null && nullToAbsent ? const Value.absent() : Value(id),
|
|
content: content == null && nullToAbsent
|
|
? const Value.absent()
|
|
: Value(content),
|
|
targetDate: targetDate == null && nullToAbsent
|
|
? const Value.absent()
|
|
: Value(targetDate),
|
|
category: category == null && nullToAbsent
|
|
? const Value.absent()
|
|
: Value(category),
|
|
);
|
|
}
|
|
|
|
TodoEntry copyWith(
|
|
{int id, String content, DateTime targetDate, int category}) =>
|
|
TodoEntry(
|
|
id: id ?? this.id,
|
|
content: content ?? this.content,
|
|
targetDate: targetDate ?? this.targetDate,
|
|
category: category ?? this.category,
|
|
);
|
|
@override
|
|
String toString() {
|
|
return (StringBuffer('TodoEntry(')
|
|
..write('id: $id, ')
|
|
..write('content: $content, ')
|
|
..write('targetDate: $targetDate, ')
|
|
..write('category: $category')
|
|
..write(')'))
|
|
.toString();
|
|
}
|
|
|
|
@override
|
|
int get hashCode => $mrjf($mrjc(id.hashCode,
|
|
$mrjc(content.hashCode, $mrjc(targetDate.hashCode, category.hashCode))));
|
|
@override
|
|
bool operator ==(dynamic other) =>
|
|
identical(this, other) ||
|
|
(other is TodoEntry &&
|
|
other.id == this.id &&
|
|
other.content == this.content &&
|
|
other.targetDate == this.targetDate &&
|
|
other.category == this.category);
|
|
}
|
|
|
|
class TodosCompanion extends UpdateCompanion<TodoEntry> {
|
|
final Value<int> id;
|
|
final Value<String> content;
|
|
final Value<DateTime> targetDate;
|
|
final Value<int> category;
|
|
const TodosCompanion({
|
|
this.id = const Value.absent(),
|
|
this.content = const Value.absent(),
|
|
this.targetDate = const Value.absent(),
|
|
this.category = const Value.absent(),
|
|
});
|
|
TodosCompanion.insert({
|
|
this.id = const Value.absent(),
|
|
@required String content,
|
|
this.targetDate = const Value.absent(),
|
|
this.category = const Value.absent(),
|
|
}) : content = Value(content);
|
|
TodosCompanion copyWith(
|
|
{Value<int> id,
|
|
Value<String> content,
|
|
Value<DateTime> targetDate,
|
|
Value<int> category}) {
|
|
return TodosCompanion(
|
|
id: id ?? this.id,
|
|
content: content ?? this.content,
|
|
targetDate: targetDate ?? this.targetDate,
|
|
category: category ?? this.category,
|
|
);
|
|
}
|
|
}
|
|
|
|
class $TodosTable extends Todos with TableInfo<$TodosTable, TodoEntry> {
|
|
final GeneratedDatabase _db;
|
|
final String _alias;
|
|
$TodosTable(this._db, [this._alias]);
|
|
final VerificationMeta _idMeta = const VerificationMeta('id');
|
|
GeneratedIntColumn _id;
|
|
@override
|
|
GeneratedIntColumn get id => _id ??= _constructId();
|
|
GeneratedIntColumn _constructId() {
|
|
return GeneratedIntColumn('id', $tableName, false,
|
|
hasAutoIncrement: true, declaredAsPrimaryKey: true);
|
|
}
|
|
|
|
final VerificationMeta _contentMeta = const VerificationMeta('content');
|
|
GeneratedTextColumn _content;
|
|
@override
|
|
GeneratedTextColumn get content => _content ??= _constructContent();
|
|
GeneratedTextColumn _constructContent() {
|
|
return GeneratedTextColumn(
|
|
'content',
|
|
$tableName,
|
|
false,
|
|
);
|
|
}
|
|
|
|
final VerificationMeta _targetDateMeta = const VerificationMeta('targetDate');
|
|
GeneratedDateTimeColumn _targetDate;
|
|
@override
|
|
GeneratedDateTimeColumn get targetDate =>
|
|
_targetDate ??= _constructTargetDate();
|
|
GeneratedDateTimeColumn _constructTargetDate() {
|
|
return GeneratedDateTimeColumn(
|
|
'target_date',
|
|
$tableName,
|
|
true,
|
|
);
|
|
}
|
|
|
|
final VerificationMeta _categoryMeta = const VerificationMeta('category');
|
|
GeneratedIntColumn _category;
|
|
@override
|
|
GeneratedIntColumn get category => _category ??= _constructCategory();
|
|
GeneratedIntColumn _constructCategory() {
|
|
return GeneratedIntColumn('category', $tableName, true,
|
|
$customConstraints: 'NULLABLE REFERENCES categories(id)');
|
|
}
|
|
|
|
@override
|
|
List<GeneratedColumn> get $columns => [id, content, targetDate, category];
|
|
@override
|
|
$TodosTable get asDslTable => this;
|
|
@override
|
|
String get $tableName => _alias ?? 'todos';
|
|
@override
|
|
final String actualTableName = 'todos';
|
|
@override
|
|
VerificationContext validateIntegrity(TodosCompanion d,
|
|
{bool isInserting = false}) {
|
|
final context = VerificationContext();
|
|
if (d.id.present) {
|
|
context.handle(_idMeta, id.isAcceptableValue(d.id.value, _idMeta));
|
|
}
|
|
if (d.content.present) {
|
|
context.handle(_contentMeta,
|
|
content.isAcceptableValue(d.content.value, _contentMeta));
|
|
} else if (isInserting) {
|
|
context.missing(_contentMeta);
|
|
}
|
|
if (d.targetDate.present) {
|
|
context.handle(_targetDateMeta,
|
|
targetDate.isAcceptableValue(d.targetDate.value, _targetDateMeta));
|
|
}
|
|
if (d.category.present) {
|
|
context.handle(_categoryMeta,
|
|
category.isAcceptableValue(d.category.value, _categoryMeta));
|
|
}
|
|
return context;
|
|
}
|
|
|
|
@override
|
|
Set<GeneratedColumn> get $primaryKey => {id};
|
|
@override
|
|
TodoEntry map(Map<String, dynamic> data, {String tablePrefix}) {
|
|
final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : null;
|
|
return TodoEntry.fromData(data, _db, prefix: effectivePrefix);
|
|
}
|
|
|
|
@override
|
|
Map<String, Variable> entityToSql(TodosCompanion d) {
|
|
final map = <String, Variable>{};
|
|
if (d.id.present) {
|
|
map['id'] = Variable<int, IntType>(d.id.value);
|
|
}
|
|
if (d.content.present) {
|
|
map['content'] = Variable<String, StringType>(d.content.value);
|
|
}
|
|
if (d.targetDate.present) {
|
|
map['target_date'] = Variable<DateTime, DateTimeType>(d.targetDate.value);
|
|
}
|
|
if (d.category.present) {
|
|
map['category'] = Variable<int, IntType>(d.category.value);
|
|
}
|
|
return map;
|
|
}
|
|
|
|
@override
|
|
$TodosTable createAlias(String alias) {
|
|
return $TodosTable(_db, alias);
|
|
}
|
|
}
|
|
|
|
class Category extends DataClass implements Insertable<Category> {
|
|
final int id;
|
|
final String description;
|
|
Category({@required this.id, @required this.description});
|
|
factory Category.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 Category(
|
|
id: intType.mapFromDatabaseResponse(data['${effectivePrefix}id']),
|
|
description:
|
|
stringType.mapFromDatabaseResponse(data['${effectivePrefix}desc']),
|
|
);
|
|
}
|
|
factory Category.fromJson(Map<String, dynamic> json,
|
|
{ValueSerializer serializer}) {
|
|
serializer ??= moorRuntimeOptions.defaultSerializer;
|
|
return Category(
|
|
id: serializer.fromJson<int>(json['id']),
|
|
description: serializer.fromJson<String>(json['description']),
|
|
);
|
|
}
|
|
@override
|
|
Map<String, dynamic> toJson({ValueSerializer serializer}) {
|
|
serializer ??= moorRuntimeOptions.defaultSerializer;
|
|
return <String, dynamic>{
|
|
'id': serializer.toJson<int>(id),
|
|
'description': serializer.toJson<String>(description),
|
|
};
|
|
}
|
|
|
|
@override
|
|
CategoriesCompanion createCompanion(bool nullToAbsent) {
|
|
return CategoriesCompanion(
|
|
id: id == null && nullToAbsent ? const Value.absent() : Value(id),
|
|
description: description == null && nullToAbsent
|
|
? const Value.absent()
|
|
: Value(description),
|
|
);
|
|
}
|
|
|
|
Category copyWith({int id, String description}) => Category(
|
|
id: id ?? this.id,
|
|
description: description ?? this.description,
|
|
);
|
|
@override
|
|
String toString() {
|
|
return (StringBuffer('Category(')
|
|
..write('id: $id, ')
|
|
..write('description: $description')
|
|
..write(')'))
|
|
.toString();
|
|
}
|
|
|
|
@override
|
|
int get hashCode => $mrjf($mrjc(id.hashCode, description.hashCode));
|
|
@override
|
|
bool operator ==(dynamic other) =>
|
|
identical(this, other) ||
|
|
(other is Category &&
|
|
other.id == this.id &&
|
|
other.description == this.description);
|
|
}
|
|
|
|
class CategoriesCompanion extends UpdateCompanion<Category> {
|
|
final Value<int> id;
|
|
final Value<String> description;
|
|
const CategoriesCompanion({
|
|
this.id = const Value.absent(),
|
|
this.description = const Value.absent(),
|
|
});
|
|
CategoriesCompanion.insert({
|
|
this.id = const Value.absent(),
|
|
@required String description,
|
|
}) : description = Value(description);
|
|
CategoriesCompanion copyWith({Value<int> id, Value<String> description}) {
|
|
return CategoriesCompanion(
|
|
id: id ?? this.id,
|
|
description: description ?? this.description,
|
|
);
|
|
}
|
|
}
|
|
|
|
class $CategoriesTable extends Categories
|
|
with TableInfo<$CategoriesTable, Category> {
|
|
final GeneratedDatabase _db;
|
|
final String _alias;
|
|
$CategoriesTable(this._db, [this._alias]);
|
|
final VerificationMeta _idMeta = const VerificationMeta('id');
|
|
GeneratedIntColumn _id;
|
|
@override
|
|
GeneratedIntColumn get id => _id ??= _constructId();
|
|
GeneratedIntColumn _constructId() {
|
|
return GeneratedIntColumn('id', $tableName, false,
|
|
hasAutoIncrement: true, declaredAsPrimaryKey: true);
|
|
}
|
|
|
|
final VerificationMeta _descriptionMeta =
|
|
const VerificationMeta('description');
|
|
GeneratedTextColumn _description;
|
|
@override
|
|
GeneratedTextColumn get description =>
|
|
_description ??= _constructDescription();
|
|
GeneratedTextColumn _constructDescription() {
|
|
return GeneratedTextColumn(
|
|
'desc',
|
|
$tableName,
|
|
false,
|
|
);
|
|
}
|
|
|
|
@override
|
|
List<GeneratedColumn> get $columns => [id, description];
|
|
@override
|
|
$CategoriesTable get asDslTable => this;
|
|
@override
|
|
String get $tableName => _alias ?? 'categories';
|
|
@override
|
|
final String actualTableName = 'categories';
|
|
@override
|
|
VerificationContext validateIntegrity(CategoriesCompanion d,
|
|
{bool isInserting = false}) {
|
|
final context = VerificationContext();
|
|
if (d.id.present) {
|
|
context.handle(_idMeta, id.isAcceptableValue(d.id.value, _idMeta));
|
|
}
|
|
if (d.description.present) {
|
|
context.handle(_descriptionMeta,
|
|
description.isAcceptableValue(d.description.value, _descriptionMeta));
|
|
} else if (isInserting) {
|
|
context.missing(_descriptionMeta);
|
|
}
|
|
return context;
|
|
}
|
|
|
|
@override
|
|
Set<GeneratedColumn> get $primaryKey => {id};
|
|
@override
|
|
Category map(Map<String, dynamic> data, {String tablePrefix}) {
|
|
final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : null;
|
|
return Category.fromData(data, _db, prefix: effectivePrefix);
|
|
}
|
|
|
|
@override
|
|
Map<String, Variable> entityToSql(CategoriesCompanion d) {
|
|
final map = <String, Variable>{};
|
|
if (d.id.present) {
|
|
map['id'] = Variable<int, IntType>(d.id.value);
|
|
}
|
|
if (d.description.present) {
|
|
map['desc'] = Variable<String, StringType>(d.description.value);
|
|
}
|
|
return map;
|
|
}
|
|
|
|
@override
|
|
$CategoriesTable createAlias(String alias) {
|
|
return $CategoriesTable(_db, alias);
|
|
}
|
|
}
|
|
|
|
abstract class _$Database extends GeneratedDatabase {
|
|
_$Database(QueryExecutor e) : super(SqlTypeSystem.defaultInstance, e);
|
|
$TodosTable _todos;
|
|
$TodosTable get todos => _todos ??= $TodosTable(this);
|
|
$CategoriesTable _categories;
|
|
$CategoriesTable get categories => _categories ??= $CategoriesTable(this);
|
|
Future<int> _resetCategory(int var1) {
|
|
return customUpdate(
|
|
'UPDATE todos SET category = NULL WHERE category = ?',
|
|
variables: [Variable.withInt(var1)],
|
|
updates: {todos},
|
|
);
|
|
}
|
|
|
|
CategoriesWithCountResult _rowToCategoriesWithCountResult(QueryRow row) {
|
|
return CategoriesWithCountResult(
|
|
id: row.readInt('id'),
|
|
desc: row.readString('desc'),
|
|
amount: row.readInt('amount'),
|
|
);
|
|
}
|
|
|
|
Selectable<CategoriesWithCountResult> _categoriesWithCount() {
|
|
return customSelectQuery(
|
|
'SELECT\n c.id,\n c.desc,\n (SELECT COUNT(*) FROM todos WHERE category = c.id) AS amount\n FROM categories c\n UNION ALL\n SELECT null, null, (SELECT COUNT(*) FROM todos WHERE category IS NULL)',
|
|
variables: [],
|
|
readsFrom: {categories, todos}).map(_rowToCategoriesWithCountResult);
|
|
}
|
|
|
|
@override
|
|
Iterable<TableInfo> get allTables => allSchemaEntities.whereType<TableInfo>();
|
|
@override
|
|
List<DatabaseSchemaEntity> get allSchemaEntities => [todos, categories];
|
|
}
|
|
|
|
class CategoriesWithCountResult {
|
|
final int id;
|
|
final String desc;
|
|
final int amount;
|
|
CategoriesWithCountResult({
|
|
this.id,
|
|
this.desc,
|
|
this.amount,
|
|
});
|
|
}
|