diff --git a/floor_common/test/integration/view/view_test.g.dart b/floor_common/test/integration/view/view_test.g.dart new file mode 100644 index 00000000..b168d05e --- /dev/null +++ b/floor_common/test/integration/view/view_test.g.dart @@ -0,0 +1,521 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'view_test.dart'; + +// ************************************************************************** +// FloorGenerator +// ************************************************************************** + +abstract class $ViewTestDatabaseBuilderContract { + /// Adds migrations to the builder. + $ViewTestDatabaseBuilderContract addMigrations(List migrations); + + /// Adds a database [Callback] to the builder. + $ViewTestDatabaseBuilderContract addCallback(Callback callback); + + /// Creates the database and initializes it. + Future build(); +} + +// ignore: avoid_classes_with_only_static_members +class $FloorViewTestDatabase { + /// Creates a database builder for a persistent database. + /// Once a database is built, you should keep a reference to it and re-use it. + static $ViewTestDatabaseBuilderContract databaseBuilder(String name) => + _$ViewTestDatabaseBuilder(name); + + /// Creates a database builder for an in memory database. + /// Information stored in an in memory database disappears when the process is killed. + /// Once a database is built, you should keep a reference to it and re-use it. + static $ViewTestDatabaseBuilderContract inMemoryDatabaseBuilder() => + _$ViewTestDatabaseBuilder(null); +} + +class _$ViewTestDatabaseBuilder implements $ViewTestDatabaseBuilderContract { + _$ViewTestDatabaseBuilder(this.name); + + final String? name; + + final List _migrations = []; + + Callback? _callback; + + @override + $ViewTestDatabaseBuilderContract addMigrations(List migrations) { + _migrations.addAll(migrations); + return this; + } + + @override + $ViewTestDatabaseBuilderContract addCallback(Callback callback) { + _callback = callback; + return this; + } + + @override + Future build() async { + final path = name != null + ? await sqfliteDatabaseFactory.getDatabasePath(name!) + : ':memory:'; + final database = _$ViewTestDatabase(); + database.database = await database.open( + path, + _migrations, + _callback, + ); + return database; + } +} + +class _$ViewTestDatabase extends ViewTestDatabase { + _$ViewTestDatabase([StreamController? listener]) { + changeListener = listener ?? StreamController.broadcast(); + } + + PersonDao? _personDaoInstance; + + DogDao? _dogDaoInstance; + + NameDao? _nameDaoInstance; + + Future open( + String path, + List migrations, [ + Callback? callback, + ]) async { + final databaseOptions = sqflite.OpenDatabaseOptions( + version: 1, + onConfigure: (database) async { + await database.execute('PRAGMA foreign_keys = ON'); + await callback?.onConfigure?.call(database); + }, + onOpen: (database) async { + await callback?.onOpen?.call(database); + }, + onUpgrade: (database, startVersion, endVersion) async { + await MigrationAdapter.runMigrations( + database, startVersion, endVersion, migrations); + + await callback?.onUpgrade?.call(database, startVersion, endVersion); + }, + onCreate: (database, version) async { + await database.execute( + 'CREATE TABLE IF NOT EXISTS `person` (`id` INTEGER, `custom_name` TEXT NOT NULL, PRIMARY KEY (`id`))'); + await database.execute( + 'CREATE TABLE IF NOT EXISTS `dog` (`id` INTEGER, `name` TEXT NOT NULL, `nick_name` TEXT NOT NULL, `owner_id` INTEGER NOT NULL, FOREIGN KEY (`owner_id`) REFERENCES `person` (`id`) ON UPDATE NO ACTION ON DELETE CASCADE, PRIMARY KEY (`id`))'); + await database.execute( + 'CREATE INDEX `index_person_custom_name` ON `person` (`custom_name`)'); + await database.execute( + 'CREATE VIEW IF NOT EXISTS `names` AS SELECT custom_name as name FROM person UNION SELECT name from dog'); + await database.execute( + 'CREATE VIEW IF NOT EXISTS `multiline_query_names` AS SELECT custom_name as name \n FROM person \n UNION SELECT name from dog\n '); + + await callback?.onCreate?.call(database, version); + }, + ); + return sqfliteDatabaseFactory.openDatabase(path, options: databaseOptions); + } + + @override + PersonDao get personDao { + return _personDaoInstance ??= _$PersonDao(database, changeListener); + } + + @override + DogDao get dogDao { + return _dogDaoInstance ??= _$DogDao(database, changeListener); + } + + @override + NameDao get nameDao { + return _nameDaoInstance ??= _$NameDao(database, changeListener); + } +} + +class _$PersonDao extends PersonDao { + _$PersonDao( + this.database, + this.changeListener, + ) : _queryAdapter = QueryAdapter(database, changeListener), + _personInsertionAdapter = InsertionAdapter( + database, + 'person', + (Person item) => + {'id': item.id, 'custom_name': item.name}, + changeListener), + _personUpdateAdapter = UpdateAdapter( + database, + 'person', + ['id'], + (Person item) => + {'id': item.id, 'custom_name': item.name}, + changeListener), + _personDeletionAdapter = DeletionAdapter( + database, + 'person', + ['id'], + (Person item) => + {'id': item.id, 'custom_name': item.name}, + changeListener); + + final sqflite.DatabaseExecutor database; + + final StreamController changeListener; + + final QueryAdapter _queryAdapter; + + final InsertionAdapter _personInsertionAdapter; + + final UpdateAdapter _personUpdateAdapter; + + final DeletionAdapter _personDeletionAdapter; + + @override + Future> findAllPersons() async { + return _queryAdapter.queryList('SELECT * FROM person', + mapper: (Map row) => + Person(row['id'] as int?, row['custom_name'] as String)); + } + + @override + Stream> findAllPersonsAsStream() { + return _queryAdapter.queryListStream('SELECT * FROM person', + mapper: (Map row) => + Person(row['id'] as int?, row['custom_name'] as String), + queryableName: 'person', + isView: false); + } + + @override + Future findPersonById(int id) async { + return _queryAdapter.query('SELECT * FROM person WHERE id = ?1', + mapper: (Map row) => + Person(row['id'] as int?, row['custom_name'] as String), + arguments: [id]); + } + + @override + Stream findPersonByIdAsStream(int id) { + return _queryAdapter.queryStream('SELECT * FROM person WHERE id = ?1', + mapper: (Map row) => + Person(row['id'] as int?, row['custom_name'] as String), + arguments: [id], + queryableName: 'person', + isView: false); + } + + @override + Stream uniqueRecordsCountAsStream() { + return _queryAdapter.queryStream('SELECT DISTINCT COUNT(id) FROM person', + mapper: (Map row) => row.values.first as int, + queryableName: 'person', + isView: false); + } + + @override + Future findPersonByIdAndName( + int id, + String name, + ) async { + return _queryAdapter.query( + 'SELECT * FROM person WHERE id = ?1 AND custom_name = ?2', + mapper: (Map row) => + Person(row['id'] as int?, row['custom_name'] as String), + arguments: [id, name]); + } + + @override + Future> findPersonsWithIds(List ids) async { + const offset = 1; + final _sqliteVariablesForIds = + Iterable.generate(ids.length, (i) => '?${i + offset}') + .join(','); + return _queryAdapter.queryList( + 'SELECT * FROM person WHERE id IN (' + _sqliteVariablesForIds + ')', + mapper: (Map row) => + Person(row['id'] as int?, row['custom_name'] as String), + arguments: [...ids]); + } + + @override + Future> findPersonsWithNames(List names) async { + const offset = 1; + final _sqliteVariablesForNames = + Iterable.generate(names.length, (i) => '?${i + offset}') + .join(','); + return _queryAdapter.queryList( + 'SELECT * FROM person WHERE custom_name IN (' + + _sqliteVariablesForNames + + ')', + mapper: (Map row) => + Person(row['id'] as int?, row['custom_name'] as String), + arguments: [...names]); + } + + @override + Future> findPersonsWithNamesComplex( + int reference, + List names, + List moreNames, + ) async { + int offset = 2; + final _sqliteVariablesForNames = + Iterable.generate(names.length, (i) => '?${i + offset}') + .join(','); + offset += names.length; + final _sqliteVariablesForMoreNames = + Iterable.generate(moreNames.length, (i) => '?${i + offset}') + .join(','); + return _queryAdapter.queryList( + 'SELECT * FROM person WHERE custom_name IN (' + + _sqliteVariablesForNames + + ') AND id>=?1 OR custom_name IN (' + + _sqliteVariablesForMoreNames + + ') AND id<=?1', + mapper: (Map row) => + Person(row['id'] as int?, row['custom_name'] as String), + arguments: [reference, ...names, ...moreNames]); + } + + @override + Future> findPersonsWithNamesLike(String name) async { + return _queryAdapter.queryList( + 'SELECT * FROM person WHERE custom_name LIKE ?1', + mapper: (Map row) => + Person(row['id'] as int?, row['custom_name'] as String), + arguments: [name]); + } + + @override + Future> findPersonsWithEmptyName() async { + return _queryAdapter.queryList( + 'SELECT * FROM person WHERE custom_name == \'\'', + mapper: (Map row) => + Person(row['id'] as int?, row['custom_name'] as String)); + } + + @override + Future deleteAllPersons() async { + await _queryAdapter.queryNoReturn('DELETE FROM person'); + } + + @override + Stream> findAllDogsOfPersonAsStream(int id) { + return _queryAdapter.queryListStream( + 'SELECT * FROM dog WHERE owner_id = ?1', + mapper: (Map row) => Dog( + row['id'] as int?, + row['name'] as String, + row['nick_name'] as String, + row['owner_id'] as int), + arguments: [id], + queryableName: 'dog', + isView: false); + } + + @override + Future insertPerson(Person person) async { + await _personInsertionAdapter.insert(person, OnConflictStrategy.replace); + } + + @override + Future insertPersons(List persons) async { + await _personInsertionAdapter.insertList(persons, OnConflictStrategy.abort); + } + + @override + Future insertPersonWithReturn(Person person) { + return _personInsertionAdapter.insertAndReturnId( + person, OnConflictStrategy.abort); + } + + @override + Future> insertPersonsWithReturn(List persons) { + return _personInsertionAdapter.insertListAndReturnIds( + persons, OnConflictStrategy.abort); + } + + @override + Future updatePerson(Person person) async { + await _personUpdateAdapter.update(person, OnConflictStrategy.abort); + } + + @override + Future updatePersons(List persons) async { + await _personUpdateAdapter.updateList(persons, OnConflictStrategy.abort); + } + + @override + Future updatePersonWithReturn(Person person) { + return _personUpdateAdapter.updateAndReturnChangedRows( + person, OnConflictStrategy.abort); + } + + @override + Future updatePersonsWithReturn(List persons) { + return _personUpdateAdapter.updateListAndReturnChangedRows( + persons, OnConflictStrategy.abort); + } + + @override + Future deletePerson(Person person) async { + await _personDeletionAdapter.delete(person); + } + + @override + Future deletePersons(List person) async { + await _personDeletionAdapter.deleteList(person); + } + + @override + Future deletePersonWithReturn(Person person) { + return _personDeletionAdapter.deleteAndReturnChangedRows(person); + } + + @override + Future deletePersonsWithReturn(List persons) { + return _personDeletionAdapter.deleteListAndReturnChangedRows(persons); + } + + @override + Future replacePersons(List persons) async { + if (database is sqflite.Transaction) { + await super.replacePersons(persons); + } else { + await (database as sqflite.Database) + .transaction((transaction) async { + final transactionDatabase = _$ViewTestDatabase(changeListener) + ..database = transaction; + await transactionDatabase.personDao.replacePersons(persons); + }); + } + } + + @override + Future> replacePersonsAndReturn(List persons) async { + if (database is sqflite.Transaction) { + return super.replacePersonsAndReturn(persons); + } else { + return (database as sqflite.Database) + .transaction>((transaction) async { + final transactionDatabase = _$ViewTestDatabase(changeListener) + ..database = transaction; + return transactionDatabase.personDao.replacePersonsAndReturn(persons); + }); + } + } +} + +class _$DogDao extends DogDao { + _$DogDao( + this.database, + this.changeListener, + ) : _queryAdapter = QueryAdapter(database), + _dogInsertionAdapter = InsertionAdapter( + database, + 'dog', + (Dog item) => { + 'id': item.id, + 'name': item.name, + 'nick_name': item.nickName, + 'owner_id': item.ownerId + }, + changeListener); + + final sqflite.DatabaseExecutor database; + + final StreamController changeListener; + + final QueryAdapter _queryAdapter; + + final InsertionAdapter _dogInsertionAdapter; + + @override + Future findDogForPersonId(int id) async { + return _queryAdapter.query('SELECT * FROM dog WHERE owner_id = ?1', + mapper: (Map row) => Dog( + row['id'] as int?, + row['name'] as String, + row['nick_name'] as String, + row['owner_id'] as int), + arguments: [id]); + } + + @override + Future> findAllDogs() async { + return _queryAdapter.queryList('SELECT * FROM dog', + mapper: (Map row) => Dog( + row['id'] as int?, + row['name'] as String, + row['nick_name'] as String, + row['owner_id'] as int)); + } + + @override + Future insertDog(Dog dog) async { + await _dogInsertionAdapter.insert(dog, OnConflictStrategy.abort); + } +} + +class _$NameDao extends NameDao { + _$NameDao( + this.database, + this.changeListener, + ) : _queryAdapter = QueryAdapter(database, changeListener); + + final sqflite.DatabaseExecutor database; + + final StreamController changeListener; + + final QueryAdapter _queryAdapter; + + @override + Future> findAllNames() async { + return _queryAdapter.queryList('SELECT * FROM names ORDER BY name ASC', + mapper: (Map row) => Name(row['name'] as String)); + } + + @override + Stream> findAllNamesAsStream() { + return _queryAdapter.queryListStream( + 'SELECT * FROM names ORDER BY name ASC', + mapper: (Map row) => Name(row['name'] as String), + queryableName: 'names', + isView: true); + } + + @override + Future findExactName(String name) async { + return _queryAdapter.query('SELECT * FROM names WHERE name = ?1', + mapper: (Map row) => Name(row['name'] as String), + arguments: [name]); + } + + @override + Future> findNamesLike(String suffix) async { + return _queryAdapter.queryList( + 'SELECT * FROM names WHERE name LIKE ?1 ORDER BY name ASC', + mapper: (Map row) => Name(row['name'] as String), + arguments: [suffix]); + } + + @override + Future> findNamesMatchingBoth( + String prefix, + String suffix, + ) async { + return _queryAdapter.queryList( + 'SELECT * FROM names WHERE name LIKE ?2 AND name LIKE ?1 ORDER BY name ASC', + mapper: (Map row) => Name(row['name'] as String), + arguments: [prefix, suffix]); + } + + @override + Future findMultilineQueryName(String name) async { + return _queryAdapter.query( + 'SELECT * FROM multiline_query_names WHERE name = ?1', + mapper: (Map row) => + MultilineQueryName(row['name'] as String), + arguments: [name]); + } +}