drift/docs/lib/snippets/migrations/tests/generated_migrations/schema_v1.dart

233 lines
7.1 KiB
Dart

// GENERATED CODE, DO NOT EDIT BY HAND.
// ignore_for_file: type=lint
//@dart=2.12
import 'package:drift/drift.dart';
class Todos extends Table with TableInfo<Todos, TodosData> {
@override
final GeneratedDatabase attachedDatabase;
final String? _alias;
Todos(this.attachedDatabase, [this._alias]);
late final GeneratedColumn<int> id = GeneratedColumn<int>(
'id', aliasedName, false,
hasAutoIncrement: true,
type: DriftSqlType.int,
requiredDuringInsert: false,
defaultConstraints:
GeneratedColumn.constraintIsAlways('PRIMARY KEY AUTOINCREMENT'));
late final GeneratedColumn<String> title = GeneratedColumn<String>(
'title', aliasedName, false,
additionalChecks:
GeneratedColumn.checkTextLength(minTextLength: 6, maxTextLength: 10),
type: DriftSqlType.string,
requiredDuringInsert: true);
late final GeneratedColumn<String> content = GeneratedColumn<String>(
'body', aliasedName, false,
type: DriftSqlType.string, requiredDuringInsert: true);
late final GeneratedColumn<int> category = GeneratedColumn<int>(
'category', aliasedName, true,
type: DriftSqlType.int, requiredDuringInsert: false);
@override
List<GeneratedColumn> get $columns => [id, title, content, category];
@override
String get aliasedName => _alias ?? 'todos';
@override
String get actualTableName => 'todos';
@override
Set<GeneratedColumn> get $primaryKey => {id};
@override
TodosData map(Map<String, dynamic> data, {String? tablePrefix}) {
final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';
return TodosData(
id: attachedDatabase.typeMapping
.read(DriftSqlType.int, data['${effectivePrefix}id'])!,
title: attachedDatabase.typeMapping
.read(DriftSqlType.string, data['${effectivePrefix}title'])!,
content: attachedDatabase.typeMapping
.read(DriftSqlType.string, data['${effectivePrefix}body'])!,
category: attachedDatabase.typeMapping
.read(DriftSqlType.int, data['${effectivePrefix}category']),
);
}
@override
Todos createAlias(String alias) {
return Todos(attachedDatabase, alias);
}
}
class TodosData extends DataClass implements Insertable<TodosData> {
final int id;
final String title;
final String content;
final int? category;
const TodosData(
{required this.id,
required this.title,
required this.content,
this.category});
@override
Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{};
map['id'] = Variable<int>(id);
map['title'] = Variable<String>(title);
map['body'] = Variable<String>(content);
if (!nullToAbsent || category != null) {
map['category'] = Variable<int>(category);
}
return map;
}
TodosCompanion toCompanion(bool nullToAbsent) {
return TodosCompanion(
id: Value(id),
title: Value(title),
content: Value(content),
category: category == null && nullToAbsent
? const Value.absent()
: Value(category),
);
}
factory TodosData.fromJson(Map<String, dynamic> json,
{ValueSerializer? serializer}) {
serializer ??= driftRuntimeOptions.defaultSerializer;
return TodosData(
id: serializer.fromJson<int>(json['id']),
title: serializer.fromJson<String>(json['title']),
content: serializer.fromJson<String>(json['content']),
category: serializer.fromJson<int?>(json['category']),
);
}
@override
Map<String, dynamic> toJson({ValueSerializer? serializer}) {
serializer ??= driftRuntimeOptions.defaultSerializer;
return <String, dynamic>{
'id': serializer.toJson<int>(id),
'title': serializer.toJson<String>(title),
'content': serializer.toJson<String>(content),
'category': serializer.toJson<int?>(category),
};
}
TodosData copyWith(
{int? id,
String? title,
String? content,
Value<int?> category = const Value.absent()}) =>
TodosData(
id: id ?? this.id,
title: title ?? this.title,
content: content ?? this.content,
category: category.present ? category.value : this.category,
);
@override
String toString() {
return (StringBuffer('TodosData(')
..write('id: $id, ')
..write('title: $title, ')
..write('content: $content, ')
..write('category: $category')
..write(')'))
.toString();
}
@override
int get hashCode => Object.hash(id, title, content, category);
@override
bool operator ==(Object other) =>
identical(this, other) ||
(other is TodosData &&
other.id == this.id &&
other.title == this.title &&
other.content == this.content &&
other.category == this.category);
}
class TodosCompanion extends UpdateCompanion<TodosData> {
final Value<int> id;
final Value<String> title;
final Value<String> content;
final Value<int?> category;
const TodosCompanion({
this.id = const Value.absent(),
this.title = const Value.absent(),
this.content = const Value.absent(),
this.category = const Value.absent(),
});
TodosCompanion.insert({
this.id = const Value.absent(),
required String title,
required String content,
this.category = const Value.absent(),
}) : title = Value(title),
content = Value(content);
static Insertable<TodosData> custom({
Expression<int>? id,
Expression<String>? title,
Expression<String>? content,
Expression<int>? category,
}) {
return RawValuesInsertable({
if (id != null) 'id': id,
if (title != null) 'title': title,
if (content != null) 'body': content,
if (category != null) 'category': category,
});
}
TodosCompanion copyWith(
{Value<int>? id,
Value<String>? title,
Value<String>? content,
Value<int?>? category}) {
return TodosCompanion(
id: id ?? this.id,
title: title ?? this.title,
content: content ?? this.content,
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 (title.present) {
map['title'] = Variable<String>(title.value);
}
if (content.present) {
map['body'] = Variable<String>(content.value);
}
if (category.present) {
map['category'] = Variable<int>(category.value);
}
return map;
}
@override
String toString() {
return (StringBuffer('TodosCompanion(')
..write('id: $id, ')
..write('title: $title, ')
..write('content: $content, ')
..write('category: $category')
..write(')'))
.toString();
}
}
class DatabaseAtV1 extends GeneratedDatabase {
DatabaseAtV1(QueryExecutor e) : super(e);
late final Todos todos = Todos(this);
@override
Iterable<TableInfo<Table, Object?>> get allTables =>
allSchemaEntities.whereType<TableInfo<Table, Object?>>();
@override
List<DatabaseSchemaEntity> get allSchemaEntities => [todos];
@override
int get schemaVersion => 1;
}