Refactor deprecated Kysely orderBy calls

This commit is contained in:
Kalle 2025-04-21 09:41:43 +03:00
parent 7295f3b8a6
commit f6a5643544
11 changed files with 26 additions and 25 deletions

View File

@ -73,7 +73,7 @@ export const loader = async ({ params, request }: LoaderFunctionArgs) => {
).as("participants"), ).as("participants"),
]) ])
.where("TournamentMatchGameResult.matchId", "=", id) .where("TournamentMatchGameResult.matchId", "=", id)
.orderBy("TournamentMatchGameResult.number asc"), .orderBy("TournamentMatchGameResult.number", "asc"),
).as("playedMapList"), ).as("playedMapList"),
]) ])
.where("TournamentMatch.id", "=", id) .where("TournamentMatch.id", "=", id)

View File

@ -96,7 +96,7 @@ export const loader = async ({ params, request }: LoaderFunctionArgs) => {
"=", "=",
"TournamentTeam.id", "TournamentTeam.id",
) )
.orderBy("TournamentTeamMember.createdAt asc"), .orderBy("TournamentTeamMember.createdAt", "asc"),
).as("members"), ).as("members"),
jsonArrayFrom( jsonArrayFrom(
eb eb
@ -106,7 +106,7 @@ export const loader = async ({ params, request }: LoaderFunctionArgs) => {
).as("mapPool"), ).as("mapPool"),
]) ])
.where("TournamentTeam.tournamentId", "=", id) .where("TournamentTeam.tournamentId", "=", id)
.orderBy("TournamentTeam.createdAt asc") .orderBy("TournamentTeam.createdAt", "asc")
.execute(); .execute();
const friendCodes = await TournamentRepository.friendCodesByTournamentId(id); const friendCodes = await TournamentRepository.friendCodesByTournamentId(id);

View File

@ -43,7 +43,7 @@ export const loader = async ({ params, request }: LoaderFunctionArgs) => {
.selectFrom("UserWeapon") .selectFrom("UserWeapon")
.select(["UserWeapon.isFavorite", "UserWeapon.weaponSplId"]) .select(["UserWeapon.isFavorite", "UserWeapon.weaponSplId"])
.whereRef("UserWeapon.userId", "=", "User.id") .whereRef("UserWeapon.userId", "=", "User.id")
.orderBy("UserWeapon.order asc"), .orderBy("UserWeapon.order", "asc"),
).as("weapons"), ).as("weapons"),
jsonArrayFrom( jsonArrayFrom(
eb eb

View File

@ -83,7 +83,7 @@ export function findByManagersList(userIds: number[]) {
.select(["Badge.id", "Badge.code", "Badge.displayName", "Badge.hue"]) .select(["Badge.id", "Badge.code", "Badge.displayName", "Badge.hue"])
.innerJoin("BadgeManager", "Badge.id", "BadgeManager.badgeId") .innerJoin("BadgeManager", "Badge.id", "BadgeManager.badgeId")
.where("BadgeManager.userId", "in", userIds) .where("BadgeManager.userId", "in", userIds)
.orderBy("Badge.id asc") .orderBy("Badge.id", "asc")
.groupBy("Badge.id") .groupBy("Badge.id")
.execute(); .execute();
} }

View File

@ -266,7 +266,7 @@ export async function findRecentTournamentsByAuthorId(authorId: number) {
"CalendarEventDate.startTime", "CalendarEventDate.startTime",
]) ])
.where("CalendarEvent.authorId", "=", authorId) .where("CalendarEvent.authorId", "=", authorId)
.orderBy("CalendarEvent.id desc") .orderBy("CalendarEvent.id", "desc")
.limit(10) .limit(10)
.execute(); .execute();
} }

View File

