You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
145 lines
4.5 KiB
145 lines
4.5 KiB
4 months ago
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||
|
|
||
|
part of 'hx_database.dart';
|
||
|
|
||
|
// **************************************************************************
|
||
|
// FloorGenerator
|
||
|
// **************************************************************************
|
||
|
|
||
|
// ignore: avoid_classes_with_only_static_members
|
||
|
class $FloorHxDatabase {
|
||
|
/// 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 _$HxDatabaseBuilder databaseBuilder(String name) =>
|
||
|
_$HxDatabaseBuilder(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 _$HxDatabaseBuilder inMemoryDatabaseBuilder() =>
|
||
|
_$HxDatabaseBuilder(null);
|
||
|
}
|
||
|
|
||
|
class _$HxDatabaseBuilder {
|
||
|
_$HxDatabaseBuilder(this.name);
|
||
|
|
||
|
final String name;
|
||
|
|
||
|
final List<Migration> _migrations = [];
|
||
|
|
||
|
Callback _callback;
|
||
|
|
||
|
/// Adds migrations to the builder.
|
||
|
_$HxDatabaseBuilder addMigrations(List<Migration> migrations) {
|
||
|
_migrations.addAll(migrations);
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
/// Adds a database [Callback] to the builder.
|
||
|
_$HxDatabaseBuilder addCallback(Callback callback) {
|
||
|
_callback = callback;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
/// Creates the database and initializes it.
|
||
|
Future<HxDatabase> build() async {
|
||
|
final path = name != null
|
||
|
? await sqfliteDatabaseFactory.getDatabasePath(name)
|
||
|
: ':memory:';
|
||
|
final database = _$HxDatabase();
|
||
|
database.database = await database.open(
|
||
|
path,
|
||
|
_migrations,
|
||
|
_callback,
|
||
|
);
|
||
|
return database;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class _$HxDatabase extends HxDatabase {
|
||
|
_$HxDatabase([StreamController<String> listener]) {
|
||
|
changeListener = listener ?? StreamController<String>.broadcast();
|
||
|
}
|
||
|
|
||
|
MessageDao _messageDaoInstance;
|
||
|
|
||
|
Future<sqflite.Database> open(
|
||
|
String path,
|
||
|
List<Migration> 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 `Message` (`id` INTEGER, `fromId` INTEGER, `toId` INTEGER, `content` TEXT, `attach` TEXT, `msgType` INTEGER, `time` INTEGER, `state` INTEGER, `isDelete` INTEGER, PRIMARY KEY (`id`))');
|
||
|
|
||
|
await callback?.onCreate?.call(database, version);
|
||
|
},
|
||
|
);
|
||
|
return sqfliteDatabaseFactory.openDatabase(path, options: databaseOptions);
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
MessageDao get messageDao {
|
||
|
return _messageDaoInstance ??= _$MessageDao(database, changeListener);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class _$MessageDao extends MessageDao {
|
||
|
_$MessageDao(
|
||
|
this.database,
|
||
|
this.changeListener,
|
||
|
) : _queryAdapter = QueryAdapter(database, changeListener),
|
||
|
_messageInsertionAdapter = InsertionAdapter(
|
||
|
database,
|
||
|
'Message',
|
||
|
(Message item) => item.toJson(),
|
||
|
changeListener);
|
||
|
|
||
|
final sqflite.DatabaseExecutor database;
|
||
|
|
||
|
final StreamController<String> changeListener;
|
||
|
|
||
|
final QueryAdapter _queryAdapter;
|
||
|
|
||
|
final InsertionAdapter<Message> _messageInsertionAdapter;
|
||
|
|
||
|
@override
|
||
|
Stream<List<Message>> findMessageByToId(int toId) {
|
||
|
return _queryAdapter.queryListStream(
|
||
|
'SELECT * FROM Message WHERE toId = ?1',
|
||
|
mapper: (Map<String, Object> row) => Message.fromJson(row),
|
||
|
arguments: [toId],
|
||
|
queryableName: 'Message',
|
||
|
isView: false);
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
Future<List<Message>> findMessageByGroup(int userId) {
|
||
|
debugPrint("findMessageByGroup: $userId");
|
||
|
return _queryAdapter.queryList(
|
||
|
'SELECT * FROM Message WHERE toId = ?1 OR fromId = ?2 GROUP BY toId,fromId ORDER BY time DESC',
|
||
|
mapper: (Map<String, Object> row) => Message.fromJson(row),
|
||
|
arguments: [userId, userId]);
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
Future<void> insertMessage(Message message) async {
|
||
|
await _messageInsertionAdapter.insert(message, OnConflictStrategy.abort);
|
||
|
}
|
||
|
}
|