refactor
This commit is contained in:
@@ -2,27 +2,27 @@ import 'package:game_tracker/data/database.dart';
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
extension GroupMethods on AppDatabase {
|
||||
Future<List<GroupData>> getAllGroups() async {
|
||||
return await select(group).get();
|
||||
Future<List<GroupTableData>> getAllGroups() async {
|
||||
return await select(groupTable).get();
|
||||
}
|
||||
|
||||
Future<GroupData> getGroupById(String id) async {
|
||||
return await (select(group)..where((g) => g.id.equals(id))).getSingle();
|
||||
Future<GroupTableData> getGroupById(String id) async {
|
||||
return await (select(groupTable)..where((g) => g.id.equals(id))).getSingle();
|
||||
}
|
||||
|
||||
Future<void> addGroup(String id, String name) async {
|
||||
await into(group).insert(
|
||||
GroupCompanion.insert(id: id, name: name),
|
||||
await into(groupTable).insert(
|
||||
GroupTableCompanion.insert(id: id, name: name),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> deleteGroup(String id) async {
|
||||
await (delete(group)..where((g) => g.id.equals(id))).go();
|
||||
await (delete(groupTable)..where((g) => g.id.equals(id))).go();
|
||||
}
|
||||
|
||||
Future<void> updateGroupname(String id, String newName) async {
|
||||
await (update(group)..where((g) => g.id.equals(id))).write(
|
||||
GroupCompanion(name: Value(newName)),
|
||||
await (update(groupTable)..where((g) => g.id.equals(id))).write(
|
||||
GroupTableCompanion(name: Value(newName)),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,27 +2,27 @@ import 'package:game_tracker/data/database.dart';
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
extension UserMethods on AppDatabase {
|
||||
Future<List<UserData>> getAllUsers() async {
|
||||
return await select(user).get();
|
||||
Future<List<UserTableData>> getAllUsers() async {
|
||||
return await select(userTable).get();
|
||||
}
|
||||
|
||||
Future<UserData> getUserById(String id) async {
|
||||
return await (select(user)..where((u) => u.id.equals(id))).getSingle();
|
||||
Future<UserTableData> getUserById(String id) async {
|
||||
return await (select(userTable)..where((u) => u.id.equals(id))).getSingle();
|
||||
}
|
||||
|
||||
Future<void> addUser(String id, String name) async {
|
||||
await into(user).insert(
|
||||
UserCompanion.insert(id: id, name: name),
|
||||
await into(userTable).insert(
|
||||
UserTableCompanion.insert(id: id, name: name),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> deleteUser(String id) async {
|
||||
await (delete(user)..where((u) => u.id.equals(id))).go();
|
||||
await (delete(userTable)..where((u) => u.id.equals(id))).go();
|
||||
}
|
||||
|
||||
Future<void> updateUsername(String id, String newName) async {
|
||||
await (update(user)..where((u) => u.id.equals(id))).write(
|
||||
UserCompanion(name: Value(newName)),
|
||||
await (update(userTable)..where((u) => u.id.equals(id))).write(
|
||||
UserTableCompanion(name: Value(newName)),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,25 +2,25 @@ import 'package:game_tracker/data/database.dart';
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
extension UserGroupMethods on AppDatabase {
|
||||
Future<List<UserGroupData>> getAllUsersAndGroups() async {
|
||||
return await select(userGroup).get();
|
||||
Future<List<UserGroupTableData>> getAllUsersAndGroups() async {
|
||||
return await select(userGroupTable).get();
|
||||
}
|
||||
|
||||
Future<List<UserGroupData>> getUsersGroups(String userId) async {
|
||||
return await (select(userGroup)..where((uG) => uG.userId.equals(userId))).get();
|
||||
Future<List<UserGroupTableData>> getUsersGroups(String userId) async {
|
||||
return await (select(userGroupTable)..where((uG) => uG.userId.equals(userId))).get();
|
||||
}
|
||||
|
||||
Future<List<UserGroupData>> getGroupsUsers(String groupId) async {
|
||||
return await (select(userGroup)..where((uG) => uG.groupId.equals(groupId))).get();
|
||||
Future<List<UserGroupTableData>> getGroupsUsers(String groupId) async {
|
||||
return await (select(userGroupTable)..where((uG) => uG.groupId.equals(groupId))).get();
|
||||
}
|
||||
|
||||
Future<void> addUserToGroup(String userId, String groupId) async {
|
||||
await into(userGroup).insert(
|
||||
UserGroupCompanion.insert(userId: userId, groupId: groupId),
|
||||
await into(userGroupTable).insert(
|
||||
UserGroupTableCompanion.insert(userId: userId, groupId: groupId),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> removeUserFromGroup(String userId, String groupId) async {
|
||||
await (delete(userGroup)..where((uG) => uG.userId.equals(userId) & uG.groupId.equals(groupId))).go();
|
||||
await (delete(userGroupTable)..where((uG) => uG.userId.equals(userId) & uG.groupId.equals(groupId))).go();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user