update drift to 2.7.0

Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
Sahil Kumar
2023-04-20 18:41:51 +05:30
committed by xsahil03x
parent a1a4e55e75
commit fc05a9a4cf
28 changed files with 2021 additions and 1740 deletions
@@ -6,7 +6,21 @@ import 'package:drift/drift.dart';
/// by the sqlite backend.
class ListConverter<T> extends TypeConverter<List<T>, String> {
@override
List<T>? mapToDart(String? fromDb) {
List<T> fromSql(String fromDb) {
return List<T>.from(jsonDecode(fromDb) ?? []);
}
@override
String toSql(List<T> value) {
return jsonEncode(value);
}
}
/// Maps a nullable [List] of type [T] into a nullable [String] understood
/// by the sqlite backend.
class NullableListConverter<T> extends TypeConverter<List<T>?, String?> {
@override
List<T>? fromSql(String? fromDb) {
if (fromDb == null) {
return null;
}
@@ -14,7 +28,7 @@ class ListConverter<T> extends TypeConverter<List<T>, String> {
}
@override
String? mapToSql(List<T>? value) {
String? toSql(List<T>? value) {
if (value == null) {
return null;
}
@@ -6,7 +6,21 @@ import 'package:drift/drift.dart';
/// by the sqlite backend.
class MapConverter<T> extends TypeConverter<Map<String, T>, String> {
@override
Map<String, T>? mapToDart(String? fromDb) {
Map<String, T> fromSql(String fromDb) {
return Map<String, T>.from(jsonDecode(fromDb) ?? {});
}
@override
String toSql(Map<String, T> value) {
return jsonEncode(value);
}
}
/// Maps a nullable [Map] of type [String], [T] into a nullable [String]
/// understood by the sqlite backend.
class NullableMapConverter<T> extends TypeConverter<Map<String, T>?, String?> {
@override
Map<String, T>? fromSql(String? fromDb) {
if (fromDb == null) {
return null;
}
@@ -14,7 +28,7 @@ class MapConverter<T> extends TypeConverter<Map<String, T>, String> {
}
@override
String? mapToSql(Map<String, T>? value) {
String? toSql(Map<String, T>? value) {
if (value == null) {
return null;
}
@@ -6,7 +6,7 @@ import 'package:stream_chat/stream_chat.dart';
class MessageSendingStatusConverter
extends TypeConverter<MessageSendingStatus, int> {
@override
MessageSendingStatus? mapToDart(int? fromDb) {
MessageSendingStatus fromSql(int fromDb) {
switch (fromDb) {
case 0:
return MessageSendingStatus.sending;
@@ -22,13 +22,12 @@ class MessageSendingStatusConverter
return MessageSendingStatus.deleting;
case 6:
return MessageSendingStatus.failed_delete;
default:
return null;
}
return MessageSendingStatus.sending;
}
@override
int? mapToSql(MessageSendingStatus? value) {
int toSql(MessageSendingStatus value) {
switch (value) {
case MessageSendingStatus.sending:
return 0;
@@ -44,8 +43,6 @@ class MessageSendingStatusConverter
return 5;
case MessageSendingStatus.failed_delete:
return 6;
default:
return null;
}
}
}
@@ -2,10 +2,7 @@
part of 'channel_dao.dart';
// **************************************************************************
// DaoGenerator
// **************************************************************************
// ignore_for_file: type=lint
mixin _$ChannelDaoMixin on DatabaseAccessor<DriftChatDatabase> {
$ChannelsTable get channels => attachedDatabase.channels;
$UsersTable get users => attachedDatabase.users;
@@ -2,10 +2,7 @@
part of 'channel_query_dao.dart';
// **************************************************************************
// DaoGenerator
// **************************************************************************
// ignore_for_file: type=lint
mixin _$ChannelQueryDaoMixin on DatabaseAccessor<DriftChatDatabase> {
$ChannelQueriesTable get channelQueries => attachedDatabase.channelQueries;
$ChannelsTable get channels => attachedDatabase.channels;
@@ -2,10 +2,7 @@
part of 'connection_event_dao.dart';
// **************************************************************************
// DaoGenerator
// **************************************************************************
// ignore_for_file: type=lint
mixin _$ConnectionEventDaoMixin on DatabaseAccessor<DriftChatDatabase> {
$ConnectionEventsTable get connectionEvents =>
attachedDatabase.connectionEvents;
@@ -2,10 +2,7 @@
part of 'member_dao.dart';
// **************************************************************************
// DaoGenerator
// **************************************************************************
// ignore_for_file: type=lint
mixin _$MemberDaoMixin on DatabaseAccessor<DriftChatDatabase> {
$MembersTable get members => attachedDatabase.members;
$UsersTable get users => attachedDatabase.users;
@@ -2,11 +2,9 @@
part of 'message_dao.dart';
// **************************************************************************
// DaoGenerator
// **************************************************************************
// ignore_for_file: type=lint
mixin _$MessageDaoMixin on DatabaseAccessor<DriftChatDatabase> {
$ChannelsTable get channels => attachedDatabase.channels;
$MessagesTable get messages => attachedDatabase.messages;
$UsersTable get users => attachedDatabase.users;
}
@@ -2,11 +2,9 @@
part of 'pinned_message_dao.dart';
// **************************************************************************
// DaoGenerator
// **************************************************************************
// ignore_for_file: type=lint
mixin _$PinnedMessageDaoMixin on DatabaseAccessor<DriftChatDatabase> {
$ChannelsTable get channels => attachedDatabase.channels;
$PinnedMessagesTable get pinnedMessages => attachedDatabase.pinnedMessages;
$UsersTable get users => attachedDatabase.users;
}
@@ -2,10 +2,7 @@
part of 'pinned_message_reaction_dao.dart';
// **************************************************************************
// DaoGenerator
// **************************************************************************
// ignore_for_file: type=lint
mixin _$PinnedMessageReactionDaoMixin on DatabaseAccessor<DriftChatDatabase> {
$PinnedMessageReactionsTable get pinnedMessageReactions =>
attachedDatabase.pinnedMessageReactions;
@@ -2,10 +2,7 @@
part of 'reaction_dao.dart';
// **************************************************************************
// DaoGenerator
// **************************************************************************
// ignore_for_file: type=lint
mixin _$ReactionDaoMixin on DatabaseAccessor<DriftChatDatabase> {
$ReactionsTable get reactions => attachedDatabase.reactions;
$UsersTable get users => attachedDatabase.users;
@@ -2,10 +2,7 @@
part of 'read_dao.dart';
// **************************************************************************
// DaoGenerator
// **************************************************************************
// ignore_for_file: type=lint
mixin _$ReadDaoMixin on DatabaseAccessor<DriftChatDatabase> {
$ReadsTable get reads => attachedDatabase.reads;
$UsersTable get users => attachedDatabase.users;
@@ -2,10 +2,7 @@
part of 'user_dao.dart';
// **************************************************************************
// DaoGenerator
// **************************************************************************
// ignore_for_file: type=lint
mixin _$UserDaoMixin on DatabaseAccessor<DriftChatDatabase> {
$UsersTable get users => attachedDatabase.users;
}
@@ -1,6 +1,5 @@
import 'package:drift/drift.dart';
import 'package:stream_chat/stream_chat.dart';
import 'package:stream_chat_persistence/src/converter/converter.dart';
import 'package:stream_chat_persistence/src/dao/dao.dart';
import 'package:stream_chat_persistence/src/entity/entity.dart';
@@ -37,18 +36,12 @@ part 'drift_chat_database.g.dart';
],
)
class DriftChatDatabase extends _$DriftChatDatabase {
/// Creates a new moor chat database instance
/// Creates a new drift chat database instance
DriftChatDatabase(
this._userId,
QueryExecutor executor,
) : super(executor);
/// Instantiate a new database instance
DriftChatDatabase.connect(
this._userId,
DatabaseConnection connection,
) : super.connect(connection);
final String _userId;
/// User id to which the database is connected
File diff suppressed because it is too large Load Diff
@@ -23,7 +23,7 @@ class SharedDB {
}) async {
final dbName = 'db_$userId';
if (connectionMode == ConnectionMode.background) {
return DriftChatDatabase.connect(
return DriftChatDatabase(
userId,
DatabaseConnection.delayed(Future(() async {
final isolate = await _createMoorIsolate(
@@ -34,6 +34,7 @@ class SharedDB {
})),
);
}
return DriftChatDatabase(
userId,
LazyDatabase(
@@ -68,7 +69,7 @@ class SharedDB {
logStatements: request.logStatements,
));
final moorIsolate = DriftIsolate.inCurrent(
() => DatabaseConnection.fromExecutor(executor),
() => DatabaseConnection(executor),
);
request.sendMoorIsolate.send(moorIsolate);
}
@@ -4,6 +4,8 @@ import 'package:stream_chat_persistence/src/converter/list_converter.dart';
import 'package:stream_chat_persistence/src/converter/map_converter.dart';
import 'package:stream_chat_persistence/src/converter/message_sending_status_converter.dart';
import 'channels.dart';
/// Represents a [Messages] table in [MoorChatDatabase].
@DataClassName('MessageEntity')
class Messages extends Table {
@@ -78,10 +80,11 @@ class Messages extends Table {
/// The channel cid of which this message is part of
TextColumn get channelCid =>
text().customConstraint('REFERENCES channels(cid) ON DELETE CASCADE')();
text().references(Channels, #cid, onDelete: KeyAction.cascade)();
/// A Map of [messageText] translations.
TextColumn get i18n => text().nullable().map(MapConverter<String>())();
TextColumn get i18n =>
text().nullable().map(NullableMapConverter<String>())();
/// Message custom extraData
TextColumn get extraData => text().nullable().map(MapConverter<Object?>())();
@@ -1,6 +1,5 @@
// coverage:ignore-file
import 'package:drift/drift.dart';
import 'package:stream_chat_persistence/src/entity/messages.dart';
/// Represents a [PinnedMessages] table in [MoorChatDatabase].