Example #1
0
        public async Task <Battle?> GetNextBattle()
        {
            DbCommand PrepareQuery(IDatabase database)
            {
                var cmd = _db.CreateCommand();

                cmd.CommandText = "SELECT * FROM FleetsBattleQueue ORDER BY ROWID LIMIT 1;";
                return(cmd);
            }

            var enumerable = new SqlAsyncResult <Battle?>(_db, PrepareQuery, a => Battle.Parse(a));

            return(await enumerable.SingleOrDefaultAsync());
        }
        public async Task <byte[]?> LoadBlob(ulong id)
        {
            DbCommand PrepareQuery(IDatabase database)
            {
                var cmd = _db.CreateCommand();

                cmd.CommandText = "SELECT Blob FROM Fleets WHERE FleetId = @FleetId;";
                cmd.Parameters.Add(new SqliteParameter("@FleetId", DbType.UInt64)
                {
                    Value = id
                });
                return(cmd);
            }

            var enumerable = new SqlAsyncResult <byte[]?>(_db, PrepareQuery, a => (byte[])a["Blob"]);

            return(await enumerable.SingleOrDefaultAsync());
        }
        public async Task <FleetTrueskillRating?> GetRank(ulong id)
        {
            DbCommand PrepareQuery(IDatabase database)
            {
                var cmd = _db.CreateCommand();

                cmd.CommandText = "SELECT Fleets.FleetId, Mean, StdDev, UserId, Name FROM FleetsRanks INNER JOIN Fleets ON Fleets.FleetId=FleetsRanks.FleetId WHERE Fleets.FleetId = @FleetId;";
                cmd.Parameters.Add(new SqliteParameter("@FleetId", DbType.UInt64)
                {
                    Value = id
                });
                return(cmd);
            }

            var enumerable = new SqlAsyncResult <FleetTrueskillRating?>(_db, PrepareQuery, a => FleetTrueskillRating.Read(a));

            return(await enumerable.SingleOrDefaultAsync());
        }