mirror of https://github.com/AMT-Cheif/drift.git
475 lines
15 KiB
Dart
475 lines
15 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 ?? '';
|
|
return TodoEntry(
|
|
id: const IntType()
|
|
.mapFromDatabaseResponse(data['${effectivePrefix}id'])!,
|
|
content: const StringType()
|
|
.mapFromDatabaseResponse(data['${effectivePrefix}content'])!,
|
|
targetDate: const DateTimeType()
|
|
.mapFromDatabaseResponse(data['${effectivePrefix}target_date']),
|
|
category: const IntType()
|
|
.mapFromDatabaseResponse(data['${effectivePrefix}category']),
|
|
);
|
|
}
|
|
@override
|
|
Map<String, Expression> toColumns(bool nullToAbsent) {
|
|
final map = <String, Expression>{};
|
|
map['id'] = Variable<int>(id);
|
|
map['content'] = Variable<String>(content);
|
|
if (!nullToAbsent || targetDate != null) {
|
|
map['target_date'] = Variable<DateTime?>(targetDate);
|
|
}
|
|
if (!nullToAbsent || category != null) {
|
|
map['category'] = Variable<int?>(category);
|
|
}
|
|
return map;
|
|
}
|
|
|
|
TodosCompanion toCompanion(bool nullToAbsent) {
|
|
return TodosCompanion(
|
|
id: Value(id),
|
|
content: Value(content),
|
|
targetDate: targetDate == null && nullToAbsent
|
|
? const Value.absent()
|
|
: Value(targetDate),
|
|
category: category == null && nullToAbsent
|
|
? const Value.absent()
|
|
: Value(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),
|
|
};
|
|
}
|
|
|
|
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 => Object.hash(id, content, targetDate, category);
|
|
@override
|
|
bool operator ==(Object 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);
|
|
static Insertable<TodoEntry> custom({
|
|
Expression<int>? id,
|
|
Expression<String>? content,
|
|
Expression<DateTime>? targetDate,
|
|
Expression<int>? category,
|
|
}) {
|
|
return RawValuesInsertable({
|
|
if (id != null) 'id': id,
|
|
if (content != null) 'content': content,
|
|
if (targetDate != null) 'target_date': targetDate,
|
|
if (category != null) 'category': category,
|
|
});
|
|
}
|
|
|
|
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,
|
|
);
|
|
}
|
|
|
|
@override
|
|
Map<String, Expression> toColumns(bool nullToAbsent) {
|
|
final map = <String, Expression>{};
|
|
if (id.present) {
|
|
map['id'] = Variable<int>(id.value);
|
|
}
|
|
if (content.present) {
|
|
map['content'] = Variable<String>(content.value);
|
|
}
|
|
if (targetDate.present) {
|
|
map['target_date'] = Variable<DateTime?>(targetDate.value);
|
|
}
|
|
if (category.present) {
|
|
map['category'] = Variable<int?>(category.value);
|
|
}
|
|
return map;
|
|
}
|
|
|
|
@override
|
|
String toString() {
|
|
return (StringBuffer('TodosCompanion(')
|
|
..write('id: $id, ')
|
|
..write('content: $content, ')
|
|
..write('targetDate: $targetDate, ')
|
|
..write('category: $category')
|
|
..write(')'))
|
|
.toString();
|
|
}
|
|
}
|
|
|
|
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');
|
|
late final GeneratedColumn<int?> id = GeneratedColumn<int?>(
|
|
'id', aliasedName, false,
|
|
typeName: 'INTEGER',
|
|
requiredDuringInsert: false,
|
|
defaultConstraints: 'PRIMARY KEY AUTOINCREMENT');
|
|
final VerificationMeta _contentMeta = const VerificationMeta('content');
|
|
late final GeneratedColumn<String?> content = GeneratedColumn<String?>(
|
|
'content', aliasedName, false,
|
|
typeName: 'TEXT', requiredDuringInsert: true);
|
|
final VerificationMeta _targetDateMeta = const VerificationMeta('targetDate');
|
|
late final GeneratedColumn<DateTime> targetDate = GeneratedColumn<DateTime>(
|
|
'target_date', aliasedName, true,
|
|
typeName: 'INTEGER', requiredDuringInsert: false);
|
|
final VerificationMeta _categoryMeta = const VerificationMeta('category');
|
|
late final GeneratedColumn<int> category = GeneratedColumn<int>(
|
|
'category', aliasedName, true,
|
|
typeName: 'INTEGER',
|
|
requiredDuringInsert: false,
|
|
$customConstraints: 'NULLABLE REFERENCES categories(id)');
|
|
@override
|
|
List<GeneratedColumn> get $columns => [id, content, targetDate, category];
|
|
@override
|
|
String get aliasedName => _alias ?? 'todos';
|
|
@override
|
|
String get actualTableName => 'todos';
|
|
@override
|
|
VerificationContext validateIntegrity(Insertable<TodoEntry> instance,
|
|
{bool isInserting = false}) {
|
|
final context = VerificationContext();
|
|
final data = instance.toColumns(true);
|
|
if (data.containsKey('id')) {
|
|
context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta));
|
|
}
|
|
if (data.containsKey('content')) {
|
|
context.handle(_contentMeta,
|
|
content.isAcceptableOrUnknown(data['content']!, _contentMeta));
|
|
} else if (isInserting) {
|
|
context.missing(_contentMeta);
|
|
}
|
|
if (data.containsKey('target_date')) {
|
|
context.handle(
|
|
_targetDateMeta,
|
|
targetDate.isAcceptableOrUnknown(
|
|
data['target_date']!, _targetDateMeta));
|
|
}
|
|
if (data.containsKey('category')) {
|
|
context.handle(_categoryMeta,
|
|
category.isAcceptableOrUnknown(data['category']!, _categoryMeta));
|
|
}
|
|
return context;
|
|
}
|
|
|
|
@override
|
|
Set<GeneratedColumn> get $primaryKey => {id};
|
|
@override
|
|
TodoEntry map(Map<String, dynamic> data, {String? tablePrefix}) {
|
|
return TodoEntry.fromData(data, _db,
|
|
prefix: tablePrefix != null ? '$tablePrefix.' : null);
|
|
}
|
|
|
|
@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 ?? '';
|
|
return Category(
|
|
id: const IntType()
|
|
.mapFromDatabaseResponse(data['${effectivePrefix}id'])!,
|
|
description: const StringType()
|
|
.mapFromDatabaseResponse(data['${effectivePrefix}desc'])!,
|
|
);
|
|
}
|
|
@override
|
|
Map<String, Expression> toColumns(bool nullToAbsent) {
|
|
final map = <String, Expression>{};
|
|
map['id'] = Variable<int>(id);
|
|
map['desc'] = Variable<String>(description);
|
|
return map;
|
|
}
|
|
|
|
CategoriesCompanion toCompanion(bool nullToAbsent) {
|
|
return CategoriesCompanion(
|
|
id: Value(id),
|
|
description: Value(description),
|
|
);
|
|
}
|
|
|
|
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),
|
|
};
|
|
}
|
|
|
|
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 => Object.hash(id, description);
|
|
@override
|
|
bool operator ==(Object 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);
|
|
static Insertable<Category> custom({
|
|
Expression<int>? id,
|
|
Expression<String>? description,
|
|
}) {
|
|
return RawValuesInsertable({
|
|
if (id != null) 'id': id,
|
|
if (description != null) 'desc': description,
|
|
});
|
|
}
|
|
|
|
CategoriesCompanion copyWith({Value<int>? id, Value<String>? description}) {
|
|
return CategoriesCompanion(
|
|
id: id ?? this.id,
|
|
description: description ?? this.description,
|
|
);
|
|
}
|
|
|
|
@override
|
|
Map<String, Expression> toColumns(bool nullToAbsent) {
|
|
final map = <String, Expression>{};
|
|
if (id.present) {
|
|
map['id'] = Variable<int>(id.value);
|
|
}
|
|
if (description.present) {
|
|
map['desc'] = Variable<String>(description.value);
|
|
}
|
|
return map;
|
|
}
|
|
|
|
@override
|
|
String toString() {
|
|
return (StringBuffer('CategoriesCompanion(')
|
|
..write('id: $id, ')
|
|
..write('description: $description')
|
|
..write(')'))
|
|
.toString();
|
|
}
|
|
}
|
|
|
|
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');
|
|
late final GeneratedColumn<int> id = GeneratedColumn<int>(
|
|
'id', aliasedName, false,
|
|
typeName: 'INTEGER',
|
|
requiredDuringInsert: false,
|
|
defaultConstraints: 'PRIMARY KEY AUTOINCREMENT');
|
|
final VerificationMeta _descriptionMeta =
|
|
const VerificationMeta('description');
|
|
late final GeneratedColumn<String?> description = GeneratedColumn<String?>(
|
|
'desc', aliasedName, false,
|
|
typeName: 'TEXT', requiredDuringInsert: true);
|
|
@override
|
|
List<GeneratedColumn> get $columns => [id, description];
|
|
@override
|
|
String get aliasedName => _alias ?? 'categories';
|
|
@override
|
|
String get actualTableName => 'categories';
|
|
@override
|
|
VerificationContext validateIntegrity(Insertable<Category> instance,
|
|
{bool isInserting = false}) {
|
|
final context = VerificationContext();
|
|
final data = instance.toColumns(true);
|
|
if (data.containsKey('id')) {
|
|
context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta));
|
|
}
|
|
if (data.containsKey('desc')) {
|
|
context.handle(_descriptionMeta,
|
|
description.isAcceptableOrUnknown(data['desc']!, _descriptionMeta));
|
|
} else if (isInserting) {
|
|
context.missing(_descriptionMeta);
|
|
}
|
|
return context;
|
|
}
|
|
|
|
@override
|
|
Set<GeneratedColumn> get $primaryKey => {id};
|
|
@override
|
|
Category map(Map<String, dynamic> data, {String? tablePrefix}) {
|
|
return Category.fromData(data, _db,
|
|
prefix: tablePrefix != null ? '$tablePrefix.' : null);
|
|
}
|
|
|
|
@override
|
|
$CategoriesTable createAlias(String alias) {
|
|
return $CategoriesTable(_db, alias);
|
|
}
|
|
}
|
|
|
|
abstract class _$Database extends GeneratedDatabase {
|
|
_$Database(QueryExecutor e) : super(SqlTypeSystem.defaultInstance, e);
|
|
late final $TodosTable todos = $TodosTable(this);
|
|
late final $CategoriesTable categories = $CategoriesTable(this);
|
|
Future<int> _resetCategory(int? var1) {
|
|
return customUpdate(
|
|
'UPDATE todos SET category = NULL WHERE category = ?',
|
|
variables: [Variable<int?>(var1)],
|
|
updates: {todos},
|
|
updateKind: UpdateKind.update,
|
|
);
|
|
}
|
|
|
|
Selectable<CategoriesWithCountResult> _categoriesWithCount() {
|
|
return customSelect(
|
|
'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((QueryRow row) {
|
|
return CategoriesWithCountResult(
|
|
id: row.read<int?>('id'),
|
|
desc: row.read<String?>('desc'),
|
|
amount: row.read<int>('amount'),
|
|
);
|
|
});
|
|
}
|
|
|
|
@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,
|
|
required this.amount,
|
|
});
|
|
}
|