public async Task <IEnumerable <BakingRight> > Get(
            BakingRightTypeParameter type,
            AccountParameter baker,
            Int32Parameter cycle,
            Int32Parameter level,
            Int32NullParameter slots,
            Int32NullParameter priority,
            BakingRightStatusParameter status,
            SortParameter sort,
            OffsetParameter offset,
            int limit)
        {
            var sql = new SqlBuilder(@"SELECT * FROM ""BakingRights""")
                      .Filter("Cycle", cycle)
                      .Filter("Level", level)
                      .Filter("BakerId", baker)
                      .Filter("Type", type)
                      .Filter("Status", status)
                      .Filter("Priority", priority)
                      .Filter("Slots", slots)
                      .Take(sort ?? new SortParameter {
                Asc = "level"
            }, offset, limit, x => ("Level", "Level"));

            using var db = GetConnection();
            var rows = await db.QueryAsync(sql.Query, sql.Params);

            return(rows.Select(row => new BakingRight
            {
                Type = BakingRightTypes.ToString(row.Type),
                Cycle = row.Cycle,
                Level = row.Level,
                Timestamp = Time[row.Level],
                Baker = Accounts.GetAlias(row.BakerId),
                Priority = row.Priority,
                Slots = row.Slots,
                Status = BakingRightStatuses.ToString(row.Status)
            }));
        }
        public async Task <object[][]> Get(
            BakingRightTypeParameter type,
            AccountParameter baker,
            Int32Parameter cycle,
            Int32Parameter level,
            Int32NullParameter slots,
            Int32NullParameter priority,
            BakingRightStatusParameter status,
            SortParameter sort,
            OffsetParameter offset,
            int limit,
            string[] fields)
        {
            var columns = new HashSet <string>(fields.Length);

            foreach (var field in fields)
            {
                switch (field)
                {
                case "type": columns.Add(@"""Type"""); break;

                case "cycle": columns.Add(@"""Cycle"""); break;

                case "level": columns.Add(@"""Level"""); break;

                case "timestamp": columns.Add(@"""Level"""); columns.Add(@"""Status"""); break;

                case "baker": columns.Add(@"""BakerId"""); break;

                case "priority": columns.Add(@"""Priority"""); break;

                case "slots": columns.Add(@"""Slots"""); break;

                case "status": columns.Add(@"""Status"""); break;
                }
            }

            if (columns.Count == 0)
            {
                return(Array.Empty <object[]>());
            }

            var sql = new SqlBuilder($@"SELECT {string.Join(',', columns)} FROM ""BakingRights""")
                      .Filter("Cycle", cycle)
                      .Filter("Level", level)
                      .Filter("BakerId", baker)
                      .Filter("Type", type)
                      .Filter("Status", status)
                      .Filter("Priority", priority)
                      .Filter("Slots", slots)
                      .Take(sort ?? new SortParameter {
                Asc = "level"
            }, offset, limit, x => ("Level", "Level"));

            using var db = GetConnection();
            var rows = await db.QueryAsync(sql.Query, sql.Params);

            var result = new object[rows.Count()][];

            for (int i = 0; i < result.Length; i++)
            {
                result[i] = new object[fields.Length];
            }

            for (int i = 0, j = 0; i < fields.Length; j = 0, i++)
            {
                switch (fields[i])
                {
                case "type":
                    foreach (var row in rows)
                    {
                        result[j++][i] = BakingRightTypes.ToString(row.Type);
                    }
                    break;

                case "cycle":
                    foreach (var row in rows)
                    {
                        result[j++][i] = row.Cycle;
                    }
                    break;

                case "level":
                    foreach (var row in rows)
                    {
                        result[j++][i] = row.Level;
                    }
                    break;

                case "timestamp":
                    foreach (var row in rows)
                    {
                        result[j++][i] = Time[row.Level];
                    }
                    break;

                case "baker":
                    foreach (var row in rows)
                    {
                        result[j++][i] = await Accounts.GetAliasAsync(row.BakerId);
                    }
                    break;

                case "priority":
                    foreach (var row in rows)
                    {
                        result[j++][i] = row.Priority;
                    }
                    break;

                case "slots":
                    foreach (var row in rows)
                    {
                        result[j++][i] = row.Slots;
                    }
                    break;

                case "status":
                    foreach (var row in rows)
                    {
                        result[j++][i] = BakingRightStatuses.ToString(row.Status);
                    }
                    break;
                }
            }

            return(result);
        }