@ -34,7 +34,7 @@ export async function posts(user?: { id: number; plusTier: number | null }) {
innerEb innerEb
.selectFrom("UserWeapon") .selectFrom("UserWeapon")
.whereRef("UserWeapon.userId", "=", "User.id") .whereRef("UserWeapon.userId", "=", "User.id")
.orderBy("UserWeapon.order asc") .orderBy("UserWeapon.order", "asc")
.select(["UserWeapon.weaponSplId", "UserWeapon.isFavorite"]), .select(["UserWeapon.weaponSplId", "UserWeapon.isFavorite"]),
).as("weaponPool"), ).as("weaponPool"),
]) ])
@ -66,7 +66,7 @@ export async function posts(user?: { id: number; plusTier: number | null }) {
innestEb innestEb
.selectFrom("UserWeapon") .selectFrom("UserWeapon")
.whereRef("UserWeapon.userId", "=", "User.id") .whereRef("UserWeapon.userId", "=", "User.id")
.orderBy("UserWeapon.order asc") .orderBy("UserWeapon.order", "asc")
.select([ .select([
"UserWeapon.weaponSplId", "UserWeapon.weaponSplId",
"UserWeapon.isFavorite", "UserWeapon.isFavorite",
@ -80,7 +80,7 @@ export async function posts(user?: { id: number; plusTier: number | null }) {
).as("team"), ).as("team"),
]) ])
.orderBy(sql`LFGPost.authorId = ${sql`${userId}`} desc`) .orderBy(sql`LFGPost.authorId = ${sql`${userId}`} desc`)
.orderBy("LFGPost.updatedAt desc") .orderBy("LFGPost.updatedAt", "desc")
.where((eb) => .where((eb) =>
eb.or([ eb.or([
eb( eb(

View File

@ -32,7 +32,7 @@ export function findById(id: number) {
"GroupMatchMap.winnerGroupId", "GroupMatchMap.winnerGroupId",
]) ])
.where("GroupMatchMap.matchId", "=", id) .where("GroupMatchMap.matchId", "=", id)
.orderBy("GroupMatchMap.index asc"), .orderBy("GroupMatchMap.index", "asc"),
).as("mapList"), ).as("mapList"),
]) ])
.where("GroupMatch.id", "=", id) .where("GroupMatch.id", "=", id)
@ -121,7 +121,7 @@ export async function findGroupById({
.selectFrom("UserFriendCode") .selectFrom("UserFriendCode")
.select("UserFriendCode.friendCode") .select("UserFriendCode.friendCode")
.whereRef("UserFriendCode.userId", "=", "User.id") .whereRef("UserFriendCode.userId", "=", "User.id")
.orderBy("UserFriendCode.createdAt desc") .orderBy("UserFriendCode.createdAt", "desc")
.limit(1) .limit(1)
.as("friendCode"), .as("friendCode"),
jsonObjectFrom( jsonObjectFrom(
@ -138,7 +138,7 @@ export async function findGroupById({
userChatNameColor, userChatNameColor,
]) ])
.where("GroupMember.groupId", "=", groupId) .where("GroupMember.groupId", "=", groupId)
.orderBy("GroupMember.userId asc"), .orderBy("GroupMember.userId", "asc"),
).as("members"), ).as("members"),
]) ])
.where("Group.id", "=", groupId) .where("Group.id", "=", groupId)

View File

