diff --git a/lib/data/dao/player_group_dao.dart b/lib/data/dao/player_group_dao.dart index b68ed09..e51c325 100644 --- a/lib/data/dao/player_group_dao.dart +++ b/lib/data/dao/player_group_dao.dart @@ -19,26 +19,26 @@ class PlayerGroupDao extends DatabaseAccessor List groupMembers = []; for (var entry in result) { - final player = await db.playerDao.getPlayerById(entry.userId); + final player = await db.playerDao.getPlayerById(entry.playerId); groupMembers.add(player); } return groupMembers; } - /// Removes a player from a group based on [userId] and [groupId]. + /// Removes a player from a group based on [playerId] and [groupId]. /// Returns `true` if more than 0 rows were affected, otherwise `false`. - Future removePlayerFromGroup(String userId, String groupId) async { + Future removePlayerFromGroup(String playerId, String groupId) async { final query = delete(playerGroupTable) - ..where((p) => p.userId.equals(userId) & p.groupId.equals(groupId)); + ..where((p) => p.playerId.equals(playerId) & p.groupId.equals(groupId)); final rowsAffected = await query.go(); return rowsAffected > 0; } - /// Adds a player to a group with the given [userId] and [groupId]. - Future addPlayerToGroup(String userId, String groupId) async { + /// Adds a player to a group with the given [playerId] and [groupId]. + Future addPlayerToGroup(String playerId, String groupId) async { await into(playerGroupTable).insert( - PlayerGroupTableCompanion.insert(userId: userId, groupId: groupId), + PlayerGroupTableCompanion.insert(playerId: playerId, groupId: groupId), ); } } diff --git a/lib/data/db/database.g.dart b/lib/data/db/database.g.dart index 4075912..d4e9e94 100644 --- a/lib/data/db/database.g.dart +++ b/lib/data/db/database.g.dart @@ -419,10 +419,12 @@ class $PlayerGroupTableTable extends PlayerGroupTable final GeneratedDatabase attachedDatabase; final String? _alias; $PlayerGroupTableTable(this.attachedDatabase, [this._alias]); - static const VerificationMeta _userIdMeta = const VerificationMeta('userId'); + static const VerificationMeta _playerIdMeta = const VerificationMeta( + 'playerId', + ); @override - late final GeneratedColumn userId = GeneratedColumn( - 'user_id', + late final GeneratedColumn playerId = GeneratedColumn( + 'player_id', aliasedName, false, type: DriftSqlType.string, @@ -446,7 +448,7 @@ class $PlayerGroupTableTable extends PlayerGroupTable ), ); @override - List get $columns => [userId, groupId]; + List get $columns => [playerId, groupId]; @override String get aliasedName => _alias ?? actualTableName; @override @@ -459,13 +461,13 @@ class $PlayerGroupTableTable extends PlayerGroupTable }) { final context = VerificationContext(); final data = instance.toColumns(true); - if (data.containsKey('user_id')) { + if (data.containsKey('player_id')) { context.handle( - _userIdMeta, - userId.isAcceptableOrUnknown(data['user_id']!, _userIdMeta), + _playerIdMeta, + playerId.isAcceptableOrUnknown(data['player_id']!, _playerIdMeta), ); } else if (isInserting) { - context.missing(_userIdMeta); + context.missing(_playerIdMeta); } if (data.containsKey('group_id')) { context.handle( @@ -479,14 +481,14 @@ class $PlayerGroupTableTable extends PlayerGroupTable } @override - Set get $primaryKey => {userId, groupId}; + Set get $primaryKey => {playerId, groupId}; @override PlayerGroupTableData map(Map data, {String? tablePrefix}) { final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; return PlayerGroupTableData( - userId: attachedDatabase.typeMapping.read( + playerId: attachedDatabase.typeMapping.read( DriftSqlType.string, - data['${effectivePrefix}user_id'], + data['${effectivePrefix}player_id'], )!, groupId: attachedDatabase.typeMapping.read( DriftSqlType.string, @@ -503,20 +505,20 @@ class $PlayerGroupTableTable extends PlayerGroupTable class PlayerGroupTableData extends DataClass implements Insertable { - final String userId; + final String playerId; final String groupId; - const PlayerGroupTableData({required this.userId, required this.groupId}); + const PlayerGroupTableData({required this.playerId, required this.groupId}); @override Map toColumns(bool nullToAbsent) { final map = {}; - map['user_id'] = Variable(userId); + map['player_id'] = Variable(playerId); map['group_id'] = Variable(groupId); return map; } PlayerGroupTableCompanion toCompanion(bool nullToAbsent) { return PlayerGroupTableCompanion( - userId: Value(userId), + playerId: Value(playerId), groupId: Value(groupId), ); } @@ -527,7 +529,7 @@ class PlayerGroupTableData extends DataClass }) { serializer ??= driftRuntimeOptions.defaultSerializer; return PlayerGroupTableData( - userId: serializer.fromJson(json['userId']), + playerId: serializer.fromJson(json['playerId']), groupId: serializer.fromJson(json['groupId']), ); } @@ -535,19 +537,19 @@ class PlayerGroupTableData extends DataClass Map toJson({ValueSerializer? serializer}) { serializer ??= driftRuntimeOptions.defaultSerializer; return { - 'userId': serializer.toJson(userId), + 'playerId': serializer.toJson(playerId), 'groupId': serializer.toJson(groupId), }; } - PlayerGroupTableData copyWith({String? userId, String? groupId}) => + PlayerGroupTableData copyWith({String? playerId, String? groupId}) => PlayerGroupTableData( - userId: userId ?? this.userId, + playerId: playerId ?? this.playerId, groupId: groupId ?? this.groupId, ); PlayerGroupTableData copyWithCompanion(PlayerGroupTableCompanion data) { return PlayerGroupTableData( - userId: data.userId.present ? data.userId.value : this.userId, + playerId: data.playerId.present ? data.playerId.value : this.playerId, groupId: data.groupId.present ? data.groupId.value : this.groupId, ); } @@ -555,56 +557,56 @@ class PlayerGroupTableData extends DataClass @override String toString() { return (StringBuffer('PlayerGroupTableData(') - ..write('userId: $userId, ') + ..write('playerId: $playerId, ') ..write('groupId: $groupId') ..write(')')) .toString(); } @override - int get hashCode => Object.hash(userId, groupId); + int get hashCode => Object.hash(playerId, groupId); @override bool operator ==(Object other) => identical(this, other) || (other is PlayerGroupTableData && - other.userId == this.userId && + other.playerId == this.playerId && other.groupId == this.groupId); } class PlayerGroupTableCompanion extends UpdateCompanion { - final Value userId; + final Value playerId; final Value groupId; final Value rowid; const PlayerGroupTableCompanion({ - this.userId = const Value.absent(), + this.playerId = const Value.absent(), this.groupId = const Value.absent(), this.rowid = const Value.absent(), }); PlayerGroupTableCompanion.insert({ - required String userId, + required String playerId, required String groupId, this.rowid = const Value.absent(), - }) : userId = Value(userId), + }) : playerId = Value(playerId), groupId = Value(groupId); static Insertable custom({ - Expression? userId, + Expression? playerId, Expression? groupId, Expression? rowid, }) { return RawValuesInsertable({ - if (userId != null) 'user_id': userId, + if (playerId != null) 'player_id': playerId, if (groupId != null) 'group_id': groupId, if (rowid != null) 'rowid': rowid, }); } PlayerGroupTableCompanion copyWith({ - Value? userId, + Value? playerId, Value? groupId, Value? rowid, }) { return PlayerGroupTableCompanion( - userId: userId ?? this.userId, + playerId: playerId ?? this.playerId, groupId: groupId ?? this.groupId, rowid: rowid ?? this.rowid, ); @@ -613,8 +615,8 @@ class PlayerGroupTableCompanion extends UpdateCompanion { @override Map toColumns(bool nullToAbsent) { final map = {}; - if (userId.present) { - map['user_id'] = Variable(userId.value); + if (playerId.present) { + map['player_id'] = Variable(playerId.value); } if (groupId.present) { map['group_id'] = Variable(groupId.value); @@ -628,7 +630,7 @@ class PlayerGroupTableCompanion extends UpdateCompanion { @override String toString() { return (StringBuffer('PlayerGroupTableCompanion(') - ..write('userId: $userId, ') + ..write('playerId: $playerId, ') ..write('groupId: $groupId, ') ..write('rowid: $rowid') ..write(')')) @@ -890,7 +892,7 @@ final class $$PlayerTableTableReferences db.playerGroupTable, aliasName: $_aliasNameGenerator( db.playerTable.id, - db.playerGroupTable.userId, + db.playerGroupTable.playerId, ), ); @@ -898,7 +900,7 @@ final class $$PlayerTableTableReferences final manager = $$PlayerGroupTableTableTableManager( $_db, $_db.playerGroupTable, - ).filter((f) => f.userId.id.sqlEquals($_itemColumn('id')!)); + ).filter((f) => f.playerId.id.sqlEquals($_itemColumn('id')!)); final cache = $_typedResult.readTableOrNull( _playerGroupTableRefsTable($_db), @@ -935,7 +937,7 @@ class $$PlayerTableTableFilterComposer composer: this, getCurrentColumn: (t) => t.id, referencedTable: $db.playerGroupTable, - getReferencedColumn: (t) => t.userId, + getReferencedColumn: (t) => t.playerId, builder: ( joinBuilder, { @@ -996,7 +998,7 @@ class $$PlayerTableTableAnnotationComposer composer: this, getCurrentColumn: (t) => t.id, referencedTable: $db.playerGroupTable, - getReferencedColumn: (t) => t.userId, + getReferencedColumn: (t) => t.playerId, builder: ( joinBuilder, { @@ -1087,7 +1089,7 @@ class $$PlayerTableTableTableManager p0, ).playerGroupTableRefs, referencedItemsForCurrentItem: (item, referencedItems) => - referencedItems.where((e) => e.userId == item.id), + referencedItems.where((e) => e.playerId == item.id), typedResults: items, ), ]; @@ -1358,13 +1360,13 @@ typedef $$GroupTableTableProcessedTableManager = >; typedef $$PlayerGroupTableTableCreateCompanionBuilder = PlayerGroupTableCompanion Function({ - required String userId, + required String playerId, required String groupId, Value rowid, }); typedef $$PlayerGroupTableTableUpdateCompanionBuilder = PlayerGroupTableCompanion Function({ - Value userId, + Value playerId, Value groupId, Value rowid, }); @@ -1382,19 +1384,19 @@ final class $$PlayerGroupTableTableReferences super.$_typedResult, ); - static $PlayerTableTable _userIdTable(_$AppDatabase db) => + static $PlayerTableTable _playerIdTable(_$AppDatabase db) => db.playerTable.createAlias( - $_aliasNameGenerator(db.playerGroupTable.userId, db.playerTable.id), + $_aliasNameGenerator(db.playerGroupTable.playerId, db.playerTable.id), ); - $$PlayerTableTableProcessedTableManager get userId { - final $_column = $_itemColumn('user_id')!; + $$PlayerTableTableProcessedTableManager get playerId { + final $_column = $_itemColumn('player_id')!; final manager = $$PlayerTableTableTableManager( $_db, $_db.playerTable, ).filter((f) => f.id.sqlEquals($_column)); - final item = $_typedResult.readTableOrNull(_userIdTable($_db)); + final item = $_typedResult.readTableOrNull(_playerIdTable($_db)); if (item == null) return manager; return ProcessedTableManager( manager.$state.copyWith(prefetchedData: [item]), @@ -1430,10 +1432,10 @@ class $$PlayerGroupTableTableFilterComposer super.$addJoinBuilderToRootComposer, super.$removeJoinBuilderFromRootComposer, }); - $$PlayerTableTableFilterComposer get userId { + $$PlayerTableTableFilterComposer get playerId { final $$PlayerTableTableFilterComposer composer = $composerBuilder( composer: this, - getCurrentColumn: (t) => t.userId, + getCurrentColumn: (t) => t.playerId, referencedTable: $db.playerTable, getReferencedColumn: (t) => t.id, builder: @@ -1486,10 +1488,10 @@ class $$PlayerGroupTableTableOrderingComposer super.$addJoinBuilderToRootComposer, super.$removeJoinBuilderFromRootComposer, }); - $$PlayerTableTableOrderingComposer get userId { + $$PlayerTableTableOrderingComposer get playerId { final $$PlayerTableTableOrderingComposer composer = $composerBuilder( composer: this, - getCurrentColumn: (t) => t.userId, + getCurrentColumn: (t) => t.playerId, referencedTable: $db.playerTable, getReferencedColumn: (t) => t.id, builder: @@ -1542,10 +1544,10 @@ class $$PlayerGroupTableTableAnnotationComposer super.$addJoinBuilderToRootComposer, super.$removeJoinBuilderFromRootComposer, }); - $$PlayerTableTableAnnotationComposer get userId { + $$PlayerTableTableAnnotationComposer get playerId { final $$PlayerTableTableAnnotationComposer composer = $composerBuilder( composer: this, - getCurrentColumn: (t) => t.userId, + getCurrentColumn: (t) => t.playerId, referencedTable: $db.playerTable, getReferencedColumn: (t) => t.id, builder: @@ -1602,7 +1604,7 @@ class $$PlayerGroupTableTableTableManager $$PlayerGroupTableTableUpdateCompanionBuilder, (PlayerGroupTableData, $$PlayerGroupTableTableReferences), PlayerGroupTableData, - PrefetchHooks Function({bool userId, bool groupId}) + PrefetchHooks Function({bool playerId, bool groupId}) > { $$PlayerGroupTableTableTableManager( _$AppDatabase db, @@ -1619,21 +1621,21 @@ class $$PlayerGroupTableTableTableManager $$PlayerGroupTableTableAnnotationComposer($db: db, $table: table), updateCompanionCallback: ({ - Value userId = const Value.absent(), + Value playerId = const Value.absent(), Value groupId = const Value.absent(), Value rowid = const Value.absent(), }) => PlayerGroupTableCompanion( - userId: userId, + playerId: playerId, groupId: groupId, rowid: rowid, ), createCompanionCallback: ({ - required String userId, + required String playerId, required String groupId, Value rowid = const Value.absent(), }) => PlayerGroupTableCompanion.insert( - userId: userId, + playerId: playerId, groupId: groupId, rowid: rowid, ), @@ -1645,7 +1647,7 @@ class $$PlayerGroupTableTableTableManager ), ) .toList(), - prefetchHooksCallback: ({userId = false, groupId = false}) { + prefetchHooksCallback: ({playerId = false, groupId = false}) { return PrefetchHooks( db: db, explicitlyWatchedTables: [], @@ -1665,17 +1667,17 @@ class $$PlayerGroupTableTableTableManager dynamic > >(state) { - if (userId) { + if (playerId) { state = state.withJoin( currentTable: table, - currentColumn: table.userId, + currentColumn: table.playerId, referencedTable: $$PlayerGroupTableTableReferences - ._userIdTable(db), + ._playerIdTable(db), referencedColumn: $$PlayerGroupTableTableReferences - ._userIdTable(db) + ._playerIdTable(db) .id, ) as T; @@ -1719,7 +1721,7 @@ typedef $$PlayerGroupTableTableProcessedTableManager = $$PlayerGroupTableTableUpdateCompanionBuilder, (PlayerGroupTableData, $$PlayerGroupTableTableReferences), PlayerGroupTableData, - PrefetchHooks Function({bool userId, bool groupId}) + PrefetchHooks Function({bool playerId, bool groupId}) >; typedef $$GameTableTableCreateCompanionBuilder = GameTableCompanion Function({ diff --git a/lib/data/db/tables/player_group_table.dart b/lib/data/db/tables/player_group_table.dart index 096a981..61e2ed8 100644 --- a/lib/data/db/tables/player_group_table.dart +++ b/lib/data/db/tables/player_group_table.dart @@ -3,9 +3,9 @@ import 'package:game_tracker/data/db/tables/group_table.dart'; import 'package:game_tracker/data/db/tables/player_table.dart'; class PlayerGroupTable extends Table { - TextColumn get userId => text().references(PlayerTable, #id)(); + TextColumn get playerId => text().references(PlayerTable, #id)(); TextColumn get groupId => text().references(GroupTable, #id)(); @override - Set> get primaryKey => {userId, groupId}; + Set> get primaryKey => {playerId, groupId}; }