updated userId to playerId

This commit is contained in:
2025-11-12 10:57:46 +01:00
parent b83fe03f35
commit 25c7b37df3
3 changed files with 74 additions and 72 deletions

View File

@@ -19,26 +19,26 @@ class PlayerGroupDao extends DatabaseAccessor<AppDatabase>
List<Player> groupMembers = []; List<Player> groupMembers = [];
for (var entry in result) { for (var entry in result) {
final player = await db.playerDao.getPlayerById(entry.userId); final player = await db.playerDao.getPlayerById(entry.playerId);
groupMembers.add(player); groupMembers.add(player);
} }
return groupMembers; 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`. /// Returns `true` if more than 0 rows were affected, otherwise `false`.
Future<bool> removePlayerFromGroup(String userId, String groupId) async { Future<bool> removePlayerFromGroup(String playerId, String groupId) async {
final query = delete(playerGroupTable) 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(); final rowsAffected = await query.go();
return rowsAffected > 0; return rowsAffected > 0;
} }
/// Adds a player to a group with the given [userId] and [groupId]. /// Adds a player to a group with the given [playerId] and [groupId].
Future<void> addPlayerToGroup(String userId, String groupId) async { Future<void> addPlayerToGroup(String playerId, String groupId) async {
await into(playerGroupTable).insert( await into(playerGroupTable).insert(
PlayerGroupTableCompanion.insert(userId: userId, groupId: groupId), PlayerGroupTableCompanion.insert(playerId: playerId, groupId: groupId),
); );
} }
} }

View File

@@ -419,10 +419,12 @@ class $PlayerGroupTableTable extends PlayerGroupTable
final GeneratedDatabase attachedDatabase; final GeneratedDatabase attachedDatabase;
final String? _alias; final String? _alias;
$PlayerGroupTableTable(this.attachedDatabase, [this._alias]); $PlayerGroupTableTable(this.attachedDatabase, [this._alias]);
static const VerificationMeta _userIdMeta = const VerificationMeta('userId'); static const VerificationMeta _playerIdMeta = const VerificationMeta(
'playerId',
);
@override @override
late final GeneratedColumn<String> userId = GeneratedColumn<String>( late final GeneratedColumn<String> playerId = GeneratedColumn<String>(
'user_id', 'player_id',
aliasedName, aliasedName,
false, false,
type: DriftSqlType.string, type: DriftSqlType.string,
@@ -446,7 +448,7 @@ class $PlayerGroupTableTable extends PlayerGroupTable
), ),
); );
@override @override
List<GeneratedColumn> get $columns => [userId, groupId]; List<GeneratedColumn> get $columns => [playerId, groupId];
@override @override
String get aliasedName => _alias ?? actualTableName; String get aliasedName => _alias ?? actualTableName;
@override @override
@@ -459,13 +461,13 @@ class $PlayerGroupTableTable extends PlayerGroupTable
}) { }) {
final context = VerificationContext(); final context = VerificationContext();
final data = instance.toColumns(true); final data = instance.toColumns(true);
if (data.containsKey('user_id')) { if (data.containsKey('player_id')) {
context.handle( context.handle(
_userIdMeta, _playerIdMeta,
userId.isAcceptableOrUnknown(data['user_id']!, _userIdMeta), playerId.isAcceptableOrUnknown(data['player_id']!, _playerIdMeta),
); );
} else if (isInserting) { } else if (isInserting) {
context.missing(_userIdMeta); context.missing(_playerIdMeta);
} }
if (data.containsKey('group_id')) { if (data.containsKey('group_id')) {
context.handle( context.handle(
@@ -479,14 +481,14 @@ class $PlayerGroupTableTable extends PlayerGroupTable
} }
@override @override
Set<GeneratedColumn> get $primaryKey => {userId, groupId}; Set<GeneratedColumn> get $primaryKey => {playerId, groupId};
@override @override
PlayerGroupTableData map(Map<String, dynamic> data, {String? tablePrefix}) { PlayerGroupTableData map(Map<String, dynamic> data, {String? tablePrefix}) {
final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';
return PlayerGroupTableData( return PlayerGroupTableData(
userId: attachedDatabase.typeMapping.read( playerId: attachedDatabase.typeMapping.read(
DriftSqlType.string, DriftSqlType.string,
data['${effectivePrefix}user_id'], data['${effectivePrefix}player_id'],
)!, )!,
groupId: attachedDatabase.typeMapping.read( groupId: attachedDatabase.typeMapping.read(
DriftSqlType.string, DriftSqlType.string,
@@ -503,20 +505,20 @@ class $PlayerGroupTableTable extends PlayerGroupTable
class PlayerGroupTableData extends DataClass class PlayerGroupTableData extends DataClass
implements Insertable<PlayerGroupTableData> { implements Insertable<PlayerGroupTableData> {
final String userId; final String playerId;
final String groupId; final String groupId;
const PlayerGroupTableData({required this.userId, required this.groupId}); const PlayerGroupTableData({required this.playerId, required this.groupId});
@override @override
Map<String, Expression> toColumns(bool nullToAbsent) { Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{}; final map = <String, Expression>{};
map['user_id'] = Variable<String>(userId); map['player_id'] = Variable<String>(playerId);
map['group_id'] = Variable<String>(groupId); map['group_id'] = Variable<String>(groupId);
return map; return map;
} }
PlayerGroupTableCompanion toCompanion(bool nullToAbsent) { PlayerGroupTableCompanion toCompanion(bool nullToAbsent) {
return PlayerGroupTableCompanion( return PlayerGroupTableCompanion(
userId: Value(userId), playerId: Value(playerId),
groupId: Value(groupId), groupId: Value(groupId),
); );
} }
@@ -527,7 +529,7 @@ class PlayerGroupTableData extends DataClass
}) { }) {
serializer ??= driftRuntimeOptions.defaultSerializer; serializer ??= driftRuntimeOptions.defaultSerializer;
return PlayerGroupTableData( return PlayerGroupTableData(
userId: serializer.fromJson<String>(json['userId']), playerId: serializer.fromJson<String>(json['playerId']),
groupId: serializer.fromJson<String>(json['groupId']), groupId: serializer.fromJson<String>(json['groupId']),
); );
} }
@@ -535,19 +537,19 @@ class PlayerGroupTableData extends DataClass
Map<String, dynamic> toJson({ValueSerializer? serializer}) { Map<String, dynamic> toJson({ValueSerializer? serializer}) {
serializer ??= driftRuntimeOptions.defaultSerializer; serializer ??= driftRuntimeOptions.defaultSerializer;
return <String, dynamic>{ return <String, dynamic>{
'userId': serializer.toJson<String>(userId), 'playerId': serializer.toJson<String>(playerId),
'groupId': serializer.toJson<String>(groupId), 'groupId': serializer.toJson<String>(groupId),
}; };
} }
PlayerGroupTableData copyWith({String? userId, String? groupId}) => PlayerGroupTableData copyWith({String? playerId, String? groupId}) =>
PlayerGroupTableData( PlayerGroupTableData(
userId: userId ?? this.userId, playerId: playerId ?? this.playerId,
groupId: groupId ?? this.groupId, groupId: groupId ?? this.groupId,
); );
PlayerGroupTableData copyWithCompanion(PlayerGroupTableCompanion data) { PlayerGroupTableData copyWithCompanion(PlayerGroupTableCompanion data) {
return PlayerGroupTableData( 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, groupId: data.groupId.present ? data.groupId.value : this.groupId,
); );
} }
@@ -555,56 +557,56 @@ class PlayerGroupTableData extends DataClass
@override @override
String toString() { String toString() {
return (StringBuffer('PlayerGroupTableData(') return (StringBuffer('PlayerGroupTableData(')
..write('userId: $userId, ') ..write('playerId: $playerId, ')
..write('groupId: $groupId') ..write('groupId: $groupId')
..write(')')) ..write(')'))
.toString(); .toString();
} }
@override @override
int get hashCode => Object.hash(userId, groupId); int get hashCode => Object.hash(playerId, groupId);
@override @override
bool operator ==(Object other) => bool operator ==(Object other) =>
identical(this, other) || identical(this, other) ||
(other is PlayerGroupTableData && (other is PlayerGroupTableData &&
other.userId == this.userId && other.playerId == this.playerId &&
other.groupId == this.groupId); other.groupId == this.groupId);
} }
class PlayerGroupTableCompanion extends UpdateCompanion<PlayerGroupTableData> { class PlayerGroupTableCompanion extends UpdateCompanion<PlayerGroupTableData> {
final Value<String> userId; final Value<String> playerId;
final Value<String> groupId; final Value<String> groupId;
final Value<int> rowid; final Value<int> rowid;
const PlayerGroupTableCompanion({ const PlayerGroupTableCompanion({
this.userId = const Value.absent(), this.playerId = const Value.absent(),
this.groupId = const Value.absent(), this.groupId = const Value.absent(),
this.rowid = const Value.absent(), this.rowid = const Value.absent(),
}); });
PlayerGroupTableCompanion.insert({ PlayerGroupTableCompanion.insert({
required String userId, required String playerId,
required String groupId, required String groupId,
this.rowid = const Value.absent(), this.rowid = const Value.absent(),
}) : userId = Value(userId), }) : playerId = Value(playerId),
groupId = Value(groupId); groupId = Value(groupId);
static Insertable<PlayerGroupTableData> custom({ static Insertable<PlayerGroupTableData> custom({
Expression<String>? userId, Expression<String>? playerId,
Expression<String>? groupId, Expression<String>? groupId,
Expression<int>? rowid, Expression<int>? rowid,
}) { }) {
return RawValuesInsertable({ return RawValuesInsertable({
if (userId != null) 'user_id': userId, if (playerId != null) 'player_id': playerId,
if (groupId != null) 'group_id': groupId, if (groupId != null) 'group_id': groupId,
if (rowid != null) 'rowid': rowid, if (rowid != null) 'rowid': rowid,
}); });
} }
PlayerGroupTableCompanion copyWith({ PlayerGroupTableCompanion copyWith({
Value<String>? userId, Value<String>? playerId,
Value<String>? groupId, Value<String>? groupId,
Value<int>? rowid, Value<int>? rowid,
}) { }) {
return PlayerGroupTableCompanion( return PlayerGroupTableCompanion(
userId: userId ?? this.userId, playerId: playerId ?? this.playerId,
groupId: groupId ?? this.groupId, groupId: groupId ?? this.groupId,
rowid: rowid ?? this.rowid, rowid: rowid ?? this.rowid,
); );
@@ -613,8 +615,8 @@ class PlayerGroupTableCompanion extends UpdateCompanion<PlayerGroupTableData> {
@override @override
Map<String, Expression> toColumns(bool nullToAbsent) { Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{}; final map = <String, Expression>{};
if (userId.present) { if (playerId.present) {
map['user_id'] = Variable<String>(userId.value); map['player_id'] = Variable<String>(playerId.value);
} }
if (groupId.present) { if (groupId.present) {
map['group_id'] = Variable<String>(groupId.value); map['group_id'] = Variable<String>(groupId.value);
@@ -628,7 +630,7 @@ class PlayerGroupTableCompanion extends UpdateCompanion<PlayerGroupTableData> {
@override @override
String toString() { String toString() {
return (StringBuffer('PlayerGroupTableCompanion(') return (StringBuffer('PlayerGroupTableCompanion(')
..write('userId: $userId, ') ..write('playerId: $playerId, ')
..write('groupId: $groupId, ') ..write('groupId: $groupId, ')
..write('rowid: $rowid') ..write('rowid: $rowid')
..write(')')) ..write(')'))
@@ -890,7 +892,7 @@ final class $$PlayerTableTableReferences
db.playerGroupTable, db.playerGroupTable,
aliasName: $_aliasNameGenerator( aliasName: $_aliasNameGenerator(
db.playerTable.id, db.playerTable.id,
db.playerGroupTable.userId, db.playerGroupTable.playerId,
), ),
); );
@@ -898,7 +900,7 @@ final class $$PlayerTableTableReferences
final manager = $$PlayerGroupTableTableTableManager( final manager = $$PlayerGroupTableTableTableManager(
$_db, $_db,
$_db.playerGroupTable, $_db.playerGroupTable,
).filter((f) => f.userId.id.sqlEquals($_itemColumn<String>('id')!)); ).filter((f) => f.playerId.id.sqlEquals($_itemColumn<String>('id')!));
final cache = $_typedResult.readTableOrNull( final cache = $_typedResult.readTableOrNull(
_playerGroupTableRefsTable($_db), _playerGroupTableRefsTable($_db),
@@ -935,7 +937,7 @@ class $$PlayerTableTableFilterComposer
composer: this, composer: this,
getCurrentColumn: (t) => t.id, getCurrentColumn: (t) => t.id,
referencedTable: $db.playerGroupTable, referencedTable: $db.playerGroupTable,
getReferencedColumn: (t) => t.userId, getReferencedColumn: (t) => t.playerId,
builder: builder:
( (
joinBuilder, { joinBuilder, {
@@ -996,7 +998,7 @@ class $$PlayerTableTableAnnotationComposer
composer: this, composer: this,
getCurrentColumn: (t) => t.id, getCurrentColumn: (t) => t.id,
referencedTable: $db.playerGroupTable, referencedTable: $db.playerGroupTable,
getReferencedColumn: (t) => t.userId, getReferencedColumn: (t) => t.playerId,
builder: builder:
( (
joinBuilder, { joinBuilder, {
@@ -1087,7 +1089,7 @@ class $$PlayerTableTableTableManager
p0, p0,
).playerGroupTableRefs, ).playerGroupTableRefs,
referencedItemsForCurrentItem: (item, referencedItems) => referencedItemsForCurrentItem: (item, referencedItems) =>
referencedItems.where((e) => e.userId == item.id), referencedItems.where((e) => e.playerId == item.id),
typedResults: items, typedResults: items,
), ),
]; ];
@@ -1358,13 +1360,13 @@ typedef $$GroupTableTableProcessedTableManager =
>; >;
typedef $$PlayerGroupTableTableCreateCompanionBuilder = typedef $$PlayerGroupTableTableCreateCompanionBuilder =
PlayerGroupTableCompanion Function({ PlayerGroupTableCompanion Function({
required String userId, required String playerId,
required String groupId, required String groupId,
Value<int> rowid, Value<int> rowid,
}); });
typedef $$PlayerGroupTableTableUpdateCompanionBuilder = typedef $$PlayerGroupTableTableUpdateCompanionBuilder =
PlayerGroupTableCompanion Function({ PlayerGroupTableCompanion Function({
Value<String> userId, Value<String> playerId,
Value<String> groupId, Value<String> groupId,
Value<int> rowid, Value<int> rowid,
}); });
@@ -1382,19 +1384,19 @@ final class $$PlayerGroupTableTableReferences
super.$_typedResult, super.$_typedResult,
); );
static $PlayerTableTable _userIdTable(_$AppDatabase db) => static $PlayerTableTable _playerIdTable(_$AppDatabase db) =>
db.playerTable.createAlias( db.playerTable.createAlias(
$_aliasNameGenerator(db.playerGroupTable.userId, db.playerTable.id), $_aliasNameGenerator(db.playerGroupTable.playerId, db.playerTable.id),
); );
$$PlayerTableTableProcessedTableManager get userId { $$PlayerTableTableProcessedTableManager get playerId {
final $_column = $_itemColumn<String>('user_id')!; final $_column = $_itemColumn<String>('player_id')!;
final manager = $$PlayerTableTableTableManager( final manager = $$PlayerTableTableTableManager(
$_db, $_db,
$_db.playerTable, $_db.playerTable,
).filter((f) => f.id.sqlEquals($_column)); ).filter((f) => f.id.sqlEquals($_column));
final item = $_typedResult.readTableOrNull(_userIdTable($_db)); final item = $_typedResult.readTableOrNull(_playerIdTable($_db));
if (item == null) return manager; if (item == null) return manager;
return ProcessedTableManager( return ProcessedTableManager(
manager.$state.copyWith(prefetchedData: [item]), manager.$state.copyWith(prefetchedData: [item]),
@@ -1430,10 +1432,10 @@ class $$PlayerGroupTableTableFilterComposer
super.$addJoinBuilderToRootComposer, super.$addJoinBuilderToRootComposer,
super.$removeJoinBuilderFromRootComposer, super.$removeJoinBuilderFromRootComposer,
}); });
$$PlayerTableTableFilterComposer get userId { $$PlayerTableTableFilterComposer get playerId {
final $$PlayerTableTableFilterComposer composer = $composerBuilder( final $$PlayerTableTableFilterComposer composer = $composerBuilder(
composer: this, composer: this,
getCurrentColumn: (t) => t.userId, getCurrentColumn: (t) => t.playerId,
referencedTable: $db.playerTable, referencedTable: $db.playerTable,
getReferencedColumn: (t) => t.id, getReferencedColumn: (t) => t.id,
builder: builder:
@@ -1486,10 +1488,10 @@ class $$PlayerGroupTableTableOrderingComposer
super.$addJoinBuilderToRootComposer, super.$addJoinBuilderToRootComposer,
super.$removeJoinBuilderFromRootComposer, super.$removeJoinBuilderFromRootComposer,
}); });
$$PlayerTableTableOrderingComposer get userId { $$PlayerTableTableOrderingComposer get playerId {
final $$PlayerTableTableOrderingComposer composer = $composerBuilder( final $$PlayerTableTableOrderingComposer composer = $composerBuilder(
composer: this, composer: this,
getCurrentColumn: (t) => t.userId, getCurrentColumn: (t) => t.playerId,
referencedTable: $db.playerTable, referencedTable: $db.playerTable,
getReferencedColumn: (t) => t.id, getReferencedColumn: (t) => t.id,
builder: builder:
@@ -1542,10 +1544,10 @@ class $$PlayerGroupTableTableAnnotationComposer
super.$addJoinBuilderToRootComposer, super.$addJoinBuilderToRootComposer,
super.$removeJoinBuilderFromRootComposer, super.$removeJoinBuilderFromRootComposer,
}); });
$$PlayerTableTableAnnotationComposer get userId { $$PlayerTableTableAnnotationComposer get playerId {
final $$PlayerTableTableAnnotationComposer composer = $composerBuilder( final $$PlayerTableTableAnnotationComposer composer = $composerBuilder(
composer: this, composer: this,
getCurrentColumn: (t) => t.userId, getCurrentColumn: (t) => t.playerId,
referencedTable: $db.playerTable, referencedTable: $db.playerTable,
getReferencedColumn: (t) => t.id, getReferencedColumn: (t) => t.id,
builder: builder:
@@ -1602,7 +1604,7 @@ class $$PlayerGroupTableTableTableManager
$$PlayerGroupTableTableUpdateCompanionBuilder, $$PlayerGroupTableTableUpdateCompanionBuilder,
(PlayerGroupTableData, $$PlayerGroupTableTableReferences), (PlayerGroupTableData, $$PlayerGroupTableTableReferences),
PlayerGroupTableData, PlayerGroupTableData,
PrefetchHooks Function({bool userId, bool groupId}) PrefetchHooks Function({bool playerId, bool groupId})
> { > {
$$PlayerGroupTableTableTableManager( $$PlayerGroupTableTableTableManager(
_$AppDatabase db, _$AppDatabase db,
@@ -1619,21 +1621,21 @@ class $$PlayerGroupTableTableTableManager
$$PlayerGroupTableTableAnnotationComposer($db: db, $table: table), $$PlayerGroupTableTableAnnotationComposer($db: db, $table: table),
updateCompanionCallback: updateCompanionCallback:
({ ({
Value<String> userId = const Value.absent(), Value<String> playerId = const Value.absent(),
Value<String> groupId = const Value.absent(), Value<String> groupId = const Value.absent(),
Value<int> rowid = const Value.absent(), Value<int> rowid = const Value.absent(),
}) => PlayerGroupTableCompanion( }) => PlayerGroupTableCompanion(
userId: userId, playerId: playerId,
groupId: groupId, groupId: groupId,
rowid: rowid, rowid: rowid,
), ),
createCompanionCallback: createCompanionCallback:
({ ({
required String userId, required String playerId,
required String groupId, required String groupId,
Value<int> rowid = const Value.absent(), Value<int> rowid = const Value.absent(),
}) => PlayerGroupTableCompanion.insert( }) => PlayerGroupTableCompanion.insert(
userId: userId, playerId: playerId,
groupId: groupId, groupId: groupId,
rowid: rowid, rowid: rowid,
), ),
@@ -1645,7 +1647,7 @@ class $$PlayerGroupTableTableTableManager
), ),
) )
.toList(), .toList(),
prefetchHooksCallback: ({userId = false, groupId = false}) { prefetchHooksCallback: ({playerId = false, groupId = false}) {
return PrefetchHooks( return PrefetchHooks(
db: db, db: db,
explicitlyWatchedTables: [], explicitlyWatchedTables: [],
@@ -1665,17 +1667,17 @@ class $$PlayerGroupTableTableTableManager
dynamic dynamic
> >
>(state) { >(state) {
if (userId) { if (playerId) {
state = state =
state.withJoin( state.withJoin(
currentTable: table, currentTable: table,
currentColumn: table.userId, currentColumn: table.playerId,
referencedTable: referencedTable:
$$PlayerGroupTableTableReferences $$PlayerGroupTableTableReferences
._userIdTable(db), ._playerIdTable(db),
referencedColumn: referencedColumn:
$$PlayerGroupTableTableReferences $$PlayerGroupTableTableReferences
._userIdTable(db) ._playerIdTable(db)
.id, .id,
) )
as T; as T;
@@ -1719,7 +1721,7 @@ typedef $$PlayerGroupTableTableProcessedTableManager =
$$PlayerGroupTableTableUpdateCompanionBuilder, $$PlayerGroupTableTableUpdateCompanionBuilder,
(PlayerGroupTableData, $$PlayerGroupTableTableReferences), (PlayerGroupTableData, $$PlayerGroupTableTableReferences),
PlayerGroupTableData, PlayerGroupTableData,
PrefetchHooks Function({bool userId, bool groupId}) PrefetchHooks Function({bool playerId, bool groupId})
>; >;
typedef $$GameTableTableCreateCompanionBuilder = typedef $$GameTableTableCreateCompanionBuilder =
GameTableCompanion Function({ GameTableCompanion Function({

View File

@@ -3,9 +3,9 @@ import 'package:game_tracker/data/db/tables/group_table.dart';
import 'package:game_tracker/data/db/tables/player_table.dart'; import 'package:game_tracker/data/db/tables/player_table.dart';
class PlayerGroupTable extends Table { 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)(); TextColumn get groupId => text().references(GroupTable, #id)();
@override @override
Set<Column<Object>> get primaryKey => {userId, groupId}; Set<Column<Object>> get primaryKey => {playerId, groupId};
} }