@ -114,7 +114,7 @@ export function findByOrganizerUserId(userId: number) {
"ORGANIZER", "ORGANIZER",
), ),
) )
.orderBy("TournamentOrganization.id asc") .orderBy("TournamentOrganization.id", "asc")
.execute(); .execute();
} }
@ -170,7 +170,7 @@ const findEventsBaseQuery = (organizationId: number) =>
"=", "=",
"TournamentTeam.id", "TournamentTeam.id",
) )
.orderBy("User.id asc"), .orderBy("User.id", "asc"),
).as("members"), ).as("members"),
]) ])
.whereRef( .whereRef(
@ -200,7 +200,7 @@ const findEventsBaseQuery = (organizationId: number) =>
"=", "=",
"CalendarEventResultTeam.id", "CalendarEventResultTeam.id",
) )
.orderBy("User.id asc"), .orderBy("User.id", "asc"),
).as("members"), ).as("members"),
]) ])
.whereRef("CalendarEventResultTeam.eventId", "=", "CalendarEvent.id") .whereRef("CalendarEventResultTeam.eventId", "=", "CalendarEvent.id")
@ -252,7 +252,7 @@ export async function findEventsByMonth({
"<=", "<=",
dateToDatabaseTimestamp(lastDayOfTheMonth), dateToDatabaseTimestamp(lastDayOfTheMonth),
) )
.orderBy("CalendarEventDate.startTime asc") .orderBy("CalendarEventDate.startTime", "asc")
.execute(); .execute();
return events.map(mapEvent); return events.map(mapEvent);
@ -273,7 +273,7 @@ const findSeriesEventsBaseQuery = ({
), ),
), ),
) )
.orderBy("CalendarEventDate.startTime desc"); .orderBy("CalendarEventDate.startTime", "desc");
export async function findPaginatedEventsBySeries({ export async function findPaginatedEventsBySeries({
organizationId, organizationId,

View File

@ -208,7 +208,7 @@ export async function findById(id: number) {
"=", "=",
"TournamentTeam.id", "TournamentTeam.id",
) )
.orderBy("TournamentTeamMember.createdAt asc"), .orderBy("TournamentTeamMember.createdAt", "asc"),
).as("members"), ).as("members"),
jsonArrayFrom( jsonArrayFrom(
innerEb innerEb
@ -252,7 +252,8 @@ export async function findById(id: number) {
).as("team"), ).as("team"),
]) ])
.where("TournamentTeam.tournamentId", "=", id) .where("TournamentTeam.tournamentId", "=", id)
.orderBy(["TournamentTeam.seed asc", "TournamentTeam.createdAt asc"]), .orderBy("TournamentTeam.seed", "asc")
.orderBy("TournamentTeam.createdAt", "asc"),
).as("teams"), ).as("teams"),
jsonArrayFrom( jsonArrayFrom(
eb eb
@ -523,7 +524,7 @@ export function forShowcase() {
).as("firstPlacers"), ).as("firstPlacers"),
]) ])
.where("CalendarEventDate.startTime", ">", databaseTimestampWeekAgo()) .where("CalendarEventDate.startTime", ">", databaseTimestampWeekAgo())
.orderBy("CalendarEventDate.startTime asc") .orderBy("CalendarEventDate.startTime", "asc")
.$narrowType<{ teamsCount: NotNull }>() .$narrowType<{ teamsCount: NotNull }>()
.execute(); .execute();
} }
@ -603,7 +604,7 @@ export async function friendCodesByTournamentId(tournamentId: number) {
"UserFriendCode.userId", "UserFriendCode.userId",
) )
.select(["TournamentTeamMember.userId", "UserFriendCode.friendCode"]) .select(["TournamentTeamMember.userId", "UserFriendCode.friendCode"])
.orderBy("UserFriendCode.createdAt asc") .orderBy("UserFriendCode.createdAt", "asc")
.where("TournamentTeam.tournamentId", "=", tournamentId) .where("TournamentTeam.tournamentId", "=", tournamentId)
.execute(); .execute();
@ -1030,7 +1031,7 @@ export function pickBanEventsByMatchId(matchId: number) {
"TournamentMatchPickBanEvent.number", "TournamentMatchPickBanEvent.number",
]) ])
.where("matchId", "=", matchId) .where("matchId", "=", matchId)
.orderBy("TournamentMatchPickBanEvent.number asc") .orderBy("TournamentMatchPickBanEvent.number", "asc")
.execute(); .execute();
} }

View File

@ -580,7 +580,7 @@ export async function currentFriendCodeByUserId(userId: number) {
"UserFriendCode.submitterUserId", "UserFriendCode.submitterUserId",
]) ])
.where("userId", "=", userId) .where("userId", "=", userId)
.orderBy("UserFriendCode.createdAt desc") .orderBy("UserFriendCode.createdAt", "desc")
.limit(1) .limit(1)
.executeTakeFirst(); .executeTakeFirst();
} }
@ -595,7 +595,7 @@ export async function allCurrentFriendCodes() {
const allFriendCodes = await db const allFriendCodes = await db
.selectFrom("UserFriendCode") .selectFrom("UserFriendCode")
.select(["UserFriendCode.friendCode", "UserFriendCode.userId"]) .select(["UserFriendCode.friendCode", "UserFriendCode.userId"])
.orderBy("UserFriendCode.createdAt desc") .orderBy("UserFriendCode.createdAt", "desc")
.execute(); .execute();
const seenUserIds = new Set<number>(); const seenUserIds = new Set<number>();

View File

@ -11,7 +11,7 @@ async function main() {
"UserWeapon.userId", "UserWeapon.userId",
]) ])
.where("UserWeapon.order", "!=", 5) .where("UserWeapon.order", "!=", 5)
.orderBy("UserWeapon.order asc") .orderBy("UserWeapon.order", "asc")
.execute(); .execute();
// group by userId // group by userId