예제 #1
0
        public IAsyncEnumerable <GameUpdateView> GetGameUpdates(GameUpdateQueryOptions opts, bool ignoreSort = false)
        {
            var q = new SqlKata.Query("game_updates_unique")
                    .Select("game_id", "timestamp", "hash", "data")
                    .ApplyBounds(opts, "timestamp");

            if (!ignoreSort)
            {
                q.ApplySorting(opts, "timestamp", "hash");
            }

            if (opts.Season != null)
            {
                q.Where("season", opts.Season.Value);
            }
            if (opts.Tournament != null)
            {
                q.Where("tournament", opts.Tournament.Value);
            }
            if (opts.Day != null)
            {
                q.Where("day", opts.Day.Value);
            }
            if (opts.Game != null)
            {
                q.WhereIn("game_id", opts.Game);
            }
            if (opts.Search != null)
            {
                q.WhereRaw("search_tsv @@ websearch_to_tsquery(?)", opts.Search);
            }
            if (opts.Started != null)
            {
                q.WhereRaw("(data->>'gameStart')::bool = ?", opts.Started.Value);
            }

            return(_db.QueryKataAsync <GameUpdateView>(q));
        }