mirror of https://github.com/AMT-Cheif/drift.git
Revert unintentional change to example
This commit is contained in:
parent
5740eb8721
commit
a973de343c
|
@ -6,16 +6,6 @@ import 'package:drift/native.dart';
|
||||||
|
|
||||||
part 'main.g.dart';
|
part 'main.g.dart';
|
||||||
|
|
||||||
class Todo extends Table {
|
|
||||||
TextColumn get id => text()();
|
|
||||||
|
|
||||||
TextColumn get listid => text().nullable()();
|
|
||||||
|
|
||||||
TextColumn get text$ => text().named('text').nullable()();
|
|
||||||
|
|
||||||
BoolColumn get completed => boolean()();
|
|
||||||
}
|
|
||||||
|
|
||||||
@DataClassName('TodoCategory')
|
@DataClassName('TodoCategory')
|
||||||
class TodoCategories extends Table {
|
class TodoCategories extends Table {
|
||||||
IntColumn get id => integer().autoIncrement()();
|
IntColumn get id => integer().autoIncrement()();
|
||||||
|
@ -67,7 +57,6 @@ abstract class TodoItemWithCategoryNameView extends View {
|
||||||
}
|
}
|
||||||
|
|
||||||
@DriftDatabase(tables: [
|
@DriftDatabase(tables: [
|
||||||
Todo,
|
|
||||||
TodoItems,
|
TodoItems,
|
||||||
TodoCategories,
|
TodoCategories,
|
||||||
], views: [
|
], views: [
|
||||||
|
|
|
@ -3,270 +3,6 @@
|
||||||
part of 'main.dart';
|
part of 'main.dart';
|
||||||
|
|
||||||
// ignore_for_file: type=lint
|
// ignore_for_file: type=lint
|
||||||
class $TodoTable extends Todo with TableInfo<$TodoTable, TodoData> {
|
|
||||||
@override
|
|
||||||
final GeneratedDatabase attachedDatabase;
|
|
||||||
final String? _alias;
|
|
||||||
$TodoTable(this.attachedDatabase, [this._alias]);
|
|
||||||
static const VerificationMeta _idMeta = const VerificationMeta('id');
|
|
||||||
@override
|
|
||||||
late final GeneratedColumn<String> id = GeneratedColumn<String>(
|
|
||||||
'id', aliasedName, false,
|
|
||||||
type: DriftSqlType.string, requiredDuringInsert: true);
|
|
||||||
static const VerificationMeta _listidMeta = const VerificationMeta('listid');
|
|
||||||
@override
|
|
||||||
late final GeneratedColumn<String> listid = GeneratedColumn<String>(
|
|
||||||
'listid', aliasedName, true,
|
|
||||||
type: DriftSqlType.string, requiredDuringInsert: false);
|
|
||||||
static const VerificationMeta _text$Meta = const VerificationMeta('text\$');
|
|
||||||
@override
|
|
||||||
late final GeneratedColumn<String> text$ = GeneratedColumn<String>(
|
|
||||||
'text', aliasedName, true,
|
|
||||||
type: DriftSqlType.string, requiredDuringInsert: false);
|
|
||||||
static const VerificationMeta _completedMeta =
|
|
||||||
const VerificationMeta('completed');
|
|
||||||
@override
|
|
||||||
late final GeneratedColumn<bool> completed = GeneratedColumn<bool>(
|
|
||||||
'completed', aliasedName, false,
|
|
||||||
type: DriftSqlType.bool,
|
|
||||||
requiredDuringInsert: true,
|
|
||||||
defaultConstraints:
|
|
||||||
GeneratedColumn.constraintIsAlways('CHECK ("completed" IN (0, 1))'));
|
|
||||||
@override
|
|
||||||
List<GeneratedColumn> get $columns => [id, listid, text$, completed];
|
|
||||||
@override
|
|
||||||
String get aliasedName => _alias ?? actualTableName;
|
|
||||||
@override
|
|
||||||
String get actualTableName => $name;
|
|
||||||
static const String $name = 'todo';
|
|
||||||
@override
|
|
||||||
VerificationContext validateIntegrity(Insertable<TodoData> instance,
|
|
||||||
{bool isInserting = false}) {
|
|
||||||
final context = VerificationContext();
|
|
||||||
final data = instance.toColumns(true);
|
|
||||||
if (data.containsKey('id')) {
|
|
||||||
context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta));
|
|
||||||
} else if (isInserting) {
|
|
||||||
context.missing(_idMeta);
|
|
||||||
}
|
|
||||||
if (data.containsKey('listid')) {
|
|
||||||
context.handle(_listidMeta,
|
|
||||||
listid.isAcceptableOrUnknown(data['listid']!, _listidMeta));
|
|
||||||
}
|
|
||||||
if (data.containsKey('text')) {
|
|
||||||
context.handle(
|
|
||||||
_text$Meta, text$.isAcceptableOrUnknown(data['text']!, _text$Meta));
|
|
||||||
}
|
|
||||||
if (data.containsKey('completed')) {
|
|
||||||
context.handle(_completedMeta,
|
|
||||||
completed.isAcceptableOrUnknown(data['completed']!, _completedMeta));
|
|
||||||
} else if (isInserting) {
|
|
||||||
context.missing(_completedMeta);
|
|
||||||
}
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Set<GeneratedColumn> get $primaryKey => const {};
|
|
||||||
@override
|
|
||||||
TodoData map(Map<String, dynamic> data, {String? tablePrefix}) {
|
|
||||||
final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';
|
|
||||||
return TodoData(
|
|
||||||
id: attachedDatabase.typeMapping
|
|
||||||
.read(DriftSqlType.string, data['${effectivePrefix}id'])!,
|
|
||||||
listid: attachedDatabase.typeMapping
|
|
||||||
.read(DriftSqlType.string, data['${effectivePrefix}listid']),
|
|
||||||
text$: attachedDatabase.typeMapping
|
|
||||||
.read(DriftSqlType.string, data['${effectivePrefix}text']),
|
|
||||||
completed: attachedDatabase.typeMapping
|
|
||||||
.read(DriftSqlType.bool, data['${effectivePrefix}completed'])!,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
$TodoTable createAlias(String alias) {
|
|
||||||
return $TodoTable(attachedDatabase, alias);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TodoData extends DataClass implements Insertable<TodoData> {
|
|
||||||
final String id;
|
|
||||||
final String? listid;
|
|
||||||
final String? text$;
|
|
||||||
final bool completed;
|
|
||||||
const TodoData(
|
|
||||||
{required this.id, this.listid, this.text$, required this.completed});
|
|
||||||
@override
|
|
||||||
Map<String, Expression> toColumns(bool nullToAbsent) {
|
|
||||||
final map = <String, Expression>{};
|
|
||||||
map['id'] = Variable<String>(id);
|
|
||||||
if (!nullToAbsent || listid != null) {
|
|
||||||
map['listid'] = Variable<String>(listid);
|
|
||||||
}
|
|
||||||
if (!nullToAbsent || text$ != null) {
|
|
||||||
map['text'] = Variable<String>(text$);
|
|
||||||
}
|
|
||||||
map['completed'] = Variable<bool>(completed);
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
TodoCompanion toCompanion(bool nullToAbsent) {
|
|
||||||
return TodoCompanion(
|
|
||||||
id: Value(id),
|
|
||||||
listid:
|
|
||||||
listid == null && nullToAbsent ? const Value.absent() : Value(listid),
|
|
||||||
text$:
|
|
||||||
text$ == null && nullToAbsent ? const Value.absent() : Value(text$),
|
|
||||||
completed: Value(completed),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
factory TodoData.fromJson(Map<String, dynamic> json,
|
|
||||||
{ValueSerializer? serializer}) {
|
|
||||||
serializer ??= driftRuntimeOptions.defaultSerializer;
|
|
||||||
return TodoData(
|
|
||||||
id: serializer.fromJson<String>(json['id']),
|
|
||||||
listid: serializer.fromJson<String?>(json['listid']),
|
|
||||||
text$: serializer.fromJson<String?>(json['text\$']),
|
|
||||||
completed: serializer.fromJson<bool>(json['completed']),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
factory TodoData.fromJsonString(String encodedJson,
|
|
||||||
{ValueSerializer? serializer}) =>
|
|
||||||
TodoData.fromJson(
|
|
||||||
DataClass.parseJson(encodedJson) as Map<String, dynamic>,
|
|
||||||
serializer: serializer);
|
|
||||||
@override
|
|
||||||
Map<String, dynamic> toJson({ValueSerializer? serializer}) {
|
|
||||||
serializer ??= driftRuntimeOptions.defaultSerializer;
|
|
||||||
return <String, dynamic>{
|
|
||||||
'id': serializer.toJson<String>(id),
|
|
||||||
'listid': serializer.toJson<String?>(listid),
|
|
||||||
'text\$': serializer.toJson<String?>(text$),
|
|
||||||
'completed': serializer.toJson<bool>(completed),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
TodoData copyWith(
|
|
||||||
{String? id,
|
|
||||||
Value<String?> listid = const Value.absent(),
|
|
||||||
Value<String?> text$ = const Value.absent(),
|
|
||||||
bool? completed}) =>
|
|
||||||
TodoData(
|
|
||||||
id: id ?? this.id,
|
|
||||||
listid: listid.present ? listid.value : this.listid,
|
|
||||||
text$: text$.present ? text$.value : this.text$,
|
|
||||||
completed: completed ?? this.completed,
|
|
||||||
);
|
|
||||||
@override
|
|
||||||
String toString() {
|
|
||||||
return (StringBuffer('TodoData(')
|
|
||||||
..write('id: $id, ')
|
|
||||||
..write('listid: $listid, ')
|
|
||||||
..write('text\$: ${text$}, ')
|
|
||||||
..write('completed: $completed')
|
|
||||||
..write(')'))
|
|
||||||
.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
int get hashCode => Object.hash(id, listid, text$, completed);
|
|
||||||
@override
|
|
||||||
bool operator ==(Object other) =>
|
|
||||||
identical(this, other) ||
|
|
||||||
(other is TodoData &&
|
|
||||||
other.id == this.id &&
|
|
||||||
other.listid == this.listid &&
|
|
||||||
other.text$ == this.text$ &&
|
|
||||||
other.completed == this.completed);
|
|
||||||
}
|
|
||||||
|
|
||||||
class TodoCompanion extends UpdateCompanion<TodoData> {
|
|
||||||
final Value<String> id;
|
|
||||||
final Value<String?> listid;
|
|
||||||
final Value<String?> text$;
|
|
||||||
final Value<bool> completed;
|
|
||||||
final Value<int> rowid;
|
|
||||||
const TodoCompanion({
|
|
||||||
this.id = const Value.absent(),
|
|
||||||
this.listid = const Value.absent(),
|
|
||||||
this.text$ = const Value.absent(),
|
|
||||||
this.completed = const Value.absent(),
|
|
||||||
this.rowid = const Value.absent(),
|
|
||||||
});
|
|
||||||
TodoCompanion.insert({
|
|
||||||
required String id,
|
|
||||||
this.listid = const Value.absent(),
|
|
||||||
this.text$ = const Value.absent(),
|
|
||||||
required bool completed,
|
|
||||||
this.rowid = const Value.absent(),
|
|
||||||
}) : id = Value(id),
|
|
||||||
completed = Value(completed);
|
|
||||||
static Insertable<TodoData> custom({
|
|
||||||
Expression<String>? id,
|
|
||||||
Expression<String>? listid,
|
|
||||||
Expression<String>? text$,
|
|
||||||
Expression<bool>? completed,
|
|
||||||
Expression<int>? rowid,
|
|
||||||
}) {
|
|
||||||
return RawValuesInsertable({
|
|
||||||
if (id != null) 'id': id,
|
|
||||||
if (listid != null) 'listid': listid,
|
|
||||||
if (text$ != null) 'text': text$,
|
|
||||||
if (completed != null) 'completed': completed,
|
|
||||||
if (rowid != null) 'rowid': rowid,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
TodoCompanion copyWith(
|
|
||||||
{Value<String>? id,
|
|
||||||
Value<String?>? listid,
|
|
||||||
Value<String?>? text$,
|
|
||||||
Value<bool>? completed,
|
|
||||||
Value<int>? rowid}) {
|
|
||||||
return TodoCompanion(
|
|
||||||
id: id ?? this.id,
|
|
||||||
listid: listid ?? this.listid,
|
|
||||||
text$: text$ ?? this.text$,
|
|
||||||
completed: completed ?? this.completed,
|
|
||||||
rowid: rowid ?? this.rowid,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Map<String, Expression> toColumns(bool nullToAbsent) {
|
|
||||||
final map = <String, Expression>{};
|
|
||||||
if (id.present) {
|
|
||||||
map['id'] = Variable<String>(id.value);
|
|
||||||
}
|
|
||||||
if (listid.present) {
|
|
||||||
map['listid'] = Variable<String>(listid.value);
|
|
||||||
}
|
|
||||||
if (text$.present) {
|
|
||||||
map['text'] = Variable<String>(text$.value);
|
|
||||||
}
|
|
||||||
if (completed.present) {
|
|
||||||
map['completed'] = Variable<bool>(completed.value);
|
|
||||||
}
|
|
||||||
if (rowid.present) {
|
|
||||||
map['rowid'] = Variable<int>(rowid.value);
|
|
||||||
}
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
String toString() {
|
|
||||||
return (StringBuffer('TodoCompanion(')
|
|
||||||
..write('id: $id, ')
|
|
||||||
..write('listid: $listid, ')
|
|
||||||
..write('text\$: ${text$}, ')
|
|
||||||
..write('completed: $completed, ')
|
|
||||||
..write('rowid: $rowid')
|
|
||||||
..write(')'))
|
|
||||||
.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class $TodoCategoriesTable extends TodoCategories
|
class $TodoCategoriesTable extends TodoCategories
|
||||||
with TableInfo<$TodoCategoriesTable, TodoCategory> {
|
with TableInfo<$TodoCategoriesTable, TodoCategory> {
|
||||||
@override
|
@override
|
||||||
|
@ -949,7 +685,6 @@ class $TodoItemWithCategoryNameViewView extends ViewInfo<
|
||||||
|
|
||||||
abstract class _$Database extends GeneratedDatabase {
|
abstract class _$Database extends GeneratedDatabase {
|
||||||
_$Database(QueryExecutor e) : super(e);
|
_$Database(QueryExecutor e) : super(e);
|
||||||
late final $TodoTable todo = $TodoTable(this);
|
|
||||||
late final $TodoCategoriesTable todoCategories = $TodoCategoriesTable(this);
|
late final $TodoCategoriesTable todoCategories = $TodoCategoriesTable(this);
|
||||||
late final $TodoItemsTable todoItems = $TodoItemsTable(this);
|
late final $TodoItemsTable todoItems = $TodoItemsTable(this);
|
||||||
late final $TodoCategoryItemCountView todoCategoryItemCount =
|
late final $TodoCategoryItemCountView todoCategoryItemCount =
|
||||||
|
@ -961,5 +696,5 @@ abstract class _$Database extends GeneratedDatabase {
|
||||||
allSchemaEntities.whereType<TableInfo<Table, Object?>>();
|
allSchemaEntities.whereType<TableInfo<Table, Object?>>();
|
||||||
@override
|
@override
|
||||||
List<DatabaseSchemaEntity> get allSchemaEntities =>
|
List<DatabaseSchemaEntity> get allSchemaEntities =>
|
||||||
[todo, todoCategories, todoItems, todoCategoryItemCount, customViewName];
|
[todoCategories, todoItems, todoCategoryItemCount, customViewName];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue