public async Task <List <Player> > GetAllAsync() { Logger.LogDebug($"Getting all players from '{MetadataResolver.TableName<PlayerSql>()}' table."); List <PlayerSql> sqlEntries = await DbConnection.Select <PlayerSql>().ExecuteAsync(); return(sqlEntries.Select(PlayerSql.ToCoreEntity).ToList()); }
public async Task <List <TeamWeekStats> > GetAsync(WeekInfo week) { Logger.LogDebug($"Getting team stats for '{week}' from '{MetadataResolver.TableName<TeamGameStatsSql>()}' table."); List <TeamGameStatsSql> sqlEntries = await DbConnection.Select <TeamGameStatsSql>() .Where(s => s.Season == week.Season && s.Week == week.Week) .ExecuteAsync(); return(sqlEntries.Select(TeamGameStatsSql.ToCoreEntity).ToList()); }
public async Task <List <WeekMatchup> > GetAsync(WeekInfo week) { Logger.LogDebug($"Retrieving week matchups for week '{week}' from '{MetadataResolver.TableName<WeekGameMatchupSql>()}' table."); List <WeekGameMatchupSql> matchups = await DbConnection.Select <WeekGameMatchupSql>() .Where(m => m.Season == week.Season && m.Week == week.Week) .ExecuteAsync(); return(matchups.Select(WeekGameMatchupSql.ToCoreEntity).ToList()); }
private void AppendSelectFrom(List <Expression <Func <TEntity, object> > > propertySelections) { propertySelections?.ForEach(PropertySelectionResolver.ValidatePropertyExpression); var table = MetadataResolver.TableName <TEntity>(); var selections = PropertySelectionResolver.GetSelectionsFromProperties(propertySelections); string selectFrom = $"SELECT {selections} FROM {table}"; _sqlBuilder.Append(selectFrom); }
public Task AddAsync(PlayerAdd player) { if (player == null) { throw new ArgumentNullException(nameof(player), "Player add must be provided."); } Logger.LogDebug($"Adding player '{player}' to '{MetadataResolver.TableName<PlayerSql>()}' table."); PlayerSql sqlEntry = PlayerSql.FromCoreAddEntity(player); return(DbConnection.Insert(sqlEntry).ExecuteAsync()); }
public Task AddAsync(List <WeekMatchup> matchups) { if (matchups == null) { throw new ArgumentNullException(nameof(matchups), "Week matchups must be provided."); } Logger.LogDebug($"Adding {matchups.Count} week matchups to '{MetadataResolver.TableName<WeekGameMatchupSql>()}' table."); var sqlEntries = matchups.Select(WeekGameMatchupSql.FromCoreEntity).ToList(); return(DbConnection.InsertMany(sqlEntries).ExecuteAsync()); }
public TableExistsQuery(Func <NpgsqlConnection> getConnection) { _getConnection = getConnection ?? throw new ArgumentNullException(nameof(getConnection)); var fullTableIdentifier = MetadataResolver.TableName <TEntity>(); var split = fullTableIdentifier.Split('.'); var schema = split[0]; var tableName = split[1]; var innerQuery = "SELECT 1 FROM pg_tables " + $"WHERE schemaname = '{schema}' AND tablename = '{tableName}'"; _sqlBuilder.Append($"SELECT EXISTS({innerQuery})"); }
public async Task AddAsync(List <Team> teams) { if (teams == null) { throw new ArgumentNullException(nameof(teams), "Teams must be provided."); } if (!teams.Any()) { return; } var sqlEntries = teams.Select(TeamSql.FromCoreEntity).ToList(); Logger.LogDebug($"Adding {sqlEntries.Count} teams to '{MetadataResolver.TableName<TeamSql>()}' table."); await DbConnection.InsertMany(sqlEntries).ExecuteAsync(); }
public Task UpdateAsync(Guid id, PlayerUpdate update) { if (id == Guid.Empty) { throw new ArgumentException("Player id must be provided.", nameof(id)); } if (update == null) { throw new ArgumentNullException(nameof(update), "Update must be provided."); } Logger.LogDebug($"Updating player '{id}' in '{MetadataResolver.TableName<PlayerSql>()}' table."); return(DbConnection.Update <PlayerSql>() .Where(p => p.Id == id) .Set(p => p.Number, update.Number) .Set(p => p.Position, update.Position) .Set(p => p.Status, update.Status) .ExecuteAsync()); }
public async Task UpdateRosterMappingsAsync(List <Roster> rosters) { if (rosters == null) { throw new ArgumentNullException(nameof(rosters), "Rosters must be provided."); } Logger.LogDebug($"Updating roster mappings for players in '{MetadataResolver.TableName<PlayerTeamMapSql>()}'."); await DbConnection.Truncate <PlayerTeamMapSql>().ExecuteAsync(); List <PlayerSql> players = await DbConnection.Select <PlayerSql>(p => p.Id, p => p.NflId).ExecuteAsync(); Dictionary <string, Guid> nflIdMap = players.ToDictionary(p => p.NflId, p => p.Id); foreach (Roster roster in rosters) { await UpdateForRosterAsync(roster, nflIdMap); } }