mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
fix: folder name sorting
This commit is contained in:
@@ -419,13 +419,18 @@ export const secretFolderDALFactory = (db: TDbClient) => {
|
|||||||
.select(
|
.select(
|
||||||
selectAllTableCols(TableName.SecretFolder),
|
selectAllTableCols(TableName.SecretFolder),
|
||||||
db.raw(
|
db.raw(
|
||||||
`DENSE_RANK() OVER (ORDER BY ${TableName.SecretFolder}."name" ${
|
`DENSE_RANK() OVER (ORDER BY CASE WHEN ${TableName.SecretFolder}."name" LIKE '\\_%' THEN ${orderDirection === OrderByDirection.ASC ? "0" : "1"} ELSE ${orderDirection === OrderByDirection.ASC ? "1" : "0"} END,
|
||||||
orderDirection ?? OrderByDirection.ASC
|
LOWER(${TableName.SecretFolder}."name") ${orderDirection},
|
||||||
}) as rank`
|
${TableName.SecretFolder}."name" ${orderDirection}
|
||||||
|
) as rank`
|
||||||
),
|
),
|
||||||
db.ref("slug").withSchema(TableName.Environment).as("environment")
|
db.ref("slug").withSchema(TableName.Environment).as("environment")
|
||||||
)
|
)
|
||||||
.orderBy(`${TableName.SecretFolder}.${orderBy}`, orderDirection);
|
.orderByRaw(
|
||||||
|
`CASE WHEN ${TableName.SecretFolder}.${orderBy} LIKE '\\_%' THEN ${orderDirection === OrderByDirection.ASC ? "0" : "1"} ELSE ${orderDirection === OrderByDirection.ASC ? "1" : "0"} END`
|
||||||
|
)
|
||||||
|
.orderByRaw(`LOWER(${TableName.SecretFolder}.${orderBy}) ${orderDirection}`)
|
||||||
|
.orderByRaw(`${TableName.SecretFolder}.${orderBy} ${orderDirection}`);
|
||||||
|
|
||||||
if (limit) {
|
if (limit) {
|
||||||
const rankOffset = offset + 1; // ranks start from 1
|
const rankOffset = offset + 1; // ranks start from 1
|
||||||
@@ -434,7 +439,12 @@ export const secretFolderDALFactory = (db: TDbClient) => {
|
|||||||
.select("*")
|
.select("*")
|
||||||
.from<Awaited<typeof query>[number]>("w")
|
.from<Awaited<typeof query>[number]>("w")
|
||||||
.where("w.rank", ">=", rankOffset)
|
.where("w.rank", ">=", rankOffset)
|
||||||
.andWhere("w.rank", "<", rankOffset + limit);
|
.andWhere("w.rank", "<", rankOffset + limit)
|
||||||
|
.orderByRaw(
|
||||||
|
`CASE WHEN "w"."${orderBy}" LIKE '\\_%' THEN ${orderDirection === OrderByDirection.ASC ? "0" : "1"} ELSE ${orderDirection === OrderByDirection.ASC ? "1" : "0"} END`
|
||||||
|
)
|
||||||
|
.orderByRaw(`LOWER("w"."${orderBy}") ${orderDirection}`)
|
||||||
|
.orderByRaw(`"w"."${orderBy}" ${orderDirection}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const folders = await query;
|
const folders = await query;
|
||||||
|
|||||||
Reference in New Issue
Block a user