From 81ba7686c7c99c79bb9995d3b137f3741c089323 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Thu, 13 Oct 2022 22:05:42 +0200 Subject: [PATCH] Generate queries with new analyzer --- drift/test/generated/todos.g.dart | 2184 +++++------------ drift_dev/lib/src/analysis/driver/cache.dart | 17 +- .../src/analysis/resolver/file_analysis.dart | 11 + drift_dev/lib/src/analysis/results/dart.dart | 12 + drift_dev/lib/src/analysis/serializer.dart | 16 +- .../lib/src/backends/build/drift_builder.dart | 20 +- drift_dev/lib/src/writer/database_writer.dart | 23 +- .../lib/src/writer/queries/query_writer.dart | 83 +- .../src/writer/queries/result_set_writer.dart | 35 +- drift_dev/lib/src/writer/queries/utils.dart | 85 + 10 files changed, 857 insertions(+), 1629 deletions(-) create mode 100644 drift_dev/lib/src/writer/queries/utils.dart diff --git a/drift/test/generated/todos.g.dart b/drift/test/generated/todos.g.dart index 1a2690e4..19da24a5 100644 --- a/drift/test/generated/todos.g.dart +++ b/drift/test/generated/todos.g.dart @@ -7,1600 +7,654 @@ part of 'todos.dart'; // DriftElementId(asset:drift/test/generated/todos.dart, categories) // DriftElementId(asset:drift/test/generated/todos.dart, todo_with_category_view) class TodoEntry extends DataClass implements Insertable { - final int id; - final String? title; - final String content; - final DateTime? targetDate; - final int? category; - const TodoEntry( - {required this.id, - this.title, - required this.content, - this.targetDate, - this.category}); - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - map['id'] = Variable(id); - if (!nullToAbsent || title != null) { - map['title'] = Variable(title); - } - map['content'] = Variable(content); - if (!nullToAbsent || targetDate != null) { - map['target_date'] = Variable(targetDate); - } - if (!nullToAbsent || category != null) { - map['category'] = Variable(category); - } - return map; - } - - TodosTableCompanion toCompanion(bool nullToAbsent) { - return TodosTableCompanion( - id: Value(id), - title: - title == null && nullToAbsent ? const Value.absent() : Value(title), - 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 json, - {ValueSerializer? serializer}) { - serializer ??= driftRuntimeOptions.defaultSerializer; - return TodoEntry( - id: serializer.fromJson(json['id']), - title: serializer.fromJson(json['title']), - content: serializer.fromJson(json['content']), - targetDate: serializer.fromJson(json['target_date']), - category: serializer.fromJson(json['category']), - ); - } - factory TodoEntry.fromJsonString(String encodedJson, - {ValueSerializer? serializer}) => - TodoEntry.fromJson( - DataClass.parseJson(encodedJson) as Map, - serializer: serializer); - @override - Map toJson({ValueSerializer? serializer}) { - serializer ??= driftRuntimeOptions.defaultSerializer; - return { - 'id': serializer.toJson(id), - 'title': serializer.toJson(title), - 'content': serializer.toJson(content), - 'target_date': serializer.toJson(targetDate), - 'category': serializer.toJson(category), - }; - } - - TodoEntry copyWith( - {int? id, - Value title = const Value.absent(), - String? content, - Value targetDate = const Value.absent(), - Value category = const Value.absent()}) => - TodoEntry( - id: id ?? this.id, - title: title.present ? title.value : this.title, - content: content ?? this.content, - targetDate: targetDate.present ? targetDate.value : this.targetDate, - category: category.present ? category.value : this.category, - ); - @override - String toString() { - return (StringBuffer('TodoEntry(') - ..write('id: $id, ') - ..write('title: $title, ') - ..write('content: $content, ') - ..write('targetDate: $targetDate, ') - ..write('category: $category') - ..write(')')) - .toString(); - } - - @override - int get hashCode => Object.hash(id, title, content, targetDate, category); - @override - bool operator ==(Object other) => - identical(this, other) || - (other is TodoEntry && - other.id == this.id && - other.title == this.title && - other.content == this.content && - other.targetDate == this.targetDate && - other.category == this.category); +final int id; +final String? title; +final String content; +final DateTime? targetDate; +final int? category; +const TodoEntry({required this.id, this.title, required this.content, this.targetDate, this.category});@override +Map toColumns(bool nullToAbsent) { +final map = {};map['id'] = Variable(id);if (!nullToAbsent || title != null){map['title'] = Variable(title);}map['content'] = Variable(content);if (!nullToAbsent || targetDate != null){map['target_date'] = Variable(targetDate);}if (!nullToAbsent || category != null){map['category'] = Variable(category);}return map; } - -class TodosTableCompanion extends UpdateCompanion { - final Value id; - final Value title; - final Value content; - final Value targetDate; - final Value category; - const TodosTableCompanion({ - this.id = const Value.absent(), - this.title = const Value.absent(), - this.content = const Value.absent(), - this.targetDate = const Value.absent(), - this.category = const Value.absent(), - }); - TodosTableCompanion.insert({ - this.id = const Value.absent(), - this.title = const Value.absent(), - required String content, - this.targetDate = const Value.absent(), - this.category = const Value.absent(), - }) : content = Value(content); - static Insertable custom({ - Expression? id, - Expression? title, - Expression? content, - Expression? targetDate, - Expression? category, - }) { - return RawValuesInsertable({ - if (id != null) 'id': id, - if (title != null) 'title': title, - if (content != null) 'content': content, - if (targetDate != null) 'target_date': targetDate, - if (category != null) 'category': category, - }); - } - - TodosTableCompanion copyWith( - {Value? id, - Value? title, - Value? content, - Value? targetDate, - Value? category}) { - return TodosTableCompanion( - id: id ?? this.id, - title: title ?? this.title, - content: content ?? this.content, - targetDate: targetDate ?? this.targetDate, - category: category ?? this.category, - ); - } - - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (id.present) { - map['id'] = Variable(id.value); - } - if (title.present) { - map['title'] = Variable(title.value); - } - if (content.present) { - map['content'] = Variable(content.value); - } - if (targetDate.present) { - map['target_date'] = Variable(targetDate.value); - } - if (category.present) { - map['category'] = Variable(category.value); - } - return map; - } - - @override - String toString() { - return (StringBuffer('TodosTableCompanion(') - ..write('id: $id, ') - ..write('title: $title, ') - ..write('content: $content, ') - ..write('targetDate: $targetDate, ') - ..write('category: $category') - ..write(')')) - .toString(); - } +TodosTableCompanion toCompanion(bool nullToAbsent) { +return TodosTableCompanion(id: Value (id),title: title == null && nullToAbsent ? const Value.absent() : Value (title),content: Value (content),targetDate: targetDate == null && nullToAbsent ? const Value.absent() : Value (targetDate),category: category == null && nullToAbsent ? const Value.absent() : Value (category),); } - -class $TodosTableTable extends TodosTable - with TableInfo<$TodosTableTable, TodoEntry> { - @override - final GeneratedDatabase attachedDatabase; - final String? _alias; - $TodosTableTable(this.attachedDatabase, [this._alias]); - final VerificationMeta _idMeta = const VerificationMeta('id'); - @override - late final GeneratedColumn id = GeneratedColumn( - 'id', aliasedName, false, - type: DriftSqlType.int, - requiredDuringInsert: false, - defaultConstraints: 'PRIMARY KEY AUTOINCREMENT'); - final VerificationMeta _titleMeta = const VerificationMeta('title'); - @override - late final GeneratedColumn title = GeneratedColumn( - 'title', aliasedName, true, - additionalChecks: - GeneratedColumn.checkTextLength(minTextLength: 4, maxTextLength: 16), - type: DriftSqlType.string, - requiredDuringInsert: false); - final VerificationMeta _contentMeta = const VerificationMeta('content'); - @override - late final GeneratedColumn content = GeneratedColumn( - 'content', aliasedName, false, - type: DriftSqlType.string, requiredDuringInsert: true); - final VerificationMeta _targetDateMeta = const VerificationMeta('targetDate'); - @override - late final GeneratedColumn targetDate = GeneratedColumn( - 'target_date', aliasedName, true, - type: DriftSqlType.dateTime, - requiredDuringInsert: false, - defaultConstraints: 'UNIQUE'); - final VerificationMeta _categoryMeta = const VerificationMeta('category'); - @override - late final GeneratedColumn category = GeneratedColumn( - 'category', aliasedName, true, - type: DriftSqlType.int, - requiredDuringInsert: false, - defaultConstraints: 'REFERENCES categories (id)'); - @override - List get $columns => - [id, title, content, targetDate, category]; - @override - String get aliasedName => _alias ?? 'todos'; - @override - String get actualTableName => 'todos'; - @override - VerificationContext validateIntegrity(Insertable 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('title')) { - context.handle( - _titleMeta, title.isAcceptableOrUnknown(data['title']!, _titleMeta)); - } - 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 get $primaryKey => {id}; - @override - List> get uniqueKeys => [ - {title, category}, - {title, targetDate}, - ]; - @override - TodoEntry map(Map data, {String? tablePrefix}) { - final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; - return TodoEntry( - id: attachedDatabase.options.types - .read(DriftSqlType.int, data['${effectivePrefix}id'])!, - title: attachedDatabase.options.types - .read(DriftSqlType.string, data['${effectivePrefix}title']), - content: attachedDatabase.options.types - .read(DriftSqlType.string, data['${effectivePrefix}content'])!, - targetDate: attachedDatabase.options.types - .read(DriftSqlType.dateTime, data['${effectivePrefix}target_date']), - category: attachedDatabase.options.types - .read(DriftSqlType.int, data['${effectivePrefix}category']), - ); - } - - @override - $TodosTableTable createAlias(String alias) { - return $TodosTableTable(attachedDatabase, alias); - } +factory TodoEntry.fromJson(Map json, {ValueSerializer? serializer}) { +serializer ??= driftRuntimeOptions.defaultSerializer; +return TodoEntry(id: serializer.fromJson(json['id']),title: serializer.fromJson(json['title']),content: serializer.fromJson(json['content']),targetDate: serializer.fromJson(json['target_date']),category: serializer.fromJson(json['category']),);} +factory TodoEntry.fromJsonString(String encodedJson, {ValueSerializer? serializer}) => TodoEntry.fromJson(DataClass.parseJson(encodedJson) as Map, serializer: serializer);@override Map toJson({ValueSerializer? serializer}) { +serializer ??= driftRuntimeOptions.defaultSerializer; +return { +'id': serializer.toJson(id),'title': serializer.toJson(title),'content': serializer.toJson(content),'target_date': serializer.toJson(targetDate),'category': serializer.toJson(category),};}TodoEntry copyWith({int? id,Value title = const Value.absent(),String? content,Value targetDate = const Value.absent(),Value category = const Value.absent()}) => TodoEntry(id: id ?? this.id,title: title.present ? title.value : this.title,content: content ?? this.content,targetDate: targetDate.present ? targetDate.value : this.targetDate,category: category.present ? category.value : this.category,);@override +String toString() {return (StringBuffer('TodoEntry(')..write('id: $id, ')..write('title: $title, ')..write('content: $content, ')..write('targetDate: $targetDate, ')..write('category: $category')..write(')')).toString();} +@override + int get hashCode => Object.hash(id, title, content, targetDate, category);@override +bool operator ==(Object other) => identical(this, other) || (other is TodoEntry && other.id == this.id && other.title == this.title && other.content == this.content && other.targetDate == this.targetDate && other.category == this.category); +}class TodosTableCompanion extends UpdateCompanion { +final Value id; +final Value title; +final Value content; +final Value targetDate; +final Value category; +const TodosTableCompanion({this.id = const Value.absent(),this.title = const Value.absent(),this.content = const Value.absent(),this.targetDate = const Value.absent(),this.category = const Value.absent(),}); +TodosTableCompanion.insert({this.id = const Value.absent(),this.title = const Value.absent(),required String content,this.targetDate = const Value.absent(),this.category = const Value.absent(),}): content = Value(content); +static Insertable custom({Expression? id, +Expression? title, +Expression? content, +Expression? targetDate, +Expression? category, +}) { +return RawValuesInsertable({if (id != null)'id': id,if (title != null)'title': title,if (content != null)'content': content,if (targetDate != null)'target_date': targetDate,if (category != null)'category': category,}); +}TodosTableCompanion copyWith({Value? id, Value? title, Value? content, Value? targetDate, Value? category}) { +return TodosTableCompanion(id: id ?? this.id,title: title ?? this.title,content: content ?? this.content,targetDate: targetDate ?? this.targetDate,category: category ?? this.category,); } - -class Category extends DataClass implements Insertable { - final int id; - final String description; - final CategoryPriority priority; - final String descriptionInUpperCase; - const Category( - {required this.id, - required this.description, - required this.priority, - required this.descriptionInUpperCase}); - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - map['id'] = Variable(id); - map['desc'] = Variable(description); - { - final converter = $CategoriesTable.$converterpriorityn; - map['priority'] = Variable(converter.toSql(priority)); - } - return map; - } - - CategoriesCompanion toCompanion(bool nullToAbsent) { - return CategoriesCompanion( - id: Value(id), - description: Value(description), - priority: Value(priority), - ); - } - - factory Category.fromJson(Map json, - {ValueSerializer? serializer}) { - serializer ??= driftRuntimeOptions.defaultSerializer; - return Category( - id: serializer.fromJson(json['id']), - description: serializer.fromJson(json['description']), - priority: serializer.fromJson(json['priority']), - descriptionInUpperCase: - serializer.fromJson(json['descriptionInUpperCase']), - ); - } - factory Category.fromJsonString(String encodedJson, - {ValueSerializer? serializer}) => - Category.fromJson( - DataClass.parseJson(encodedJson) as Map, - serializer: serializer); - @override - Map toJson({ValueSerializer? serializer}) { - serializer ??= driftRuntimeOptions.defaultSerializer; - return { - 'id': serializer.toJson(id), - 'description': serializer.toJson(description), - 'priority': serializer.toJson(priority), - 'descriptionInUpperCase': - serializer.toJson(descriptionInUpperCase), - }; - } - - Category copyWith( - {int? id, - String? description, - CategoryPriority? priority, - String? descriptionInUpperCase}) => - Category( - id: id ?? this.id, - description: description ?? this.description, - priority: priority ?? this.priority, - descriptionInUpperCase: - descriptionInUpperCase ?? this.descriptionInUpperCase, - ); - @override - String toString() { - return (StringBuffer('Category(') - ..write('id: $id, ') - ..write('description: $description, ') - ..write('priority: $priority, ') - ..write('descriptionInUpperCase: $descriptionInUpperCase') - ..write(')')) - .toString(); - } - - @override - int get hashCode => - Object.hash(id, description, priority, descriptionInUpperCase); - @override - bool operator ==(Object other) => - identical(this, other) || - (other is Category && - other.id == this.id && - other.description == this.description && - other.priority == this.priority && - other.descriptionInUpperCase == this.descriptionInUpperCase); +@override +Map toColumns(bool nullToAbsent) { +final map = {};if (id.present) {map['id'] = Variable(id.value);}if (title.present) {map['title'] = Variable(title.value);}if (content.present) {map['content'] = Variable(content.value);}if (targetDate.present) {map['target_date'] = Variable(targetDate.value);}if (category.present) {map['category'] = Variable(category.value);}return map; } - -class CategoriesCompanion extends UpdateCompanion { - final Value id; - final Value description; - final Value priority; - const CategoriesCompanion({ - this.id = const Value.absent(), - this.description = const Value.absent(), - this.priority = const Value.absent(), - }); - CategoriesCompanion.insert({ - this.id = const Value.absent(), - required String description, - this.priority = const Value.absent(), - }) : description = Value(description); - static Insertable custom({ - Expression? id, - Expression? description, - Expression? priority, - }) { - return RawValuesInsertable({ - if (id != null) 'id': id, - if (description != null) 'desc': description, - if (priority != null) 'priority': priority, - }); - } - - CategoriesCompanion copyWith( - {Value? id, - Value? description, - Value? priority}) { - return CategoriesCompanion( - id: id ?? this.id, - description: description ?? this.description, - priority: priority ?? this.priority, - ); - } - - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (id.present) { - map['id'] = Variable(id.value); - } - if (description.present) { - map['desc'] = Variable(description.value); - } - if (priority.present) { - final converter = $CategoriesTable.$converterpriorityn; - map['priority'] = Variable(converter.toSql(priority.value)); - } - return map; - } - - @override - String toString() { - return (StringBuffer('CategoriesCompanion(') - ..write('id: $id, ') - ..write('description: $description, ') - ..write('priority: $priority') - ..write(')')) - .toString(); - } +@override +String toString() {return (StringBuffer('TodosTableCompanion(')..write('id: $id, ')..write('title: $title, ')..write('content: $content, ')..write('targetDate: $targetDate, ')..write('category: $category')..write(')')).toString();} } - -class $CategoriesTable extends Categories - with TableInfo<$CategoriesTable, Category> { - @override - final GeneratedDatabase attachedDatabase; - final String? _alias; - $CategoriesTable(this.attachedDatabase, [this._alias]); - final VerificationMeta _idMeta = const VerificationMeta('id'); - @override - late final GeneratedColumn id = GeneratedColumn( - 'id', aliasedName, false, - type: DriftSqlType.int, - requiredDuringInsert: false, - defaultConstraints: 'PRIMARY KEY AUTOINCREMENT'); - final VerificationMeta _descriptionMeta = - const VerificationMeta('description'); - @override - late final GeneratedColumn description = GeneratedColumn( - 'desc', aliasedName, false, - type: DriftSqlType.string, - requiredDuringInsert: true, - $customConstraints: 'NOT NULL UNIQUE'); - final VerificationMeta _priorityMeta = const VerificationMeta('priority'); - @override - late final GeneratedColumnWithTypeConverter priority = - GeneratedColumn('priority', aliasedName, false, - type: DriftSqlType.int, - requiredDuringInsert: false, - defaultValue: const Constant(0)) - .withConverter( - $CategoriesTable.$converterpriorityn); - final VerificationMeta _descriptionInUpperCaseMeta = - const VerificationMeta('descriptionInUpperCase'); - @override - late final GeneratedColumn descriptionInUpperCase = - GeneratedColumn('description_in_upper_case', aliasedName, false, - generatedAs: GeneratedAs(description.upper(), false), - type: DriftSqlType.string, - requiredDuringInsert: false); - @override - List get $columns => - [id, description, priority, descriptionInUpperCase]; - @override - String get aliasedName => _alias ?? 'categories'; - @override - String get actualTableName => 'categories'; - @override - VerificationContext validateIntegrity(Insertable 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); - } - context.handle(_priorityMeta, const VerificationResult.success()); - if (data.containsKey('description_in_upper_case')) { - context.handle( - _descriptionInUpperCaseMeta, - descriptionInUpperCase.isAcceptableOrUnknown( - data['description_in_upper_case']!, _descriptionInUpperCaseMeta)); - } - return context; - } - - @override - Set get $primaryKey => {id}; - @override - Category map(Map data, {String? tablePrefix}) { - final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; - return Category( - id: attachedDatabase.options.types - .read(DriftSqlType.int, data['${effectivePrefix}id'])!, - description: attachedDatabase.options.types - .read(DriftSqlType.string, data['${effectivePrefix}desc'])!, - priority: $CategoriesTable.$converterpriorityn.fromSql(attachedDatabase - .options.types - .read(DriftSqlType.int, data['${effectivePrefix}priority'])!), - descriptionInUpperCase: attachedDatabase.options.types.read( - DriftSqlType.string, - data['${effectivePrefix}description_in_upper_case'])!, - ); - } - - @override - $CategoriesTable createAlias(String alias) { - return $CategoriesTable(attachedDatabase, alias); - } - - static TypeConverter $converterpriority = - const EnumIndexConverter(CategoryPriority.values); +class $TodosTableTable extends TodosTable with TableInfo<$TodosTableTable, TodoEntry> { +@override final GeneratedDatabase attachedDatabase; +final String? _alias; +$TodosTableTable(this.attachedDatabase, [this._alias]); +final VerificationMeta _idMeta = const VerificationMeta('id'); +@override +late final GeneratedColumn id = GeneratedColumn('id', aliasedName, false, type: DriftSqlType.int, requiredDuringInsert: false, defaultConstraints: 'PRIMARY KEY AUTOINCREMENT'); +final VerificationMeta _titleMeta = const VerificationMeta('title'); +@override +late final GeneratedColumn title = GeneratedColumn('title', aliasedName, true, additionalChecks: GeneratedColumn.checkTextLength(minTextLength: 4,maxTextLength: 16), type: DriftSqlType.string, requiredDuringInsert: false); +final VerificationMeta _contentMeta = const VerificationMeta('content'); +@override +late final GeneratedColumn content = GeneratedColumn('content', aliasedName, false, type: DriftSqlType.string, requiredDuringInsert: true); +final VerificationMeta _targetDateMeta = const VerificationMeta('targetDate'); +@override +late final GeneratedColumn targetDate = GeneratedColumn('target_date', aliasedName, true, type: DriftSqlType.dateTime, requiredDuringInsert: false, defaultConstraints: 'UNIQUE'); +final VerificationMeta _categoryMeta = const VerificationMeta('category'); +@override +late final GeneratedColumn category = GeneratedColumn('category', aliasedName, true, type: DriftSqlType.int, requiredDuringInsert: false, defaultConstraints: 'REFERENCES categories (id)'); +@override +List get $columns => [id, title, content, targetDate, category]; +@override +String get aliasedName => _alias ?? 'todos'; +@override + String get actualTableName => 'todos'; +@override +VerificationContext validateIntegrity(Insertable 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('title')) { +context.handle(_titleMeta, title.isAcceptableOrUnknown(data['title']!, _titleMeta));}if (data.containsKey('content')) { +context.handle(_contentMeta, content.isAcceptableOrUnknown(data['content']!, _contentMeta));} else if (isInserting) { +context.missing(_contentMeta); } - -class User extends DataClass implements Insertable { - final int id; - final String name; - final bool isAwesome; - final Uint8List profilePicture; - final DateTime creationTime; - const User( - {required this.id, - required this.name, - required this.isAwesome, - required this.profilePicture, - required this.creationTime}); - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - map['id'] = Variable(id); - map['name'] = Variable(name); - map['is_awesome'] = Variable(isAwesome); - map['profile_picture'] = Variable(profilePicture); - map['creation_time'] = Variable(creationTime); - return map; - } - - UsersCompanion toCompanion(bool nullToAbsent) { - return UsersCompanion( - id: Value(id), - name: Value(name), - isAwesome: Value(isAwesome), - profilePicture: Value(profilePicture), - creationTime: Value(creationTime), - ); - } - - factory User.fromJson(Map json, - {ValueSerializer? serializer}) { - serializer ??= driftRuntimeOptions.defaultSerializer; - return User( - id: serializer.fromJson(json['id']), - name: serializer.fromJson(json['name']), - isAwesome: serializer.fromJson(json['isAwesome']), - profilePicture: serializer.fromJson(json['profilePicture']), - creationTime: serializer.fromJson(json['creationTime']), - ); - } - factory User.fromJsonString(String encodedJson, - {ValueSerializer? serializer}) => - User.fromJson(DataClass.parseJson(encodedJson) as Map, - serializer: serializer); - @override - Map toJson({ValueSerializer? serializer}) { - serializer ??= driftRuntimeOptions.defaultSerializer; - return { - 'id': serializer.toJson(id), - 'name': serializer.toJson(name), - 'isAwesome': serializer.toJson(isAwesome), - 'profilePicture': serializer.toJson(profilePicture), - 'creationTime': serializer.toJson(creationTime), - }; - } - - User copyWith( - {int? id, - String? name, - bool? isAwesome, - Uint8List? profilePicture, - DateTime? creationTime}) => - User( - id: id ?? this.id, - name: name ?? this.name, - isAwesome: isAwesome ?? this.isAwesome, - profilePicture: profilePicture ?? this.profilePicture, - creationTime: creationTime ?? this.creationTime, - ); - @override - String toString() { - return (StringBuffer('User(') - ..write('id: $id, ') - ..write('name: $name, ') - ..write('isAwesome: $isAwesome, ') - ..write('profilePicture: $profilePicture, ') - ..write('creationTime: $creationTime') - ..write(')')) - .toString(); - } - - @override - int get hashCode => Object.hash(id, name, isAwesome, - $driftBlobEquality.hash(profilePicture), creationTime); - @override - bool operator ==(Object other) => - identical(this, other) || - (other is User && - other.id == this.id && - other.name == this.name && - other.isAwesome == this.isAwesome && - $driftBlobEquality.equals( - other.profilePicture, this.profilePicture) && - other.creationTime == this.creationTime); +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; } - -class UsersCompanion extends UpdateCompanion { - final Value id; - final Value name; - final Value isAwesome; - final Value profilePicture; - final Value creationTime; - const UsersCompanion({ - this.id = const Value.absent(), - this.name = const Value.absent(), - this.isAwesome = const Value.absent(), - this.profilePicture = const Value.absent(), - this.creationTime = const Value.absent(), - }); - UsersCompanion.insert({ - this.id = const Value.absent(), - required String name, - this.isAwesome = const Value.absent(), - required Uint8List profilePicture, - this.creationTime = const Value.absent(), - }) : name = Value(name), - profilePicture = Value(profilePicture); - static Insertable custom({ - Expression? id, - Expression? name, - Expression? isAwesome, - Expression? profilePicture, - Expression? creationTime, - }) { - return RawValuesInsertable({ - if (id != null) 'id': id, - if (name != null) 'name': name, - if (isAwesome != null) 'is_awesome': isAwesome, - if (profilePicture != null) 'profile_picture': profilePicture, - if (creationTime != null) 'creation_time': creationTime, - }); - } - - UsersCompanion copyWith( - {Value? id, - Value? name, - Value? isAwesome, - Value? profilePicture, - Value? creationTime}) { - return UsersCompanion( - id: id ?? this.id, - name: name ?? this.name, - isAwesome: isAwesome ?? this.isAwesome, - profilePicture: profilePicture ?? this.profilePicture, - creationTime: creationTime ?? this.creationTime, - ); - } - - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (id.present) { - map['id'] = Variable(id.value); - } - if (name.present) { - map['name'] = Variable(name.value); - } - if (isAwesome.present) { - map['is_awesome'] = Variable(isAwesome.value); - } - if (profilePicture.present) { - map['profile_picture'] = Variable(profilePicture.value); - } - if (creationTime.present) { - map['creation_time'] = Variable(creationTime.value); - } - return map; - } - - @override - String toString() { - return (StringBuffer('UsersCompanion(') - ..write('id: $id, ') - ..write('name: $name, ') - ..write('isAwesome: $isAwesome, ') - ..write('profilePicture: $profilePicture, ') - ..write('creationTime: $creationTime') - ..write(')')) - .toString(); - } +@override +Set get $primaryKey => {id}; +@override +List> get uniqueKeys => [{title, category}, +{title, targetDate}, +]; +@override TodoEntry map(Map data, {String? tablePrefix}) { +final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';return TodoEntry(id: attachedDatabase.options.types.read(DriftSqlType.int, data['${effectivePrefix}id'])!, title: attachedDatabase.options.types.read(DriftSqlType.string, data['${effectivePrefix}title']), content: attachedDatabase.options.types.read(DriftSqlType.string, data['${effectivePrefix}content'])!, targetDate: attachedDatabase.options.types.read(DriftSqlType.dateTime, data['${effectivePrefix}target_date']), category: attachedDatabase.options.types.read(DriftSqlType.int, data['${effectivePrefix}category']), ); +} +@override +$TodosTableTable createAlias(String alias) { +return $TodosTableTable(attachedDatabase, alias);}}class Category extends DataClass implements Insertable { +final int id; +final String description; +final CategoryPriority priority; +final String descriptionInUpperCase; +const Category({required this.id, required this.description, required this.priority, required this.descriptionInUpperCase});@override +Map toColumns(bool nullToAbsent) { +final map = {};map['id'] = Variable(id);map['desc'] = Variable(description);{final converter = $CategoriesTable.$converterpriorityn; +map['priority'] = Variable(converter.toSql(priority));}return map; +} +CategoriesCompanion toCompanion(bool nullToAbsent) { +return CategoriesCompanion(id: Value (id),description: Value (description),priority: Value (priority),); +} +factory Category.fromJson(Map json, {ValueSerializer? serializer}) { +serializer ??= driftRuntimeOptions.defaultSerializer; +return Category(id: serializer.fromJson(json['id']),description: serializer.fromJson(json['description']),priority: serializer.fromJson(json['priority']),descriptionInUpperCase: serializer.fromJson(json['descriptionInUpperCase']),);} +factory Category.fromJsonString(String encodedJson, {ValueSerializer? serializer}) => Category.fromJson(DataClass.parseJson(encodedJson) as Map, serializer: serializer);@override Map toJson({ValueSerializer? serializer}) { +serializer ??= driftRuntimeOptions.defaultSerializer; +return { +'id': serializer.toJson(id),'description': serializer.toJson(description),'priority': serializer.toJson(priority),'descriptionInUpperCase': serializer.toJson(descriptionInUpperCase),};}Category copyWith({int? id,String? description,CategoryPriority? priority,String? descriptionInUpperCase}) => Category(id: id ?? this.id,description: description ?? this.description,priority: priority ?? this.priority,descriptionInUpperCase: descriptionInUpperCase ?? this.descriptionInUpperCase,);@override +String toString() {return (StringBuffer('Category(')..write('id: $id, ')..write('description: $description, ')..write('priority: $priority, ')..write('descriptionInUpperCase: $descriptionInUpperCase')..write(')')).toString();} +@override + int get hashCode => Object.hash(id, description, priority, descriptionInUpperCase);@override +bool operator ==(Object other) => identical(this, other) || (other is Category && other.id == this.id && other.description == this.description && other.priority == this.priority && other.descriptionInUpperCase == this.descriptionInUpperCase); +}class CategoriesCompanion extends UpdateCompanion { +final Value id; +final Value description; +final Value priority; +const CategoriesCompanion({this.id = const Value.absent(),this.description = const Value.absent(),this.priority = const Value.absent(),}); +CategoriesCompanion.insert({this.id = const Value.absent(),required String description,required CategoryPriority priority,}): description = Value(description), priority = Value(priority); +static Insertable custom({Expression? id, +Expression? description, +Expression? priority, +}) { +return RawValuesInsertable({if (id != null)'id': id,if (description != null)'desc': description,if (priority != null)'priority': priority,}); +}CategoriesCompanion copyWith({Value? id, Value? description, Value? priority}) { +return CategoriesCompanion(id: id ?? this.id,description: description ?? this.description,priority: priority ?? this.priority,); +} +@override +Map toColumns(bool nullToAbsent) { +final map = {};if (id.present) {map['id'] = Variable(id.value);}if (description.present) {map['desc'] = Variable(description.value);}if (priority.present) {final converter = $CategoriesTable.$converterpriorityn; +map['priority'] = Variable(converter.toSql(priority.value));}return map; +} +@override +String toString() {return (StringBuffer('CategoriesCompanion(')..write('id: $id, ')..write('description: $description, ')..write('priority: $priority')..write(')')).toString();} +} +class $CategoriesTable extends Categories with TableInfo<$CategoriesTable, Category> { +@override final GeneratedDatabase attachedDatabase; +final String? _alias; +$CategoriesTable(this.attachedDatabase, [this._alias]); +final VerificationMeta _idMeta = const VerificationMeta('id'); +@override +late final GeneratedColumn id = GeneratedColumn('id', aliasedName, false, type: DriftSqlType.int, requiredDuringInsert: false, defaultConstraints: 'PRIMARY KEY AUTOINCREMENT'); +final VerificationMeta _descriptionMeta = const VerificationMeta('description'); +@override +late final GeneratedColumn description = GeneratedColumn('desc', aliasedName, false, type: DriftSqlType.string, requiredDuringInsert: true, $customConstraints: 'NOT NULL UNIQUE'); +final VerificationMeta _priorityMeta = const VerificationMeta('priority'); +@override +late final GeneratedColumnWithTypeConverter priority = GeneratedColumn('priority', aliasedName, false, type: DriftSqlType.int, requiredDuringInsert: true).withConverter($CategoriesTable.$converterpriorityn); +final VerificationMeta _descriptionInUpperCaseMeta = const VerificationMeta('descriptionInUpperCase'); +@override +late final GeneratedColumn descriptionInUpperCase = GeneratedColumn('description_in_upper_case', aliasedName, false, generatedAs: GeneratedAs(description.upper(), false), type: DriftSqlType.string, requiredDuringInsert: false); +@override +List get $columns => [id, description, priority, descriptionInUpperCase]; +@override +String get aliasedName => _alias ?? 'categories'; +@override + String get actualTableName => 'categories'; +@override +VerificationContext validateIntegrity(Insertable 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); +} +context.handle(_priorityMeta, const VerificationResult.success());if (data.containsKey('description_in_upper_case')) { +context.handle(_descriptionInUpperCaseMeta, descriptionInUpperCase.isAcceptableOrUnknown(data['description_in_upper_case']!, _descriptionInUpperCaseMeta));}return context; +} +@override +Set get $primaryKey => {id}; +@override Category map(Map data, {String? tablePrefix}) { +final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';return Category(id: attachedDatabase.options.types.read(DriftSqlType.int, data['${effectivePrefix}id'])!, description: attachedDatabase.options.types.read(DriftSqlType.string, data['${effectivePrefix}desc'])!, priority: $CategoriesTable.$converterpriorityn.fromSql(attachedDatabase.options.types.read(DriftSqlType.int, data['${effectivePrefix}priority'])!), descriptionInUpperCase: attachedDatabase.options.types.read(DriftSqlType.string, data['${effectivePrefix}description_in_upper_case'])!, ); +} +@override +$CategoriesTable createAlias(String alias) { +return $CategoriesTable(attachedDatabase, alias);}static TypeConverter $converterpriority = const EnumIndexConverter(CategoryPriority.values);}class User extends DataClass implements Insertable { +final int id; +final String name; +final bool isAwesome; +final Uint8List profilePicture; +final DateTime creationTime; +const User({required this.id, required this.name, required this.isAwesome, required this.profilePicture, required this.creationTime});@override +Map toColumns(bool nullToAbsent) { +final map = {};map['id'] = Variable(id);map['name'] = Variable(name);map['is_awesome'] = Variable(isAwesome);map['profile_picture'] = Variable(profilePicture);map['creation_time'] = Variable(creationTime);return map; +} +UsersCompanion toCompanion(bool nullToAbsent) { +return UsersCompanion(id: Value (id),name: Value (name),isAwesome: Value (isAwesome),profilePicture: Value (profilePicture),creationTime: Value (creationTime),); +} +factory User.fromJson(Map json, {ValueSerializer? serializer}) { +serializer ??= driftRuntimeOptions.defaultSerializer; +return User(id: serializer.fromJson(json['id']),name: serializer.fromJson(json['name']),isAwesome: serializer.fromJson(json['isAwesome']),profilePicture: serializer.fromJson(json['profilePicture']),creationTime: serializer.fromJson(json['creationTime']),);} +factory User.fromJsonString(String encodedJson, {ValueSerializer? serializer}) => User.fromJson(DataClass.parseJson(encodedJson) as Map, serializer: serializer);@override Map toJson({ValueSerializer? serializer}) { +serializer ??= driftRuntimeOptions.defaultSerializer; +return { +'id': serializer.toJson(id),'name': serializer.toJson(name),'isAwesome': serializer.toJson(isAwesome),'profilePicture': serializer.toJson(profilePicture),'creationTime': serializer.toJson(creationTime),};}User copyWith({int? id,String? name,bool? isAwesome,Uint8List? profilePicture,DateTime? creationTime}) => User(id: id ?? this.id,name: name ?? this.name,isAwesome: isAwesome ?? this.isAwesome,profilePicture: profilePicture ?? this.profilePicture,creationTime: creationTime ?? this.creationTime,);@override +String toString() {return (StringBuffer('User(')..write('id: $id, ')..write('name: $name, ')..write('isAwesome: $isAwesome, ')..write('profilePicture: $profilePicture, ')..write('creationTime: $creationTime')..write(')')).toString();} +@override + int get hashCode => Object.hash(id, name, isAwesome, $driftBlobEquality.hash(profilePicture), creationTime);@override +bool operator ==(Object other) => identical(this, other) || (other is User && other.id == this.id && other.name == this.name && other.isAwesome == this.isAwesome && $driftBlobEquality.equals(other.profilePicture, this.profilePicture) && other.creationTime == this.creationTime); +}class UsersCompanion extends UpdateCompanion { +final Value id; +final Value name; +final Value isAwesome; +final Value profilePicture; +final Value creationTime; +const UsersCompanion({this.id = const Value.absent(),this.name = const Value.absent(),this.isAwesome = const Value.absent(),this.profilePicture = const Value.absent(),this.creationTime = const Value.absent(),}); +UsersCompanion.insert({this.id = const Value.absent(),required String name,required bool isAwesome,required Uint8List profilePicture,required DateTime creationTime,}): name = Value(name), isAwesome = Value(isAwesome), profilePicture = Value(profilePicture), creationTime = Value(creationTime); +static Insertable custom({Expression? id, +Expression? name, +Expression? isAwesome, +Expression? profilePicture, +Expression? creationTime, +}) { +return RawValuesInsertable({if (id != null)'id': id,if (name != null)'name': name,if (isAwesome != null)'is_awesome': isAwesome,if (profilePicture != null)'profile_picture': profilePicture,if (creationTime != null)'creation_time': creationTime,}); +}UsersCompanion copyWith({Value? id, Value? name, Value? isAwesome, Value? profilePicture, Value? creationTime}) { +return UsersCompanion(id: id ?? this.id,name: name ?? this.name,isAwesome: isAwesome ?? this.isAwesome,profilePicture: profilePicture ?? this.profilePicture,creationTime: creationTime ?? this.creationTime,); +} +@override +Map toColumns(bool nullToAbsent) { +final map = {};if (id.present) {map['id'] = Variable(id.value);}if (name.present) {map['name'] = Variable(name.value);}if (isAwesome.present) {map['is_awesome'] = Variable(isAwesome.value);}if (profilePicture.present) {map['profile_picture'] = Variable(profilePicture.value);}if (creationTime.present) {map['creation_time'] = Variable(creationTime.value);}return map; +} +@override +String toString() {return (StringBuffer('UsersCompanion(')..write('id: $id, ')..write('name: $name, ')..write('isAwesome: $isAwesome, ')..write('profilePicture: $profilePicture, ')..write('creationTime: $creationTime')..write(')')).toString();} } - class $UsersTable extends Users with TableInfo<$UsersTable, User> { - @override - final GeneratedDatabase attachedDatabase; - final String? _alias; - $UsersTable(this.attachedDatabase, [this._alias]); - final VerificationMeta _idMeta = const VerificationMeta('id'); - @override - late final GeneratedColumn id = GeneratedColumn( - 'id', aliasedName, false, - type: DriftSqlType.int, - requiredDuringInsert: false, - defaultConstraints: 'PRIMARY KEY AUTOINCREMENT'); - final VerificationMeta _nameMeta = const VerificationMeta('name'); - @override - late final GeneratedColumn name = GeneratedColumn( - 'name', aliasedName, false, - additionalChecks: - GeneratedColumn.checkTextLength(minTextLength: 6, maxTextLength: 32), - type: DriftSqlType.string, - requiredDuringInsert: true, - defaultConstraints: 'UNIQUE'); - final VerificationMeta _isAwesomeMeta = const VerificationMeta('isAwesome'); - @override - late final GeneratedColumn isAwesome = GeneratedColumn( - 'is_awesome', aliasedName, false, - type: DriftSqlType.bool, - requiredDuringInsert: false, - defaultConstraints: 'CHECK (is_awesome IN (0, 1))', - defaultValue: const Constant(true)); - final VerificationMeta _profilePictureMeta = - const VerificationMeta('profilePicture'); - @override - late final GeneratedColumn profilePicture = - GeneratedColumn('profile_picture', aliasedName, false, - type: DriftSqlType.blob, requiredDuringInsert: true); - final VerificationMeta _creationTimeMeta = - const VerificationMeta('creationTime'); - @override - late final GeneratedColumn creationTime = GeneratedColumn( - 'creation_time', aliasedName, false, - check: () => creationTime.isBiggerThan(Constant(DateTime.utc(1950))), - type: DriftSqlType.dateTime, - requiredDuringInsert: false, - defaultValue: currentDateAndTime); - @override - List get $columns => - [id, name, isAwesome, profilePicture, creationTime]; - @override - String get aliasedName => _alias ?? 'users'; - @override - String get actualTableName => 'users'; - @override - VerificationContext validateIntegrity(Insertable 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('name')) { - context.handle( - _nameMeta, name.isAcceptableOrUnknown(data['name']!, _nameMeta)); - } else if (isInserting) { - context.missing(_nameMeta); - } - if (data.containsKey('is_awesome')) { - context.handle(_isAwesomeMeta, - isAwesome.isAcceptableOrUnknown(data['is_awesome']!, _isAwesomeMeta)); - } - if (data.containsKey('profile_picture')) { - context.handle( - _profilePictureMeta, - profilePicture.isAcceptableOrUnknown( - data['profile_picture']!, _profilePictureMeta)); - } else if (isInserting) { - context.missing(_profilePictureMeta); - } - if (data.containsKey('creation_time')) { - context.handle( - _creationTimeMeta, - creationTime.isAcceptableOrUnknown( - data['creation_time']!, _creationTimeMeta)); - } - return context; - } - - @override - Set get $primaryKey => {id}; - @override - User map(Map data, {String? tablePrefix}) { - final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; - return User( - id: attachedDatabase.options.types - .read(DriftSqlType.int, data['${effectivePrefix}id'])!, - name: attachedDatabase.options.types - .read(DriftSqlType.string, data['${effectivePrefix}name'])!, - isAwesome: attachedDatabase.options.types - .read(DriftSqlType.bool, data['${effectivePrefix}is_awesome'])!, - profilePicture: attachedDatabase.options.types - .read(DriftSqlType.blob, data['${effectivePrefix}profile_picture'])!, - creationTime: attachedDatabase.options.types.read( - DriftSqlType.dateTime, data['${effectivePrefix}creation_time'])!, - ); - } - - @override - $UsersTable createAlias(String alias) { - return $UsersTable(attachedDatabase, alias); - } +@override final GeneratedDatabase attachedDatabase; +final String? _alias; +$UsersTable(this.attachedDatabase, [this._alias]); +final VerificationMeta _idMeta = const VerificationMeta('id'); +@override +late final GeneratedColumn id = GeneratedColumn('id', aliasedName, false, type: DriftSqlType.int, requiredDuringInsert: false, defaultConstraints: 'PRIMARY KEY AUTOINCREMENT'); +final VerificationMeta _nameMeta = const VerificationMeta('name'); +@override +late final GeneratedColumn name = GeneratedColumn('name', aliasedName, false, additionalChecks: GeneratedColumn.checkTextLength(minTextLength: 6,maxTextLength: 32), type: DriftSqlType.string, requiredDuringInsert: true, defaultConstraints: 'UNIQUE'); +final VerificationMeta _isAwesomeMeta = const VerificationMeta('isAwesome'); +@override +late final GeneratedColumn isAwesome = GeneratedColumn('is_awesome', aliasedName, false, type: DriftSqlType.bool, requiredDuringInsert: true, defaultConstraints: 'CHECK (is_awesome IN (0, 1))'); +final VerificationMeta _profilePictureMeta = const VerificationMeta('profilePicture'); +@override +late final GeneratedColumn profilePicture = GeneratedColumn('profile_picture', aliasedName, false, type: DriftSqlType.blob, requiredDuringInsert: true); +final VerificationMeta _creationTimeMeta = const VerificationMeta('creationTime'); +@override +late final GeneratedColumn creationTime = GeneratedColumn('creation_time', aliasedName, false, check: () => creationTime.isBiggerThan(Constant(DateTime.utc(1950))), type: DriftSqlType.dateTime, requiredDuringInsert: true); +@override +List get $columns => [id, name, isAwesome, profilePicture, creationTime]; +@override +String get aliasedName => _alias ?? 'users'; +@override + String get actualTableName => 'users'; +@override +VerificationContext validateIntegrity(Insertable 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('name')) { +context.handle(_nameMeta, name.isAcceptableOrUnknown(data['name']!, _nameMeta));} else if (isInserting) { +context.missing(_nameMeta); } - -class SharedTodo extends DataClass implements Insertable { - final int todo; - final int user; - const SharedTodo({required this.todo, required this.user}); - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - map['todo'] = Variable(todo); - map['user'] = Variable(user); - return map; - } - - SharedTodosCompanion toCompanion(bool nullToAbsent) { - return SharedTodosCompanion( - todo: Value(todo), - user: Value(user), - ); - } - - factory SharedTodo.fromJson(Map json, - {ValueSerializer? serializer}) { - serializer ??= driftRuntimeOptions.defaultSerializer; - return SharedTodo( - todo: serializer.fromJson(json['todo']), - user: serializer.fromJson(json['user']), - ); - } - factory SharedTodo.fromJsonString(String encodedJson, - {ValueSerializer? serializer}) => - SharedTodo.fromJson( - DataClass.parseJson(encodedJson) as Map, - serializer: serializer); - @override - Map toJson({ValueSerializer? serializer}) { - serializer ??= driftRuntimeOptions.defaultSerializer; - return { - 'todo': serializer.toJson(todo), - 'user': serializer.toJson(user), - }; - } - - SharedTodo copyWith({int? todo, int? user}) => SharedTodo( - todo: todo ?? this.todo, - user: user ?? this.user, - ); - @override - String toString() { - return (StringBuffer('SharedTodo(') - ..write('todo: $todo, ') - ..write('user: $user') - ..write(')')) - .toString(); - } - - @override - int get hashCode => Object.hash(todo, user); - @override - bool operator ==(Object other) => - identical(this, other) || - (other is SharedTodo && - other.todo == this.todo && - other.user == this.user); +if (data.containsKey('is_awesome')) { +context.handle(_isAwesomeMeta, isAwesome.isAcceptableOrUnknown(data['is_awesome']!, _isAwesomeMeta));} else if (isInserting) { +context.missing(_isAwesomeMeta); } - -class SharedTodosCompanion extends UpdateCompanion { - final Value todo; - final Value user; - const SharedTodosCompanion({ - this.todo = const Value.absent(), - this.user = const Value.absent(), - }); - SharedTodosCompanion.insert({ - required int todo, - required int user, - }) : todo = Value(todo), - user = Value(user); - static Insertable custom({ - Expression? todo, - Expression? user, - }) { - return RawValuesInsertable({ - if (todo != null) 'todo': todo, - if (user != null) 'user': user, - }); - } - - SharedTodosCompanion copyWith({Value? todo, Value? user}) { - return SharedTodosCompanion( - todo: todo ?? this.todo, - user: user ?? this.user, - ); - } - - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (todo.present) { - map['todo'] = Variable(todo.value); - } - if (user.present) { - map['user'] = Variable(user.value); - } - return map; - } - - @override - String toString() { - return (StringBuffer('SharedTodosCompanion(') - ..write('todo: $todo, ') - ..write('user: $user') - ..write(')')) - .toString(); - } +if (data.containsKey('profile_picture')) { +context.handle(_profilePictureMeta, profilePicture.isAcceptableOrUnknown(data['profile_picture']!, _profilePictureMeta));} else if (isInserting) { +context.missing(_profilePictureMeta); } - -class $SharedTodosTable extends SharedTodos - with TableInfo<$SharedTodosTable, SharedTodo> { - @override - final GeneratedDatabase attachedDatabase; - final String? _alias; - $SharedTodosTable(this.attachedDatabase, [this._alias]); - final VerificationMeta _todoMeta = const VerificationMeta('todo'); - @override - late final GeneratedColumn todo = GeneratedColumn( - 'todo', aliasedName, false, - type: DriftSqlType.int, requiredDuringInsert: true); - final VerificationMeta _userMeta = const VerificationMeta('user'); - @override - late final GeneratedColumn user = GeneratedColumn( - 'user', aliasedName, false, - type: DriftSqlType.int, requiredDuringInsert: true); - @override - List get $columns => [todo, user]; - @override - String get aliasedName => _alias ?? 'shared_todos'; - @override - String get actualTableName => 'shared_todos'; - @override - VerificationContext validateIntegrity(Insertable instance, - {bool isInserting = false}) { - final context = VerificationContext(); - final data = instance.toColumns(true); - if (data.containsKey('todo')) { - context.handle( - _todoMeta, todo.isAcceptableOrUnknown(data['todo']!, _todoMeta)); - } else if (isInserting) { - context.missing(_todoMeta); - } - if (data.containsKey('user')) { - context.handle( - _userMeta, user.isAcceptableOrUnknown(data['user']!, _userMeta)); - } else if (isInserting) { - context.missing(_userMeta); - } - return context; - } - - @override - Set get $primaryKey => {todo, user}; - @override - SharedTodo map(Map data, {String? tablePrefix}) { - final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; - return SharedTodo( - todo: attachedDatabase.options.types - .read(DriftSqlType.int, data['${effectivePrefix}todo'])!, - user: attachedDatabase.options.types - .read(DriftSqlType.int, data['${effectivePrefix}user'])!, - ); - } - - @override - $SharedTodosTable createAlias(String alias) { - return $SharedTodosTable(attachedDatabase, alias); - } +if (data.containsKey('creation_time')) { +context.handle(_creationTimeMeta, creationTime.isAcceptableOrUnknown(data['creation_time']!, _creationTimeMeta));} else if (isInserting) { +context.missing(_creationTimeMeta); } - -class TableWithoutPKCompanion extends UpdateCompanion { - final Value notReallyAnId; - final Value someFloat; - final Value webSafeInt; - final Value custom; - const TableWithoutPKCompanion({ - this.notReallyAnId = const Value.absent(), - this.someFloat = const Value.absent(), - this.webSafeInt = const Value.absent(), - this.custom = const Value.absent(), - }); - TableWithoutPKCompanion.insert({ - required int notReallyAnId, - required double someFloat, - this.webSafeInt = const Value.absent(), - this.custom = const Value.absent(), - }) : notReallyAnId = Value(notReallyAnId), - someFloat = Value(someFloat); - static Insertable createCustom({ - Expression? notReallyAnId, - Expression? someFloat, - Expression? webSafeInt, - Expression? custom, - }) { - return RawValuesInsertable({ - if (notReallyAnId != null) 'not_really_an_id': notReallyAnId, - if (someFloat != null) 'some_float': someFloat, - if (webSafeInt != null) 'web_safe_int': webSafeInt, - if (custom != null) 'custom': custom, - }); - } - - TableWithoutPKCompanion copyWith( - {Value? notReallyAnId, - Value? someFloat, - Value? webSafeInt, - Value? custom}) { - return TableWithoutPKCompanion( - notReallyAnId: notReallyAnId ?? this.notReallyAnId, - someFloat: someFloat ?? this.someFloat, - webSafeInt: webSafeInt ?? this.webSafeInt, - custom: custom ?? this.custom, - ); - } - - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (notReallyAnId.present) { - map['not_really_an_id'] = Variable(notReallyAnId.value); - } - if (someFloat.present) { - map['some_float'] = Variable(someFloat.value); - } - if (webSafeInt.present) { - map['web_safe_int'] = Variable(webSafeInt.value); - } - if (custom.present) { - final converter = $TableWithoutPKTable.$convertercustomn; - map['custom'] = Variable(converter.toSql(custom.value)); - } - return map; - } - - @override - String toString() { - return (StringBuffer('TableWithoutPKCompanion(') - ..write('notReallyAnId: $notReallyAnId, ') - ..write('someFloat: $someFloat, ') - ..write('webSafeInt: $webSafeInt, ') - ..write('custom: $custom') - ..write(')')) - .toString(); - } +return context; +} +@override +Set get $primaryKey => {id}; +@override User map(Map data, {String? tablePrefix}) { +final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';return User(id: attachedDatabase.options.types.read(DriftSqlType.int, data['${effectivePrefix}id'])!, name: attachedDatabase.options.types.read(DriftSqlType.string, data['${effectivePrefix}name'])!, isAwesome: attachedDatabase.options.types.read(DriftSqlType.bool, data['${effectivePrefix}is_awesome'])!, profilePicture: attachedDatabase.options.types.read(DriftSqlType.blob, data['${effectivePrefix}profile_picture'])!, creationTime: attachedDatabase.options.types.read(DriftSqlType.dateTime, data['${effectivePrefix}creation_time'])!, ); +} +@override +$UsersTable createAlias(String alias) { +return $UsersTable(attachedDatabase, alias);}}class SharedTodo extends DataClass implements Insertable { +final int todo; +final int user; +const SharedTodo({required this.todo, required this.user});@override +Map toColumns(bool nullToAbsent) { +final map = {};map['todo'] = Variable(todo);map['user'] = Variable(user);return map; +} +SharedTodosCompanion toCompanion(bool nullToAbsent) { +return SharedTodosCompanion(todo: Value (todo),user: Value (user),); +} +factory SharedTodo.fromJson(Map json, {ValueSerializer? serializer}) { +serializer ??= driftRuntimeOptions.defaultSerializer; +return SharedTodo(todo: serializer.fromJson(json['todo']),user: serializer.fromJson(json['user']),);} +factory SharedTodo.fromJsonString(String encodedJson, {ValueSerializer? serializer}) => SharedTodo.fromJson(DataClass.parseJson(encodedJson) as Map, serializer: serializer);@override Map toJson({ValueSerializer? serializer}) { +serializer ??= driftRuntimeOptions.defaultSerializer; +return { +'todo': serializer.toJson(todo),'user': serializer.toJson(user),};}SharedTodo copyWith({int? todo,int? user}) => SharedTodo(todo: todo ?? this.todo,user: user ?? this.user,);@override +String toString() {return (StringBuffer('SharedTodo(')..write('todo: $todo, ')..write('user: $user')..write(')')).toString();} +@override + int get hashCode => Object.hash(todo, user);@override +bool operator ==(Object other) => identical(this, other) || (other is SharedTodo && other.todo == this.todo && other.user == this.user); +}class SharedTodosCompanion extends UpdateCompanion { +final Value todo; +final Value user; +const SharedTodosCompanion({this.todo = const Value.absent(),this.user = const Value.absent(),}); +SharedTodosCompanion.insert({required int todo,required int user,}): todo = Value(todo), user = Value(user); +static Insertable custom({Expression? todo, +Expression? user, +}) { +return RawValuesInsertable({if (todo != null)'todo': todo,if (user != null)'user': user,}); +}SharedTodosCompanion copyWith({Value? todo, Value? user}) { +return SharedTodosCompanion(todo: todo ?? this.todo,user: user ?? this.user,); +} +@override +Map toColumns(bool nullToAbsent) { +final map = {};if (todo.present) {map['todo'] = Variable(todo.value);}if (user.present) {map['user'] = Variable(user.value);}return map; +} +@override +String toString() {return (StringBuffer('SharedTodosCompanion(')..write('todo: $todo, ')..write('user: $user')..write(')')).toString();} +} +class $SharedTodosTable extends SharedTodos with TableInfo<$SharedTodosTable, SharedTodo> { +@override final GeneratedDatabase attachedDatabase; +final String? _alias; +$SharedTodosTable(this.attachedDatabase, [this._alias]); +final VerificationMeta _todoMeta = const VerificationMeta('todo'); +@override +late final GeneratedColumn todo = GeneratedColumn('todo', aliasedName, false, type: DriftSqlType.int, requiredDuringInsert: true); +final VerificationMeta _userMeta = const VerificationMeta('user'); +@override +late final GeneratedColumn user = GeneratedColumn('user', aliasedName, false, type: DriftSqlType.int, requiredDuringInsert: true); +@override +List get $columns => [todo, user]; +@override +String get aliasedName => _alias ?? 'shared_todos'; +@override + String get actualTableName => 'shared_todos'; +@override +VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { +final context = VerificationContext(); +final data = instance.toColumns(true); +if (data.containsKey('todo')) { +context.handle(_todoMeta, todo.isAcceptableOrUnknown(data['todo']!, _todoMeta));} else if (isInserting) { +context.missing(_todoMeta); +} +if (data.containsKey('user')) { +context.handle(_userMeta, user.isAcceptableOrUnknown(data['user']!, _userMeta));} else if (isInserting) { +context.missing(_userMeta); +} +return context; +} +@override +Set get $primaryKey => {todo, user}; +@override SharedTodo map(Map data, {String? tablePrefix}) { +final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';return SharedTodo(todo: attachedDatabase.options.types.read(DriftSqlType.int, data['${effectivePrefix}todo'])!, user: attachedDatabase.options.types.read(DriftSqlType.int, data['${effectivePrefix}user'])!, ); +} +@override +$SharedTodosTable createAlias(String alias) { +return $SharedTodosTable(attachedDatabase, alias);}}class TableWithoutPKCompanion extends UpdateCompanion { +final Value notReallyAnId; +final Value someFloat; +final Value webSafeInt; +final Value custom; +const TableWithoutPKCompanion({this.notReallyAnId = const Value.absent(),this.someFloat = const Value.absent(),this.webSafeInt = const Value.absent(),this.custom = const Value.absent(),}); +TableWithoutPKCompanion.insert({required int notReallyAnId,required double someFloat,this.webSafeInt = const Value.absent(),this.custom = const Value.absent(),}): notReallyAnId = Value(notReallyAnId), someFloat = Value(someFloat); +static Insertable createCustom({Expression? notReallyAnId, +Expression? someFloat, +Expression? webSafeInt, +Expression? custom, +}) { +return RawValuesInsertable({if (notReallyAnId != null)'not_really_an_id': notReallyAnId,if (someFloat != null)'some_float': someFloat,if (webSafeInt != null)'web_safe_int': webSafeInt,if (custom != null)'custom': custom,}); +}TableWithoutPKCompanion copyWith({Value? notReallyAnId, Value? someFloat, Value? webSafeInt, Value? custom}) { +return TableWithoutPKCompanion(notReallyAnId: notReallyAnId ?? this.notReallyAnId,someFloat: someFloat ?? this.someFloat,webSafeInt: webSafeInt ?? this.webSafeInt,custom: custom ?? this.custom,); +} +@override +Map toColumns(bool nullToAbsent) { +final map = {};if (notReallyAnId.present) {map['not_really_an_id'] = Variable(notReallyAnId.value);}if (someFloat.present) {map['some_float'] = Variable(someFloat.value);}if (webSafeInt.present) {map['web_safe_int'] = Variable(webSafeInt.value);}if (custom.present) {final converter = $TableWithoutPKTable.$convertercustomn; +map['custom'] = Variable(converter.toSql(custom.value));}return map; +} +@override +String toString() {return (StringBuffer('TableWithoutPKCompanion(')..write('notReallyAnId: $notReallyAnId, ')..write('someFloat: $someFloat, ')..write('webSafeInt: $webSafeInt, ')..write('custom: $custom')..write(')')).toString();} } - class _$CustomRowClassInsertable implements Insertable { - CustomRowClass _object; +CustomRowClass _object; - _$CustomRowClassInsertable(this._object); +_$CustomRowClassInsertable(this._object); - @override - Map toColumns(bool nullToAbsent) { - return TableWithoutPKCompanion( - custom: Value(_object.custom), - webSafeInt: Value(_object.webSafeInt), - ).toColumns(false); - } +@override +Map toColumns(bool nullToAbsent) { +return TableWithoutPKCompanion( +custom: Value (_object.custom), +webSafeInt: Value (_object.webSafeInt), +).toColumns(false); +} } -extension CustomRowClassToInsertable on CustomRowClass { - _$CustomRowClassInsertable toInsertable() { - return _$CustomRowClassInsertable(this); - } +extension CustomRowClassToInsertable on CustomRowClass {_$CustomRowClassInsertable toInsertable() { +return _$CustomRowClassInsertable(this); } - -class $TableWithoutPKTable extends TableWithoutPK - with TableInfo<$TableWithoutPKTable, CustomRowClass> { - @override - final GeneratedDatabase attachedDatabase; - final String? _alias; - $TableWithoutPKTable(this.attachedDatabase, [this._alias]); - final VerificationMeta _notReallyAnIdMeta = - const VerificationMeta('notReallyAnId'); - @override - late final GeneratedColumn notReallyAnId = GeneratedColumn( - 'not_really_an_id', aliasedName, false, - type: DriftSqlType.int, requiredDuringInsert: true); - final VerificationMeta _someFloatMeta = const VerificationMeta('someFloat'); - @override - late final GeneratedColumn someFloat = GeneratedColumn( - 'some_float', aliasedName, false, - type: DriftSqlType.double, requiredDuringInsert: true); - final VerificationMeta _webSafeIntMeta = const VerificationMeta('webSafeInt'); - @override - late final GeneratedColumn webSafeInt = GeneratedColumn( - 'web_safe_int', aliasedName, true, - type: DriftSqlType.bigInt, requiredDuringInsert: false); - final VerificationMeta _customMeta = const VerificationMeta('custom'); - @override - late final GeneratedColumnWithTypeConverter custom = - GeneratedColumn('custom', aliasedName, false, - type: DriftSqlType.string, - requiredDuringInsert: false, - clientDefault: _uuid.v4) - .withConverter( - $TableWithoutPKTable.$convertercustomn); - @override - List get $columns => - [notReallyAnId, someFloat, webSafeInt, custom]; - @override - String get aliasedName => _alias ?? 'table_without_p_k'; - @override - String get actualTableName => 'table_without_p_k'; - @override - VerificationContext validateIntegrity(Insertable instance, - {bool isInserting = false}) { - final context = VerificationContext(); - final data = instance.toColumns(true); - if (data.containsKey('not_really_an_id')) { - context.handle( - _notReallyAnIdMeta, - notReallyAnId.isAcceptableOrUnknown( - data['not_really_an_id']!, _notReallyAnIdMeta)); - } else if (isInserting) { - context.missing(_notReallyAnIdMeta); - } - if (data.containsKey('some_float')) { - context.handle(_someFloatMeta, - someFloat.isAcceptableOrUnknown(data['some_float']!, _someFloatMeta)); - } else if (isInserting) { - context.missing(_someFloatMeta); - } - if (data.containsKey('web_safe_int')) { - context.handle( - _webSafeIntMeta, - webSafeInt.isAcceptableOrUnknown( - data['web_safe_int']!, _webSafeIntMeta)); - } - context.handle(_customMeta, const VerificationResult.success()); - return context; - } - - @override - Set get $primaryKey => const {}; - @override - CustomRowClass map(Map data, {String? tablePrefix}) { - final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; - return CustomRowClass.map( - attachedDatabase.options.types - .read(DriftSqlType.int, data['${effectivePrefix}not_really_an_id'])!, - attachedDatabase.options.types - .read(DriftSqlType.double, data['${effectivePrefix}some_float'])!, - custom: $TableWithoutPKTable.$convertercustomn.fromSql(attachedDatabase - .options.types - .read(DriftSqlType.string, data['${effectivePrefix}custom'])!), - webSafeInt: attachedDatabase.options.types - .read(DriftSqlType.bigInt, data['${effectivePrefix}web_safe_int']), - ); - } - - @override - $TableWithoutPKTable createAlias(String alias) { - return $TableWithoutPKTable(attachedDatabase, alias); - } - - static TypeConverter $convertercustom = - const CustomConverter(); } - -class PureDefault extends DataClass implements Insertable { - final MyCustomObject? txt; - const PureDefault({this.txt}); - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (!nullToAbsent || txt != null) { - final converter = $PureDefaultsTable.$convertertxt; - map['insert'] = Variable(converter.toSql(txt)); - } - return map; - } - - PureDefaultsCompanion toCompanion(bool nullToAbsent) { - return PureDefaultsCompanion( - txt: txt == null && nullToAbsent ? const Value.absent() : Value(txt), - ); - } - - factory PureDefault.fromJson(Map json, - {ValueSerializer? serializer}) { - serializer ??= driftRuntimeOptions.defaultSerializer; - return PureDefault( - txt: $PureDefaultsTable.$convertertxt - .fromJson(serializer.fromJson(json['txt'])), - ); - } - factory PureDefault.fromJsonString(String encodedJson, - {ValueSerializer? serializer}) => - PureDefault.fromJson( - DataClass.parseJson(encodedJson) as Map, - serializer: serializer); - @override - Map toJson({ValueSerializer? serializer}) { - serializer ??= driftRuntimeOptions.defaultSerializer; - return { - 'txt': serializer - .toJson($PureDefaultsTable.$convertertxt.toJson(txt)), - }; - } - - PureDefault copyWith({Value txt = const Value.absent()}) => - PureDefault( - txt: txt.present ? txt.value : this.txt, - ); - @override - String toString() { - return (StringBuffer('PureDefault(') - ..write('txt: $txt') - ..write(')')) - .toString(); - } - - @override - int get hashCode => txt.hashCode; - @override - bool operator ==(Object other) => - identical(this, other) || (other is PureDefault && other.txt == this.txt); +class $TableWithoutPKTable extends TableWithoutPK with TableInfo<$TableWithoutPKTable, CustomRowClass> { +@override final GeneratedDatabase attachedDatabase; +final String? _alias; +$TableWithoutPKTable(this.attachedDatabase, [this._alias]); +final VerificationMeta _notReallyAnIdMeta = const VerificationMeta('notReallyAnId'); +@override +late final GeneratedColumn notReallyAnId = GeneratedColumn('not_really_an_id', aliasedName, false, type: DriftSqlType.int, requiredDuringInsert: true); +final VerificationMeta _someFloatMeta = const VerificationMeta('someFloat'); +@override +late final GeneratedColumn someFloat = GeneratedColumn('some_float', aliasedName, false, type: DriftSqlType.double, requiredDuringInsert: true); +final VerificationMeta _webSafeIntMeta = const VerificationMeta('webSafeInt'); +@override +late final GeneratedColumn webSafeInt = GeneratedColumn('web_safe_int', aliasedName, true, type: DriftSqlType.bigInt, requiredDuringInsert: false); +final VerificationMeta _customMeta = const VerificationMeta('custom'); +@override +late final GeneratedColumnWithTypeConverter custom = GeneratedColumn('custom', aliasedName, false, type: DriftSqlType.string, requiredDuringInsert: false, defaultValue: _uuid.v4, clientDefault: _uuid.v4).withConverter($TableWithoutPKTable.$convertercustomn); +@override +List get $columns => [notReallyAnId, someFloat, webSafeInt, custom]; +@override +String get aliasedName => _alias ?? 'table_without_p_k'; +@override + String get actualTableName => 'table_without_p_k'; +@override +VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { +final context = VerificationContext(); +final data = instance.toColumns(true); +if (data.containsKey('not_really_an_id')) { +context.handle(_notReallyAnIdMeta, notReallyAnId.isAcceptableOrUnknown(data['not_really_an_id']!, _notReallyAnIdMeta));} else if (isInserting) { +context.missing(_notReallyAnIdMeta); } - -class PureDefaultsCompanion extends UpdateCompanion { - final Value txt; - const PureDefaultsCompanion({ - this.txt = const Value.absent(), - }); - PureDefaultsCompanion.insert({ - this.txt = const Value.absent(), - }); - static Insertable custom({ - Expression? txt, - }) { - return RawValuesInsertable({ - if (txt != null) 'insert': txt, - }); - } - - PureDefaultsCompanion copyWith({Value? txt}) { - return PureDefaultsCompanion( - txt: txt ?? this.txt, - ); - } - - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (txt.present) { - final converter = $PureDefaultsTable.$convertertxt; - map['insert'] = Variable(converter.toSql(txt.value)); - } - return map; - } - - @override - String toString() { - return (StringBuffer('PureDefaultsCompanion(') - ..write('txt: $txt') - ..write(')')) - .toString(); - } +if (data.containsKey('some_float')) { +context.handle(_someFloatMeta, someFloat.isAcceptableOrUnknown(data['some_float']!, _someFloatMeta));} else if (isInserting) { +context.missing(_someFloatMeta); } - -class $PureDefaultsTable extends PureDefaults - with TableInfo<$PureDefaultsTable, PureDefault> { - @override - final GeneratedDatabase attachedDatabase; - final String? _alias; - $PureDefaultsTable(this.attachedDatabase, [this._alias]); - final VerificationMeta _txtMeta = const VerificationMeta('txt'); - @override - late final GeneratedColumnWithTypeConverter txt = - GeneratedColumn('insert', aliasedName, true, - type: DriftSqlType.string, requiredDuringInsert: false) - .withConverter($PureDefaultsTable.$convertertxt); - @override - List get $columns => [txt]; - @override - String get aliasedName => _alias ?? 'pure_defaults'; - @override - String get actualTableName => 'pure_defaults'; - @override - VerificationContext validateIntegrity(Insertable instance, - {bool isInserting = false}) { - final context = VerificationContext(); - final data = instance.toColumns(true); - context.handle(_txtMeta, const VerificationResult.success()); - return context; - } - - @override - Set get $primaryKey => {txt}; - @override - PureDefault map(Map data, {String? tablePrefix}) { - final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; - return PureDefault( - txt: $PureDefaultsTable.$convertertxt.fromSql(attachedDatabase - .options.types - .read(DriftSqlType.string, data['${effectivePrefix}insert'])), - ); - } - - @override - $PureDefaultsTable createAlias(String alias) { - return $PureDefaultsTable(attachedDatabase, alias); - } - - static JsonTypeConverter $convertertxt = - const CustomJsonConverter(); - static JsonTypeConverter $convertertxtn = - JsonTypeConverter.asNullable($convertertxt); +if (data.containsKey('web_safe_int')) { +context.handle(_webSafeIntMeta, webSafeInt.isAcceptableOrUnknown(data['web_safe_int']!, _webSafeIntMeta));}context.handle(_customMeta, const VerificationResult.success());return context; } - -class CategoryTodoCountViewData extends DataClass { - final String? description; - final int? itemCount; - const CategoryTodoCountViewData({this.description, this.itemCount}); - factory CategoryTodoCountViewData.fromJson(Map json, - {ValueSerializer? serializer}) { - serializer ??= driftRuntimeOptions.defaultSerializer; - return CategoryTodoCountViewData( - description: serializer.fromJson(json['description']), - itemCount: serializer.fromJson(json['itemCount']), - ); - } - factory CategoryTodoCountViewData.fromJsonString(String encodedJson, - {ValueSerializer? serializer}) => - CategoryTodoCountViewData.fromJson( - DataClass.parseJson(encodedJson) as Map, - serializer: serializer); - @override - Map toJson({ValueSerializer? serializer}) { - serializer ??= driftRuntimeOptions.defaultSerializer; - return { - 'description': serializer.toJson(description), - 'itemCount': serializer.toJson(itemCount), - }; - } - - CategoryTodoCountViewData copyWith( - {Value description = const Value.absent(), - Value itemCount = const Value.absent()}) => - CategoryTodoCountViewData( - description: description.present ? description.value : this.description, - itemCount: itemCount.present ? itemCount.value : this.itemCount, - ); - @override - String toString() { - return (StringBuffer('CategoryTodoCountViewData(') - ..write('description: $description, ') - ..write('itemCount: $itemCount') - ..write(')')) - .toString(); - } - - @override - int get hashCode => Object.hash(description, itemCount); - @override - bool operator ==(Object other) => - identical(this, other) || - (other is CategoryTodoCountViewData && - other.description == this.description && - other.itemCount == this.itemCount); +@override +Set get $primaryKey => const {};@override CustomRowClass map(Map data, {String? tablePrefix}) { +final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';return CustomRowClass.map(attachedDatabase.options.types.read(DriftSqlType.int, data['${effectivePrefix}not_really_an_id'])!, attachedDatabase.options.types.read(DriftSqlType.double, data['${effectivePrefix}some_float'])!, custom: $TableWithoutPKTable.$convertercustomn.fromSql(attachedDatabase.options.types.read(DriftSqlType.string, data['${effectivePrefix}custom'])!), webSafeInt: attachedDatabase.options.types.read(DriftSqlType.bigInt, data['${effectivePrefix}web_safe_int']), ); } - -class $CategoryTodoCountViewView - extends ViewInfo<$CategoryTodoCountViewView, CategoryTodoCountViewData> - implements HasResultSet { - final String? _alias; - @override - final _$TodoDb attachedDatabase; - $CategoryTodoCountViewView(this.attachedDatabase, [this._alias]); - $TodosTableTable get todos => attachedDatabase.todosTable.createAlias('t0'); - $CategoriesTable get categories => - attachedDatabase.categories.createAlias('t1'); - @override - List get $columns => [description, itemCount]; - @override - String get aliasedName => _alias ?? entityName; - @override - String get entityName => 'category_todo_count_view'; - @override - String? get createViewStmt => null; - @override - $CategoryTodoCountViewView get asDslTable => this; - @override - CategoryTodoCountViewData map(Map data, - {String? tablePrefix}) { - final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; - return CategoryTodoCountViewData( - description: attachedDatabase.options.types - .read(DriftSqlType.string, data['${effectivePrefix}description']), - itemCount: attachedDatabase.options.types - .read(DriftSqlType.int, data['${effectivePrefix}item_count']), - ); - } - - late final GeneratedColumn description = GeneratedColumn( - 'description', aliasedName, true, - generatedAs: - GeneratedAs(categories.description + const Variable('!'), false), - type: DriftSqlType.string); - late final GeneratedColumn itemCount = GeneratedColumn( - 'item_count', aliasedName, true, - generatedAs: GeneratedAs(todos.id.count(), false), - type: DriftSqlType.int); - @override - $CategoryTodoCountViewView createAlias(String alias) { - return $CategoryTodoCountViewView(attachedDatabase, alias); - } - - @override - Query? get query => - (attachedDatabase.selectOnly(categories)..addColumns($columns)) - .join([innerJoin(todos, todos.category.equalsExp(categories.id))]) - ..groupBy([categories.id]); - @override - Set get readTables => const {'todos', 'categories'}; +@override +$TableWithoutPKTable createAlias(String alias) { +return $TableWithoutPKTable(attachedDatabase, alias);}static TypeConverter $convertercustom = const CustomConverter();}class PureDefault extends DataClass implements Insertable { +final MyCustomObject? txt; +const PureDefault({this.txt});@override +Map toColumns(bool nullToAbsent) { +final map = {};if (!nullToAbsent || txt != null){final converter = $PureDefaultsTable.$convertertxt; +map['insert'] = Variable(converter.toSql(txt));}return map; +} +PureDefaultsCompanion toCompanion(bool nullToAbsent) { +return PureDefaultsCompanion(txt: txt == null && nullToAbsent ? const Value.absent() : Value (txt),); +} +factory PureDefault.fromJson(Map json, {ValueSerializer? serializer}) { +serializer ??= driftRuntimeOptions.defaultSerializer; +return PureDefault(txt: $PureDefaultsTable.$convertertxt.fromJson(serializer.fromJson(json['txt'])),);} +factory PureDefault.fromJsonString(String encodedJson, {ValueSerializer? serializer}) => PureDefault.fromJson(DataClass.parseJson(encodedJson) as Map, serializer: serializer);@override Map toJson({ValueSerializer? serializer}) { +serializer ??= driftRuntimeOptions.defaultSerializer; +return { +'txt': serializer.toJson($PureDefaultsTable.$convertertxt.toJson(txt)),};}PureDefault copyWith({Value txt = const Value.absent()}) => PureDefault(txt: txt.present ? txt.value : this.txt,);@override +String toString() {return (StringBuffer('PureDefault(')..write('txt: $txt')..write(')')).toString();} +@override + int get hashCode => txt.hashCode;@override +bool operator ==(Object other) => identical(this, other) || (other is PureDefault && other.txt == this.txt); +}class PureDefaultsCompanion extends UpdateCompanion { +final Value txt; +const PureDefaultsCompanion({this.txt = const Value.absent(),}); +PureDefaultsCompanion.insert({this.txt = const Value.absent(),}); +static Insertable custom({Expression? txt, +}) { +return RawValuesInsertable({if (txt != null)'insert': txt,}); +}PureDefaultsCompanion copyWith({Value? txt}) { +return PureDefaultsCompanion(txt: txt ?? this.txt,); +} +@override +Map toColumns(bool nullToAbsent) { +final map = {};if (txt.present) {final converter = $PureDefaultsTable.$convertertxt; +map['insert'] = Variable(converter.toSql(txt.value));}return map; +} +@override +String toString() {return (StringBuffer('PureDefaultsCompanion(')..write('txt: $txt')..write(')')).toString();} +} +class $PureDefaultsTable extends PureDefaults with TableInfo<$PureDefaultsTable, PureDefault> { +@override final GeneratedDatabase attachedDatabase; +final String? _alias; +$PureDefaultsTable(this.attachedDatabase, [this._alias]); +final VerificationMeta _txtMeta = const VerificationMeta('txt'); +@override +late final GeneratedColumnWithTypeConverter txt = GeneratedColumn('insert', aliasedName, true, type: DriftSqlType.string, requiredDuringInsert: false).withConverter($PureDefaultsTable.$convertertxt); +@override +List get $columns => [txt]; +@override +String get aliasedName => _alias ?? 'pure_defaults'; +@override + String get actualTableName => 'pure_defaults'; +@override +VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { +final context = VerificationContext(); +final data = instance.toColumns(true); +context.handle(_txtMeta, const VerificationResult.success());return context; +} +@override +Set get $primaryKey => {txt}; +@override PureDefault map(Map data, {String? tablePrefix}) { +final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';return PureDefault(txt: $PureDefaultsTable.$convertertxt.fromSql(attachedDatabase.options.types.read(DriftSqlType.string, data['${effectivePrefix}insert'])), ); +} +@override +$PureDefaultsTable createAlias(String alias) { +return $PureDefaultsTable(attachedDatabase, alias);}static JsonTypeConverter $convertertxt = const CustomJsonConverter();static JsonTypeConverter $convertertxtn = JsonTypeConverter.asNullable($convertertxt);}class CategoryTodoCountViewData extends DataClass { +final String? description; +final int? itemCount; +const CategoryTodoCountViewData({this.description, this.itemCount});factory CategoryTodoCountViewData.fromJson(Map json, {ValueSerializer? serializer}) { +serializer ??= driftRuntimeOptions.defaultSerializer; +return CategoryTodoCountViewData(description: serializer.fromJson(json['description']),itemCount: serializer.fromJson(json['itemCount']),);} +factory CategoryTodoCountViewData.fromJsonString(String encodedJson, {ValueSerializer? serializer}) => CategoryTodoCountViewData.fromJson(DataClass.parseJson(encodedJson) as Map, serializer: serializer);@override Map toJson({ValueSerializer? serializer}) { +serializer ??= driftRuntimeOptions.defaultSerializer; +return { +'description': serializer.toJson(description),'itemCount': serializer.toJson(itemCount),};}CategoryTodoCountViewData copyWith({Value description = const Value.absent(),Value itemCount = const Value.absent()}) => CategoryTodoCountViewData(description: description.present ? description.value : this.description,itemCount: itemCount.present ? itemCount.value : this.itemCount,);@override +String toString() {return (StringBuffer('CategoryTodoCountViewData(')..write('description: $description, ')..write('itemCount: $itemCount')..write(')')).toString();} +@override + int get hashCode => Object.hash(description, itemCount);@override +bool operator ==(Object other) => identical(this, other) || (other is CategoryTodoCountViewData && other.description == this.description && other.itemCount == this.itemCount); +}class $CategoryTodoCountViewView extends ViewInfo<$CategoryTodoCountViewView, CategoryTodoCountViewData> implements HasResultSet { +final String? _alias; +@override final _$TodoDb attachedDatabase; +$CategoryTodoCountViewView(this.attachedDatabase, [this._alias]); +$TodosTableTable get todos => attachedDatabase.todosTable.createAlias('t0'); +$CategoriesTable get categories => attachedDatabase.categories.createAlias('t1'); +@override +List get $columns => [description, itemCount]; +@override +String get aliasedName => _alias ?? entityName; +@override + String get entityName=> 'category_todo_count_view'; +@override + String? get createViewStmt => null; +@override +$CategoryTodoCountViewView get asDslTable => this; +@override CategoryTodoCountViewData map(Map data, {String? tablePrefix}) { +final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';return CategoryTodoCountViewData(description: attachedDatabase.options.types.read(DriftSqlType.string, data['${effectivePrefix}description']), itemCount: attachedDatabase.options.types.read(DriftSqlType.int, data['${effectivePrefix}item_count']), ); +} +late final GeneratedColumn description = GeneratedColumn('description', aliasedName, true, generatedAs: GeneratedAs(categories.description + const Variable('!'), false), type: DriftSqlType.string); +late final GeneratedColumn itemCount = GeneratedColumn('item_count', aliasedName, true, generatedAs: GeneratedAs(todos.id.count(), false), type: DriftSqlType.int); +@override +$CategoryTodoCountViewView createAlias(String alias) { +return $CategoryTodoCountViewView(attachedDatabase, alias);}@override +Query? get query => (attachedDatabase.selectOnly(categories)..addColumns($columns)) .join([innerJoin(todos,todos.category.equalsExp(categories.id))]) ..groupBy([categories.id]); + @override + Set get readTables => const {'todos', 'categories'}; + } - class TodoWithCategoryViewData extends DataClass { - final String? title; - final String description; - const TodoWithCategoryViewData({this.title, required this.description}); - factory TodoWithCategoryViewData.fromJson(Map json, - {ValueSerializer? serializer}) { - serializer ??= driftRuntimeOptions.defaultSerializer; - return TodoWithCategoryViewData( - title: serializer.fromJson(json['title']), - description: serializer.fromJson(json['description']), - ); - } - factory TodoWithCategoryViewData.fromJsonString(String encodedJson, - {ValueSerializer? serializer}) => - TodoWithCategoryViewData.fromJson( - DataClass.parseJson(encodedJson) as Map, - serializer: serializer); - @override - Map toJson({ValueSerializer? serializer}) { - serializer ??= driftRuntimeOptions.defaultSerializer; - return { - 'title': serializer.toJson(title), - 'description': serializer.toJson(description), - }; - } - - TodoWithCategoryViewData copyWith( - {Value title = const Value.absent(), String? description}) => - TodoWithCategoryViewData( - title: title.present ? title.value : this.title, - description: description ?? this.description, - ); - @override - String toString() { - return (StringBuffer('TodoWithCategoryViewData(') - ..write('title: $title, ') - ..write('description: $description') - ..write(')')) - .toString(); - } - - @override - int get hashCode => Object.hash(title, description); - @override - bool operator ==(Object other) => - identical(this, other) || - (other is TodoWithCategoryViewData && - other.title == this.title && - other.description == this.description); +final String? title; +final String description; +const TodoWithCategoryViewData({this.title, required this.description});factory TodoWithCategoryViewData.fromJson(Map json, {ValueSerializer? serializer}) { +serializer ??= driftRuntimeOptions.defaultSerializer; +return TodoWithCategoryViewData(title: serializer.fromJson(json['title']),description: serializer.fromJson(json['description']),);} +factory TodoWithCategoryViewData.fromJsonString(String encodedJson, {ValueSerializer? serializer}) => TodoWithCategoryViewData.fromJson(DataClass.parseJson(encodedJson) as Map, serializer: serializer);@override Map toJson({ValueSerializer? serializer}) { +serializer ??= driftRuntimeOptions.defaultSerializer; +return { +'title': serializer.toJson(title),'description': serializer.toJson(description),};}TodoWithCategoryViewData copyWith({Value title = const Value.absent(),String? description}) => TodoWithCategoryViewData(title: title.present ? title.value : this.title,description: description ?? this.description,);@override +String toString() {return (StringBuffer('TodoWithCategoryViewData(')..write('title: $title, ')..write('description: $description')..write(')')).toString();} +@override + int get hashCode => Object.hash(title, description);@override +bool operator ==(Object other) => identical(this, other) || (other is TodoWithCategoryViewData && other.title == this.title && other.description == this.description); +}class $TodoWithCategoryViewView extends ViewInfo<$TodoWithCategoryViewView, TodoWithCategoryViewData> implements HasResultSet { +final String? _alias; +@override final _$TodoDb attachedDatabase; +$TodoWithCategoryViewView(this.attachedDatabase, [this._alias]); +$TodosTableTable get todos => attachedDatabase.todosTable.createAlias('t0'); +$CategoriesTable get categories => attachedDatabase.categories.createAlias('t1'); +@override +List get $columns => [title, description]; +@override +String get aliasedName => _alias ?? entityName; +@override + String get entityName=> 'todo_with_category_view'; +@override + String? get createViewStmt => null; +@override +$TodoWithCategoryViewView get asDslTable => this; +@override TodoWithCategoryViewData map(Map data, {String? tablePrefix}) { +final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';return TodoWithCategoryViewData(title: attachedDatabase.options.types.read(DriftSqlType.string, data['${effectivePrefix}title']), description: attachedDatabase.options.types.read(DriftSqlType.string, data['${effectivePrefix}desc'])!, ); } - -class $TodoWithCategoryViewView - extends ViewInfo<$TodoWithCategoryViewView, TodoWithCategoryViewData> - implements HasResultSet { - final String? _alias; - @override - final _$TodoDb attachedDatabase; - $TodoWithCategoryViewView(this.attachedDatabase, [this._alias]); - $TodosTableTable get todos => attachedDatabase.todosTable.createAlias('t0'); - $CategoriesTable get categories => - attachedDatabase.categories.createAlias('t1'); - @override - List get $columns => [title, description]; - @override - String get aliasedName => _alias ?? entityName; - @override - String get entityName => 'todo_with_category_view'; - @override - String? get createViewStmt => null; - @override - $TodoWithCategoryViewView get asDslTable => this; - @override - TodoWithCategoryViewData map(Map data, - {String? tablePrefix}) { - final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; - return TodoWithCategoryViewData( - title: attachedDatabase.options.types - .read(DriftSqlType.string, data['${effectivePrefix}title']), - description: attachedDatabase.options.types - .read(DriftSqlType.string, data['${effectivePrefix}desc'])!, - ); - } - - late final GeneratedColumn title = GeneratedColumn( - 'title', aliasedName, true, - generatedAs: GeneratedAs(todos.title, false), type: DriftSqlType.string); - late final GeneratedColumn description = GeneratedColumn( - 'desc', aliasedName, false, - generatedAs: GeneratedAs(categories.description, false), - type: DriftSqlType.string); - @override - $TodoWithCategoryViewView createAlias(String alias) { - return $TodoWithCategoryViewView(attachedDatabase, alias); - } - - @override - Query? get query => (attachedDatabase.selectOnly(todos)..addColumns($columns)) - .join([innerJoin(categories, categories.id.equalsExp(todos.category))]); - @override - Set get readTables => const {'todos', 'categories'}; +late final GeneratedColumn title = GeneratedColumn('title', aliasedName, true, generatedAs: GeneratedAs(todos.title, false), type: DriftSqlType.string); +late final GeneratedColumn description = GeneratedColumn('desc', aliasedName, false, generatedAs: GeneratedAs(categories.description, false), type: DriftSqlType.string); +@override +$TodoWithCategoryViewView createAlias(String alias) { +return $TodoWithCategoryViewView(attachedDatabase, alias);}@override +Query? get query => (attachedDatabase.selectOnly(todos)..addColumns($columns)) .join([innerJoin(categories,categories.id.equalsExp(todos.category))]); + @override + Set get readTables => const {'todos', 'categories'}; + } - -abstract class _$TodoDb extends GeneratedDatabase { - _$TodoDb(QueryExecutor e) : super(e); - _$TodoDb.connect(DatabaseConnection c) : super.connect(c); - late final $TodosTableTable todosTable = $TodosTableTable(this); - late final $CategoriesTable categories = $CategoriesTable(this); - late final $UsersTable users = $UsersTable(this); - late final $SharedTodosTable sharedTodos = $SharedTodosTable(this); - late final $TableWithoutPKTable tableWithoutPK = $TableWithoutPKTable(this); - late final $PureDefaultsTable pureDefaults = $PureDefaultsTable(this); - late final $CategoryTodoCountViewView categoryTodoCountView = - $CategoryTodoCountViewView(this); - late final $TodoWithCategoryViewView todoWithCategoryView = - $TodoWithCategoryViewView(this); - late final SomeDao someDao = SomeDao(this as TodoDb); +abstract class _$TodoDb extends GeneratedDatabase{ +_$TodoDb(QueryExecutor e): super(e); +_$TodoDb.connect(DatabaseConnection c): super.connect(c); +late final $TodosTableTable todosTable = $TodosTableTable(this); +late final $CategoriesTable categories = $CategoriesTable(this); +late final $UsersTable users = $UsersTable(this); +late final $SharedTodosTable sharedTodos = $SharedTodosTable(this); +late final $TableWithoutPKTable tableWithoutPK = $TableWithoutPKTable(this); +late final $PureDefaultsTable pureDefaults = $PureDefaultsTable(this); +late final $CategoryTodoCountViewView categoryTodoCountView = $CategoryTodoCountViewView(this); +late final $TodoWithCategoryViewView todoWithCategoryView = $TodoWithCategoryViewView(this); +late final SomeDao someDao = SomeDao(this as TodoDb); +Selectable allTodosWithCategory() { +return customSelect('SELECT t.*, c.id AS catId, c."desc" AS catDesc FROM todos AS t INNER JOIN categories AS c ON c.id = t.category', variables: [], readsFrom: {categories,todosTable,}).map((QueryRow row) { return AllTodosWithCategoryResult(row: row, +id: row.read('id'),title: row.read('title'),content: row.read('content'),targetDate: row.read('target_date'),category: row.read('category'),catId: row.read('catId'),catDesc: row.read('catDesc'),); +}); +} +Future deleteTodoById(int var1) { +return customUpdate('DELETE FROM todos WHERE id = ?1',variables: [Variable(var1)],updates: {todosTable}, updateKind: UpdateKind.delete,); +} +Selectable withIn(String var1, String var2, int var3) { +var $arrayStartIndex = 3;final expandedvar3 = $expandVar($arrayStartIndex, var3.length); +$arrayStartIndex += var3.length; +return customSelect('SELECT * FROM todos WHERE title = ?2 OR id IN ($expandedvar3) OR title = ?1', variables: [Variable(var1), Variable(var2), for (var $ in var3) Variable($)], readsFrom: {todosTable,}).asyncMap(todosTable.mapFromRow); +} +Selectable search({required int id}) { +return customSelect('SELECT * FROM todos WHERE CASE WHEN -1 = ?1 THEN 1 ELSE id = ?1 END', variables: [Variable(id)], readsFrom: {todosTable,}).asyncMap(todosTable.mapFromRow); +} +Selectable findCustom() { +return customSelect('SELECT custom FROM table_without_p_k WHERE some_float < 10', variables: [], readsFrom: {tableWithoutPK,}).map((QueryRow row) => $TableWithoutPKTable.$convertercustomn.fromSql(row.read('custom'))); +} +} +class AllTodosWithCategoryResult extends CustomResultSet { +final int id +;final String title +;final String content +;final DateTime targetDate +;final int category +;final int catId +;final String catDesc +;AllTodosWithCategoryResult({required QueryRow row,required this.id,required this.title,required this.content,required this.targetDate,required this.category,required this.catId,required this.catDesc,}): super(row); +@override int get hashCode => Object.hash(id, title, content, targetDate, category, catId, catDesc); +@override +bool operator ==(Object other) => identical(this, other) || (other is AllTodosWithCategoryResult && other.id == this.id && other.title == this.title && other.content == this.content && other.targetDate == this.targetDate && other.category == this.category && other.catId == this.catId && other.catDesc == this.catDesc); +@override +String toString() {return (StringBuffer('AllTodosWithCategoryResult(')..write('id: $id, ')..write('title: $title, ')..write('content: $content, ')..write('targetDate: $targetDate, ')..write('category: $category, ')..write('catId: $catId, ')..write('catDesc: $catDesc')..write(')')).toString();} } // DriftElementId(asset:drift/test/generated/todos.dart, users) // DriftElementId(asset:drift/test/generated/todos.dart, shared_todos) diff --git a/drift_dev/lib/src/analysis/driver/cache.dart b/drift_dev/lib/src/analysis/driver/cache.dart index c9bb1e75..19ac6bfe 100644 --- a/drift_dev/lib/src/analysis/driver/cache.dart +++ b/drift_dev/lib/src/analysis/driver/cache.dart @@ -40,9 +40,20 @@ class DriftAnalysisCache { /// /// This assumes that pre-analysis has already happened for all transitive /// imports, meaning that [knownFiles] contains an entry for every import URI. - Iterable crawl(FileState entrypoint) sync* { - final seenUris = {entrypoint.ownUri}; - final pending = [entrypoint]; + Iterable crawl(FileState entrypoint) { + return crawlMulti([entrypoint]); + } + + /// Crawls all dependencies from a set of [entrypoints]. + Iterable crawlMulti(Iterable entrypoints) sync* { + final seenUris = {}; + final pending = []; + + for (final initial in entrypoints) { + if (seenUris.add(initial.ownUri)) { + pending.add(initial); + } + } while (pending.isNotEmpty) { final found = pending.removeLast(); diff --git a/drift_dev/lib/src/analysis/resolver/file_analysis.dart b/drift_dev/lib/src/analysis/resolver/file_analysis.dart index 36a3ecf2..ff599c2d 100644 --- a/drift_dev/lib/src/analysis/resolver/file_analysis.dart +++ b/drift_dev/lib/src/analysis/resolver/file_analysis.dart @@ -37,6 +37,17 @@ class FileAnalyzer { error.span, 'Error in ${query.name}: ${error.message}')); } } + + final imports = []; + for (final include in element.declaredIncludes) { + final imported = driver.cache.knownFiles[include]; + if (imported != null) { + imports.add(imported); + } + } + + result.resolvedDatabases[element.id] = + ResolvedDatabaseAccessor(queries, imports); } } } else if (state.extension == '.drift' || state.extension == '.moor') { diff --git a/drift_dev/lib/src/analysis/results/dart.dart b/drift_dev/lib/src/analysis/results/dart.dart index 2ce7d4f0..a53967f8 100644 --- a/drift_dev/lib/src/analysis/results/dart.dart +++ b/drift_dev/lib/src/analysis/results/dart.dart @@ -13,6 +13,8 @@ import 'package:json_annotation/json_annotation.dart'; part '../../generated/analysis/results/dart.g.dart'; class AnnotatedDartCode { + static final Uri dartAsync = Uri.parse('dart:async'); + static final Uri dartCore = Uri.parse('dart:core'); static final Uri drift = Uri.parse('package:drift/drift.dart'); final List elements; @@ -85,11 +87,21 @@ class AnnotatedDartCodeBuilder { void addText(String lexeme) => _pendingText.write(lexeme); + void addCode(AnnotatedDartCode code) { + _addPendingText(); + _elements.addAll(code.elements); + } + void addSymbol(String lexeme, Uri? importUri) { _addPendingText(); _elements.add(DartTopLevelSymbol(lexeme, importUri)); } + void addTopLevel(DartTopLevelSymbol symbol) { + _addPendingText(); + _elements.add(symbol); + } + void addTopLevelElement(Element element) { _addPendingText(); _elements.add(DartTopLevelSymbol.topLevelElement(element)); diff --git a/drift_dev/lib/src/analysis/serializer.dart b/drift_dev/lib/src/analysis/serializer.dart index 55081c5f..abffac17 100644 --- a/drift_dev/lib/src/analysis/serializer.dart +++ b/drift_dev/lib/src/analysis/serializer.dart @@ -443,7 +443,9 @@ class ElementDeserializer { ? VirtualTableData.fromJson(json['virtual'] as Map) : null, writeDefaultConstraints: json['write_default_constraints'] as bool, - overrideTableConstraints: (json['custom_constraints'] as List).cast(), + overrideTableConstraints: json['custom_constraints'] != null + ? (json['custom_constraints'] as List).cast() + : null, ); case 'index': return DriftIndex( @@ -490,7 +492,7 @@ class ElementDeserializer { await _readColumn(rawColumn as Map), ]; - final serializedSource = json['serializedSource'] as Map; + final serializedSource = json['source'] as Map; final sourceKind = serializedSource['kind']; DriftViewSource source; @@ -505,12 +507,12 @@ class ElementDeserializer { } source = DartViewSource( - AnnotatedDartCode.fromJson(json['query'] as Map), - json['primaryFrom'] != null - ? readReference(json['primaryFrom'] as Map) + AnnotatedDartCode.fromJson(serializedSource['query'] as Map), + serializedSource['primaryFrom'] != null + ? readReference(serializedSource['primaryFrom'] as Map) : null, [ - for (final element in json['staticReferences']) + for (final element in serializedSource['staticReferences']) readReference(element as Map) ], ); @@ -549,7 +551,7 @@ class ElementDeserializer { ]; final includes = (json['includes'] as List).cast().map(Uri.parse).toList(); - final queries = (json['views'] as List) + final queries = (json['queries'] as List) .cast() .map(QueryOnAccessor.fromJson) .toList(); diff --git a/drift_dev/lib/src/backends/build/drift_builder.dart b/drift_dev/lib/src/backends/build/drift_builder.dart index 0ed9bd4a..b358e9cb 100644 --- a/drift_dev/lib/src/backends/build/drift_builder.dart +++ b/drift_dev/lib/src/backends/build/drift_builder.dart @@ -78,18 +78,32 @@ class DriftBuilder extends Builder { return; } - final result = await driver.resolveElements(buildStep.inputId.uri); + final fileResult = await driver.fullyAnalyze(buildStep.inputId.uri); final generationOptions = GenerationOptions( imports: ImportManagerForPartFiles(), ); final writer = Writer(options, generationOptions: generationOptions); - for (final element in result.analysis.values) { + for (final element in fileResult.analysis.values) { final result = element.result; if (result is DriftDatabase) { - DatabaseWriter(result, writer.child()).write(); + final importedQueries = {}; + final resolved = fileResult.fileAnalysis!.resolvedDatabases[result.id]!; + + // Crawl queries + for (final imported in driver.cache.crawlMulti(resolved.knownImports)) { + final resolved = await driver.fullyAnalyze(imported.ownUri); + importedQueries.addAll({ + for (final entry in resolved.fileAnalysis!.resolvedQueries.entries) + entry.key.name: entry.value, + }); + } + + final input = DatabaseGenerationInput( + result, resolved, importedQueries.values.toList()); + DatabaseWriter(input, writer.child()).write(); } else { writer.leaf().writeln('// ${element.ownId}'); } diff --git a/drift_dev/lib/src/writer/database_writer.dart b/drift_dev/lib/src/writer/database_writer.dart index 527fc85a..340e323e 100644 --- a/drift_dev/lib/src/writer/database_writer.dart +++ b/drift_dev/lib/src/writer/database_writer.dart @@ -4,9 +4,11 @@ import 'package:drift/src/runtime/executor/stream_queries.dart'; import 'package:drift_dev/src/writer/utils/memoized_getter.dart'; import 'package:recase/recase.dart'; +import '../analysis/results/file_results.dart'; import '../analysis/results/results.dart'; import '../services/find_stream_update_rules.dart'; import '../utils/string_escaper.dart'; +import 'queries/query_writer.dart'; import 'tables/table_writer.dart'; import 'tables/view_writer.dart'; import 'writer.dart'; @@ -14,10 +16,12 @@ import 'writer.dart'; /// Generates the Dart code put into a `.g.dart` file when running the /// generator. class DatabaseWriter { - final DriftDatabase db; + DatabaseGenerationInput input; final Scope scope; - DatabaseWriter(this.db, this.scope); + DriftDatabase get db => input.db; + + DatabaseWriter(this.input, this.scope); String get dbClassName { if (scope.generationOptions.isGeneratingForSchema) { @@ -118,7 +122,11 @@ class DatabaseWriter { } // Write implementation for query methods -// db.queries?.forEach((query) => QueryWriter(dbScope.child()).write(query)); + final queries = input.resolvedAccessor.definedQueries.values + .followedBy(input.importedQueries); + for (final query in queries) { + QueryWriter(dbScope.child()).write(query); + } // Write List of tables final schemaScope = dbScope.leaf(); @@ -180,6 +188,15 @@ class DatabaseWriter { } } +class DatabaseGenerationInput { + final DriftDatabase db; + final ResolvedDatabaseAccessor resolvedAccessor; + + final List importedQueries; + + DatabaseGenerationInput(this.db, this.resolvedAccessor, this.importedQueries); +} + extension on drift.UpdateRule { void writeConstructor(TextEmitter emitter) { if (this is drift.WritePropagation) { diff --git a/drift_dev/lib/src/writer/queries/query_writer.dart b/drift_dev/lib/src/writer/queries/query_writer.dart index 45baaaa8..d01cd667 100644 --- a/drift_dev/lib/src/writer/queries/query_writer.dart +++ b/drift_dev/lib/src/writer/queries/query_writer.dart @@ -1,13 +1,15 @@ -import 'package:drift_dev/moor_generator.dart'; -import 'package:drift_dev/src/analyzer/options.dart'; -import 'package:drift_dev/src/analyzer/sql_queries/explicit_alias_transformer.dart'; -import 'package:drift_dev/src/analyzer/sql_queries/nested_queries.dart'; -import 'package:drift_dev/src/utils/string_escaper.dart'; -import 'package:drift_dev/writer.dart'; import 'package:recase/recase.dart'; import 'package:sqlparser/sqlparser.dart' hide ResultColumn; +import '../../analysis/resolver/queries/nested_queries.dart'; +import '../../analysis/results/results.dart'; +import '../../analyzer/options.dart'; +import '../../analyzer/sql_queries/explicit_alias_transformer.dart'; +import '../../utils/string_escaper.dart'; +import '../writer.dart'; +import 'result_set_writer.dart'; import 'sql_writer.dart'; +import 'utils.dart'; const highestAssignedIndexVar = '\$arrayStartIndex'; @@ -17,18 +19,19 @@ class QueryWriter { final Scope scope; late final ExplicitAliasTransformer _transformer; - final StringBuffer _buffer; + final TextEmitter _emitter; + StringBuffer get _buffer => _emitter.buffer; DriftOptions get options => scope.writer.options; - QueryWriter(this.scope) : _buffer = scope.leaf(); + QueryWriter(this.scope) : _emitter = scope.leaf(); void write(SqlQuery query) { // Note that writing queries can have a result set if they use a RETURNING // clause. final resultSet = query.resultSet; if (resultSet?.needsOwnClass == true) { - final resultSetScope = scope.findScopeOfLevel(DartScope.library); + final resultSetScope = scope.root.child(); ResultSetWriter(query, resultSetScope).write(); } @@ -96,7 +99,7 @@ class QueryWriter { _buffer ..write(asDartLiteral(alias.key)) ..write(': ') - ..write(asDartLiteral(alias.value.name.name)) + ..write(asDartLiteral(alias.value.nameInSql)) ..write(', '); } @@ -153,7 +156,7 @@ class QueryWriter { final dartLiteral = asDartLiteral(specialName ?? column.name); final method = column.nullable ? 'readNullable' : 'read'; - final rawDartType = dartTypeNames[column.type]; + final rawDartType = dartTypeNames[column.sqlType]; var code = 'row.$method<$rawDartType>($dartLiteral)'; final converter = column.typeConverter; @@ -163,10 +166,10 @@ class QueryWriter { // nullable in SQL => just map null to null and only invoke the type // converter for non-null values. code = 'NullAwareTypeConverter.wrapFromSql' - '(${_converter(converter)}, $code)'; + '(${_converter(_emitter, converter)}, $code)'; } else { // Just apply the type converter directly. - code = '${_converter(converter)}.fromSql($code)'; + code = '${_converter(_emitter, converter)}.fromSql($code)'; } } return code; @@ -175,11 +178,19 @@ class QueryWriter { /// Writes a method returning a `Selectable`, where `T` is the return type /// of the custom query. void _writeSelectStatementCreator(SqlSelectQuery select) { - final returnType = - 'Selectable<${select.resultTypeCode(scope.generationOptions)}>'; + final returnType = AnnotatedDartCode.build((builder) { + builder + ..addSymbol('Selectable', AnnotatedDartCode.drift) + ..addText('<') + ..addCode(select.resultRowType(scope)) + ..addText('>'); + }); + final methodName = _nameOfCreationMethod(select); - _buffer.write('$returnType $methodName('); + _emitter + ..writeDart(returnType) + ..write(' $methodName('); _writeParameters(select); _buffer.write(') {\n'); @@ -205,8 +216,19 @@ class QueryWriter { } void _writeUpdatingQueryWithReturning(UpdatingQuery update) { - final type = update.resultTypeCode(scope.generationOptions); - _buffer.write('Future> ${update.name}('); + final type = AnnotatedDartCode.build((builder) { + builder + ..addSymbol('Future', AnnotatedDartCode.dartAsync) + ..addText('<') + ..addSymbol('List', AnnotatedDartCode.dartCore) + ..addText('<') + ..addCode(update.resultRowType(scope)) + ..addText('>>'); + }); + + _emitter + ..writeDart(type) + ..write(' ${update.name}('); _writeParameters(update); _buffer.write(') {\n'); @@ -260,7 +282,7 @@ class QueryWriter { } String typeFor(FoundElement element) { - return element.dartTypeCode(); + return _emitter.dartCode(element.dartType(scope)); } String writeScopedTypeFor(FoundDartPlaceholder element) { @@ -362,7 +384,7 @@ class QueryWriter { } void _writeVariables(SqlQuery query) { - _ExpandedVariableWriter(query, scope, _buffer).writeVariables(); + _ExpandedVariableWriter(query, _emitter).writeVariables(); } /// Returns a Dart string literal representing the query after variables have @@ -406,11 +428,8 @@ class QueryWriter { } /// Returns code to load an instance of the [converter] at runtime. -String _converter(UsedTypeConverter converter) { - final infoName = converter.table!.entityInfoName; - final field = '$infoName.${converter.fieldName}'; - - return field; +String _converter(TextEmitter emitter, AppliedTypeConverter converter) { + return emitter.dartCode(emitter.readConverter(converter)); } class _ExpandedDeclarationWriter { @@ -501,7 +520,7 @@ class _ExpandedDeclarationWriter { // The parameter is a function type that needs to be evaluated first final args = element.availableResultSets.map((e) { final table = 'this.${e.entity.dbGetterName}'; - final needsAlias = e.name != e.entity.displayName; + final needsAlias = e.name != e.entity.schemaName; if (needsAlias) { return 'alias($table, ${asDartLiteral(e.name)})'; @@ -585,10 +604,10 @@ class _ExpandedDeclarationWriter { class _ExpandedVariableWriter { final SqlQuery query; - final Scope scope; - final StringBuffer _buffer; + final TextEmitter _emitter; + StringBuffer get _buffer => _emitter.buffer; - _ExpandedVariableWriter(this.query, this.scope, this._buffer); + _ExpandedVariableWriter(this.query, this._emitter); void writeVariables() { _buffer.write('variables: ['); @@ -652,10 +671,10 @@ class _ExpandedVariableWriter { // Apply the converter. if (element.nullable && converter.canBeSkippedForNulls) { buffer.write('NullAwareTypeConverter.wrapToSql(' - '${_converter(element.typeConverter!)}, $dartExpr)'); + '${_converter(_emitter, element.typeConverter!)}, $dartExpr)'); } else { - buffer - .write('${_converter(element.typeConverter!)}.toSql($dartExpr)'); + buffer.write( + '${_converter(_emitter, element.typeConverter!)}.toSql($dartExpr)'); } } else if (capture != null) { buffer.write('row.read(${asDartLiteral(capture.helperColumn)})'); diff --git a/drift_dev/lib/src/writer/queries/result_set_writer.dart b/drift_dev/lib/src/writer/queries/result_set_writer.dart index d09ae5f4..b21eb50a 100644 --- a/drift_dev/lib/src/writer/queries/result_set_writer.dart +++ b/drift_dev/lib/src/writer/queries/result_set_writer.dart @@ -1,7 +1,8 @@ -import 'package:drift_dev/src/model/sql_query.dart'; -import 'package:drift_dev/src/model/types.dart'; -import 'package:drift_dev/src/writer/utils/override_toString.dart'; -import 'package:drift_dev/writer.dart'; +import '../../analysis/results/results.dart'; +import '../utils/hash_and_equals.dart'; +import '../utils/override_toString.dart'; +import '../writer.dart'; +import 'utils.dart'; /// Writes a class holding the result of an sql query into Dart. class ResultSetWriter { @@ -30,7 +31,7 @@ class ResultSetWriter { // write fields for (final column in resultSet.columns) { final name = resultSet.dartNameFor(column); - final runtimeType = column.dartTypeCode(); + final runtimeType = into.dartCode(into.dartType(column)); into.write('$modifier $runtimeType $name\n;'); @@ -40,26 +41,27 @@ class ResultSetWriter { for (final nested in resultSet.nestedResults) { if (nested is NestedResultTable) { - var typeName = nested.table.dartTypeCode(); final fieldName = nested.dartFieldName; - if (nested.isNullable) { - typeName += '?'; - } - - into.write('$modifier $typeName $fieldName;\n'); + into + ..write('$modifier ') + ..writeDart(nested.resultRowType(scope)) + ..write(nested.isNullable ? '? ' : ' ') + ..writeln('$fieldName;'); fields.add(EqualityField(fieldName)); if (!nested.isNullable) nonNullableFields.add(fieldName); } else if (nested is NestedResultQuery) { final fieldName = nested.filedName(); - final typeName = nested.resultTypeCode(); if (nested.query.resultSet.needsOwnClass) { ResultSetWriter(nested.query, scope).write(); } - into.write('$modifier List<$typeName> $fieldName;\n'); + into + ..write(modifier) + ..writeDart(nested.resultRowType(scope)) + ..writeln('$fieldName;'); fields.add(EqualityField(fieldName)); nonNullableFields.add(fieldName); @@ -89,11 +91,12 @@ class ResultSetWriter { // if requested, override hashCode and equals if (scope.writer.options.overrideHashAndEqualsInResultSets) { into.write('@override int get hashCode => '); - writeHashCode(fields, into); + writeHashCode(fields, into.buffer); into.write(';\n'); - overrideEquals(fields, className, into); - overrideToString(className, fields.map((f) => f.lexeme).toList(), into); + overrideEquals(fields, className, into.buffer); + overrideToString( + className, fields.map((f) => f.lexeme).toList(), into.buffer); } into.write('}\n'); diff --git a/drift_dev/lib/src/writer/queries/utils.dart b/drift_dev/lib/src/writer/queries/utils.dart new file mode 100644 index 00000000..5b4813d8 --- /dev/null +++ b/drift_dev/lib/src/writer/queries/utils.dart @@ -0,0 +1,85 @@ +import '../../analysis/results/results.dart'; +import '../writer.dart'; + +extension FoundElementType on FoundElement { + AnnotatedDartCode dartType(Scope scope) { + final $this = this; + if ($this is FoundVariable) { + return scope.dartType($this); + } else if ($this is FoundDartPlaceholder) { + return AnnotatedDartCode.build((builder) { + final kind = $this.type; + + if (kind is SimpleDartPlaceholderType) { + switch (kind.kind) { + case SimpleDartPlaceholderKind.limit: + builder.addSymbol('Limit', AnnotatedDartCode.drift); + break; + case SimpleDartPlaceholderKind.orderByTerm: + builder.addSymbol('OrderingTerm', AnnotatedDartCode.drift); + break; + case SimpleDartPlaceholderKind.orderBy: + builder.addSymbol('OrderBy', AnnotatedDartCode.drift); + break; + } + } else if (kind is ExpressionDartPlaceholderType) { + builder + ..addSymbol('Expression', AnnotatedDartCode.drift) + ..addText('<') + ..addTopLevel(dartTypeNames[kind.columnType]!) + ..addText('>'); + } else if (kind is InsertableDartPlaceholderType) { + final table = kind.table; + + builder.addSymbol('Insertable', AnnotatedDartCode.drift); + if (table != null) { + builder + ..addText('<') + ..addCode(scope.rowType(table)) + ..addText('>'); + } + } + }); + } else { + throw ArgumentError.value(this, 'this', 'Unknown query element'); + } + } +} + +extension SqlQueryType on SqlQuery { + AnnotatedDartCode resultRowType(Scope scope) { + final resultSet = this.resultSet; + if (resultSet == null) { + throw StateError('This query ($name) does not have a result set'); + } + + if (resultSet.matchingTable != null) { + return scope.rowType(resultSet.matchingTable!.table); + } + + if (resultSet.singleColumn) { + return scope.dartType(resultSet.columns.single); + } + + return AnnotatedDartCode([resultClassName]); + } +} + +extension NestedResultType on NestedResult { + AnnotatedDartCode resultRowType(Scope scope) { + final $this = this; + if ($this is NestedResultTable) { + return scope.rowType($this.table); + } else if ($this is NestedResultQuery) { + return AnnotatedDartCode.build((builder) { + builder + ..addSymbol('List', AnnotatedDartCode.dartCore) + ..addText('<') + ..addCode($this.query.resultRowType(scope)) + ..addText('>'); + }); + } else { + throw ArgumentError.value($this, 'this', 'Unknown nested type'); + } + } +}