// GENERATED CODE - DO NOT MODIFY BY HAND part of 'database.dart'; // ************************************************************************** // JsonSerializableGenerator // ************************************************************************** Preferences _$PreferencesFromJson(Map json) { return Preferences( json['receiveEmails'] as bool, ); } Map _$PreferencesToJson(Preferences instance) => { 'receiveEmails': instance.receiveEmails, }; // ************************************************************************** // MoorGenerator // ************************************************************************** // ignore_for_file: unnecessary_brace_in_string_interps, unnecessary_this class User extends DataClass implements Insertable { final int id; final String name; final DateTime birthDate; final Uint8List profilePicture; final Preferences preferences; User( {@required this.id, @required this.name, @required this.birthDate, this.profilePicture, this.preferences}); factory User.fromData(Map data, GeneratedDatabase db, {String prefix}) { final effectivePrefix = prefix ?? ''; final intType = db.typeSystem.forDartType(); final stringType = db.typeSystem.forDartType(); final dateTimeType = db.typeSystem.forDartType(); final uint8ListType = db.typeSystem.forDartType(); return User( id: intType.mapFromDatabaseResponse(data['${effectivePrefix}id']), name: stringType.mapFromDatabaseResponse(data['${effectivePrefix}name']), birthDate: dateTimeType .mapFromDatabaseResponse(data['${effectivePrefix}birth_date']), profilePicture: uint8ListType .mapFromDatabaseResponse(data['${effectivePrefix}profile_picture']), preferences: $UsersTable.$converter0.mapToDart(stringType .mapFromDatabaseResponse(data['${effectivePrefix}preferences'])), ); } @override Map toColumns(bool nullToAbsent) { final map = {}; if (!nullToAbsent || id != null) { map['id'] = Variable(id); } if (!nullToAbsent || name != null) { map['name'] = Variable(name); } if (!nullToAbsent || birthDate != null) { map['birth_date'] = Variable(birthDate); } if (!nullToAbsent || profilePicture != null) { map['profile_picture'] = Variable(profilePicture); } if (!nullToAbsent || preferences != null) { final converter = $UsersTable.$converter0; map['preferences'] = Variable(converter.mapToSql(preferences)); } return map; } factory User.fromJson(Map json, {ValueSerializer serializer}) { serializer ??= moorRuntimeOptions.defaultSerializer; return User( id: serializer.fromJson(json['id']), name: serializer.fromJson(json['name']), birthDate: serializer.fromJson(json['born_on']), profilePicture: serializer.fromJson(json['profilePicture']), preferences: serializer.fromJson(json['preferences']), ); } @override Map toJson({ValueSerializer serializer}) { serializer ??= moorRuntimeOptions.defaultSerializer; return { 'id': serializer.toJson(id), 'name': serializer.toJson(name), 'born_on': serializer.toJson(birthDate), 'profilePicture': serializer.toJson(profilePicture), 'preferences': serializer.toJson(preferences), }; } User copyWith( {int id, String name, DateTime birthDate, Uint8List profilePicture, Preferences preferences}) => User( id: id ?? this.id, name: name ?? this.name, birthDate: birthDate ?? this.birthDate, profilePicture: profilePicture ?? this.profilePicture, preferences: preferences ?? this.preferences, ); @override String toString() { return (StringBuffer('User(') ..write('id: $id, ') ..write('name: $name, ') ..write('birthDate: $birthDate, ') ..write('profilePicture: $profilePicture, ') ..write('preferences: $preferences') ..write(')')) .toString(); } @override int get hashCode => $mrjf($mrjc( id.hashCode, $mrjc( name.hashCode, $mrjc(birthDate.hashCode, $mrjc(profilePicture.hashCode, preferences.hashCode))))); @override bool operator ==(dynamic other) => identical(this, other) || (other is User && other.id == this.id && other.name == this.name && other.birthDate == this.birthDate && other.profilePicture == this.profilePicture && other.preferences == this.preferences); } class UsersCompanion extends UpdateCompanion { final Value id; final Value name; final Value birthDate; final Value profilePicture; final Value preferences; const UsersCompanion({ this.id = const Value.absent(), this.name = const Value.absent(), this.birthDate = const Value.absent(), this.profilePicture = const Value.absent(), this.preferences = const Value.absent(), }); UsersCompanion.insert({ this.id = const Value.absent(), @required String name, @required DateTime birthDate, this.profilePicture = const Value.absent(), this.preferences = const Value.absent(), }) : name = Value(name), birthDate = Value(birthDate); static Insertable custom({ Expression id, Expression name, Expression birthDate, Expression profilePicture, Expression preferences, }) { return RawValuesInsertable({ if (id != null) 'id': id, if (name != null) 'name': name, if (birthDate != null) 'birth_date': birthDate, if (profilePicture != null) 'profile_picture': profilePicture, if (preferences != null) 'preferences': preferences, }); } UsersCompanion copyWith( {Value id, Value name, Value birthDate, Value profilePicture, Value preferences}) { return UsersCompanion( id: id ?? this.id, name: name ?? this.name, birthDate: birthDate ?? this.birthDate, profilePicture: profilePicture ?? this.profilePicture, preferences: preferences ?? this.preferences, ); } @override Map toColumns(bool nullToAbsent) { final map = {}; if (id.present) { map['id'] = Variable(id.value); } if (name.present) { map['name'] = Variable(name.value); } if (birthDate.present) { map['birth_date'] = Variable(birthDate.value); } if (profilePicture.present) { map['profile_picture'] = Variable(profilePicture.value); } if (preferences.present) { final converter = $UsersTable.$converter0; map['preferences'] = Variable(converter.mapToSql(preferences.value)); } return map; } } class $UsersTable extends Users with TableInfo<$UsersTable, User> { final GeneratedDatabase _db; final String _alias; $UsersTable(this._db, [this._alias]); final VerificationMeta _idMeta = const VerificationMeta('id'); GeneratedIntColumn _id; @override GeneratedIntColumn get id => _id ??= _constructId(); GeneratedIntColumn _constructId() { return GeneratedIntColumn('id', $tableName, false, hasAutoIncrement: true, declaredAsPrimaryKey: true); } final VerificationMeta _nameMeta = const VerificationMeta('name'); GeneratedTextColumn _name; @override GeneratedTextColumn get name => _name ??= _constructName(); GeneratedTextColumn _constructName() { return GeneratedTextColumn( 'name', $tableName, false, ); } final VerificationMeta _birthDateMeta = const VerificationMeta('birthDate'); GeneratedDateTimeColumn _birthDate; @override GeneratedDateTimeColumn get birthDate => _birthDate ??= _constructBirthDate(); GeneratedDateTimeColumn _constructBirthDate() { return GeneratedDateTimeColumn( 'birth_date', $tableName, false, ); } final VerificationMeta _profilePictureMeta = const VerificationMeta('profilePicture'); GeneratedBlobColumn _profilePicture; @override GeneratedBlobColumn get profilePicture => _profilePicture ??= _constructProfilePicture(); GeneratedBlobColumn _constructProfilePicture() { return GeneratedBlobColumn( 'profile_picture', $tableName, true, ); } final VerificationMeta _preferencesMeta = const VerificationMeta('preferences'); GeneratedTextColumn _preferences; @override GeneratedTextColumn get preferences => _preferences ??= _constructPreferences(); GeneratedTextColumn _constructPreferences() { return GeneratedTextColumn( 'preferences', $tableName, true, ); } @override List get $columns => [id, name, birthDate, profilePicture, preferences]; @override $UsersTable get asDslTable => this; @override String get $tableName => _alias ?? 'users'; @override final String 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('birth_date')) { context.handle(_birthDateMeta, birthDate.isAcceptableOrUnknown(data['birth_date'], _birthDateMeta)); } else if (isInserting) { context.missing(_birthDateMeta); } if (data.containsKey('profile_picture')) { context.handle( _profilePictureMeta, profilePicture.isAcceptableOrUnknown( data['profile_picture'], _profilePictureMeta)); } context.handle(_preferencesMeta, const VerificationResult.success()); return context; } @override Set get $primaryKey => {id}; @override User map(Map data, {String tablePrefix}) { final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : null; return User.fromData(data, _db, prefix: effectivePrefix); } @override $UsersTable createAlias(String alias) { return $UsersTable(_db, alias); } static TypeConverter $converter0 = const PreferenceConverter(); } class Friendship extends DataClass implements Insertable { final int firstUser; final int secondUser; final bool reallyGoodFriends; Friendship( {@required this.firstUser, @required this.secondUser, @required this.reallyGoodFriends}); factory Friendship.fromData(Map data, GeneratedDatabase db, {String prefix}) { final effectivePrefix = prefix ?? ''; final intType = db.typeSystem.forDartType(); final boolType = db.typeSystem.forDartType(); return Friendship( firstUser: intType.mapFromDatabaseResponse(data['${effectivePrefix}first_user']), secondUser: intType .mapFromDatabaseResponse(data['${effectivePrefix}second_user']), reallyGoodFriends: boolType.mapFromDatabaseResponse( data['${effectivePrefix}really_good_friends']), ); } @override Map toColumns(bool nullToAbsent) { final map = {}; if (!nullToAbsent || firstUser != null) { map['first_user'] = Variable(firstUser); } if (!nullToAbsent || secondUser != null) { map['second_user'] = Variable(secondUser); } if (!nullToAbsent || reallyGoodFriends != null) { map['really_good_friends'] = Variable(reallyGoodFriends); } return map; } factory Friendship.fromJson(Map json, {ValueSerializer serializer}) { serializer ??= moorRuntimeOptions.defaultSerializer; return Friendship( firstUser: serializer.fromJson(json['firstUser']), secondUser: serializer.fromJson(json['secondUser']), reallyGoodFriends: serializer.fromJson(json['reallyGoodFriends']), ); } @override Map toJson({ValueSerializer serializer}) { serializer ??= moorRuntimeOptions.defaultSerializer; return { 'firstUser': serializer.toJson(firstUser), 'secondUser': serializer.toJson(secondUser), 'reallyGoodFriends': serializer.toJson(reallyGoodFriends), }; } Friendship copyWith( {int firstUser, int secondUser, bool reallyGoodFriends}) => Friendship( firstUser: firstUser ?? this.firstUser, secondUser: secondUser ?? this.secondUser, reallyGoodFriends: reallyGoodFriends ?? this.reallyGoodFriends, ); @override String toString() { return (StringBuffer('Friendship(') ..write('firstUser: $firstUser, ') ..write('secondUser: $secondUser, ') ..write('reallyGoodFriends: $reallyGoodFriends') ..write(')')) .toString(); } @override int get hashCode => $mrjf($mrjc(firstUser.hashCode, $mrjc(secondUser.hashCode, reallyGoodFriends.hashCode))); @override bool operator ==(dynamic other) => identical(this, other) || (other is Friendship && other.firstUser == this.firstUser && other.secondUser == this.secondUser && other.reallyGoodFriends == this.reallyGoodFriends); } class FriendshipsCompanion extends UpdateCompanion { final Value firstUser; final Value secondUser; final Value reallyGoodFriends; const FriendshipsCompanion({ this.firstUser = const Value.absent(), this.secondUser = const Value.absent(), this.reallyGoodFriends = const Value.absent(), }); FriendshipsCompanion.insert({ @required int firstUser, @required int secondUser, this.reallyGoodFriends = const Value.absent(), }) : firstUser = Value(firstUser), secondUser = Value(secondUser); static Insertable custom({ Expression firstUser, Expression secondUser, Expression reallyGoodFriends, }) { return RawValuesInsertable({ if (firstUser != null) 'first_user': firstUser, if (secondUser != null) 'second_user': secondUser, if (reallyGoodFriends != null) 'really_good_friends': reallyGoodFriends, }); } FriendshipsCompanion copyWith( {Value firstUser, Value secondUser, Value reallyGoodFriends}) { return FriendshipsCompanion( firstUser: firstUser ?? this.firstUser, secondUser: secondUser ?? this.secondUser, reallyGoodFriends: reallyGoodFriends ?? this.reallyGoodFriends, ); } @override Map toColumns(bool nullToAbsent) { final map = {}; if (firstUser.present) { map['first_user'] = Variable(firstUser.value); } if (secondUser.present) { map['second_user'] = Variable(secondUser.value); } if (reallyGoodFriends.present) { map['really_good_friends'] = Variable(reallyGoodFriends.value); } return map; } } class $FriendshipsTable extends Friendships with TableInfo<$FriendshipsTable, Friendship> { final GeneratedDatabase _db; final String _alias; $FriendshipsTable(this._db, [this._alias]); final VerificationMeta _firstUserMeta = const VerificationMeta('firstUser'); GeneratedIntColumn _firstUser; @override GeneratedIntColumn get firstUser => _firstUser ??= _constructFirstUser(); GeneratedIntColumn _constructFirstUser() { return GeneratedIntColumn( 'first_user', $tableName, false, ); } final VerificationMeta _secondUserMeta = const VerificationMeta('secondUser'); GeneratedIntColumn _secondUser; @override GeneratedIntColumn get secondUser => _secondUser ??= _constructSecondUser(); GeneratedIntColumn _constructSecondUser() { return GeneratedIntColumn( 'second_user', $tableName, false, ); } final VerificationMeta _reallyGoodFriendsMeta = const VerificationMeta('reallyGoodFriends'); GeneratedBoolColumn _reallyGoodFriends; @override GeneratedBoolColumn get reallyGoodFriends => _reallyGoodFriends ??= _constructReallyGoodFriends(); GeneratedBoolColumn _constructReallyGoodFriends() { return GeneratedBoolColumn('really_good_friends', $tableName, false, defaultValue: const Constant(false)); } @override List get $columns => [firstUser, secondUser, reallyGoodFriends]; @override $FriendshipsTable get asDslTable => this; @override String get $tableName => _alias ?? 'friendships'; @override final String actualTableName = 'friendships'; @override VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { final context = VerificationContext(); final data = instance.toColumns(true); if (data.containsKey('first_user')) { context.handle(_firstUserMeta, firstUser.isAcceptableOrUnknown(data['first_user'], _firstUserMeta)); } else if (isInserting) { context.missing(_firstUserMeta); } if (data.containsKey('second_user')) { context.handle( _secondUserMeta, secondUser.isAcceptableOrUnknown( data['second_user'], _secondUserMeta)); } else if (isInserting) { context.missing(_secondUserMeta); } if (data.containsKey('really_good_friends')) { context.handle( _reallyGoodFriendsMeta, reallyGoodFriends.isAcceptableOrUnknown( data['really_good_friends'], _reallyGoodFriendsMeta)); } return context; } @override Set get $primaryKey => {firstUser, secondUser}; @override Friendship map(Map data, {String tablePrefix}) { final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : null; return Friendship.fromData(data, _db, prefix: effectivePrefix); } @override $FriendshipsTable createAlias(String alias) { return $FriendshipsTable(_db, alias); } } abstract class _$Database extends GeneratedDatabase { _$Database(QueryExecutor e) : super(SqlTypeSystem.defaultInstance, e); _$Database.connect(DatabaseConnection c) : super.connect(c); $UsersTable _users; $UsersTable get users => _users ??= $UsersTable(this); $FriendshipsTable _friendships; $FriendshipsTable get friendships => _friendships ??= $FriendshipsTable(this); User _rowToUser(QueryRow row) { return User( id: row.readInt('id'), name: row.readString('name'), birthDate: row.readDateTime('birth_date'), profilePicture: row.readBlob('profile_picture'), preferences: $UsersTable.$converter0.mapToDart(row.readString('preferences')), ); } Selectable mostPopularUsers(int amount) { return customSelect( 'SELECT * FROM users u ORDER BY (SELECT COUNT(*) FROM friendships WHERE first_user = u.id OR second_user = u.id) DESC LIMIT :amount', variables: [Variable.withInt(amount)], readsFrom: {users, friendships}).map(_rowToUser); } Selectable amountOfGoodFriends(int user) { return customSelect( 'SELECT COUNT(*) FROM friendships f WHERE f.really_good_friends AND (f.first_user = :user OR f.second_user = :user)', variables: [ Variable.withInt(user) ], readsFrom: { friendships }).map((QueryRow row) => row.readInt('COUNT(*)')); } FriendshipsOfResult _rowToFriendshipsOfResult(QueryRow row) { return FriendshipsOfResult( reallyGoodFriends: row.readBool('really_good_friends'), user: users.mapFromRowOrNull(row, tablePrefix: 'nested_0'), ); } Selectable friendshipsOf(int user) { return customSelect( 'SELECT \n f.really_good_friends, "user"."id" AS "nested_0.id", "user"."name" AS "nested_0.name", "user"."birth_date" AS "nested_0.birth_date", "user"."profile_picture" AS "nested_0.profile_picture", "user"."preferences" AS "nested_0.preferences"\n FROM friendships f\n INNER JOIN users user ON user.id IN (f.first_user, f.second_user) AND\n user.id != :user\n WHERE (f.first_user = :user OR f.second_user = :user)', variables: [Variable.withInt(user)], readsFrom: {friendships, users}).map(_rowToFriendshipsOfResult); } Selectable userCount() { return customSelect('SELECT COUNT(id) FROM users', variables: [], readsFrom: {users}).map((QueryRow row) => row.readInt('COUNT(id)')); } Selectable settingsFor(int user) { return customSelect('SELECT preferences FROM users WHERE id = :user', variables: [Variable.withInt(user)], readsFrom: {users}) .map((QueryRow row) => $UsersTable.$converter0.mapToDart(row.readString('preferences'))); } Selectable usersById(List var1) { var $arrayStartIndex = 1; final expandedvar1 = $expandVar($arrayStartIndex, var1.length); $arrayStartIndex += var1.length; return customSelect('SELECT * FROM users WHERE id IN ($expandedvar1)', variables: [for (var $ in var1) Variable.withInt($)], readsFrom: {users}).map(_rowToUser); } @override Iterable get allTables => allSchemaEntities.whereType(); @override List get allSchemaEntities => [users, friendships]; } class FriendshipsOfResult { final bool reallyGoodFriends; final User user; FriendshipsOfResult({ this.reallyGoodFriends, this.user, }); @override int get hashCode => $mrjf($mrjc(reallyGoodFriends.hashCode, user.hashCode)); @override bool operator ==(dynamic other) => identical(this, other) || (other is FriendshipsOfResult && other.reallyGoodFriends == this.reallyGoodFriends && other.user == this.user); }