mirror of
https://github.com/kunkunsh/kunkun.git
synced 2025-04-20 05:29:17 +00:00
Refactor ORM commands and searchExtensionData function for improved readability and consistency
- Reformatted import statements for better organization. - Cleaned up whitespace and indentation in searchExtensionData function. - Enhanced readability of SQL conditions and query building logic. - Disabled eslint for explicit any usage in the troubleshooters page.
This commit is contained in:
parent
288c9b554a
commit
5d5cbcdeb7
@ -1,6 +1,15 @@
|
|||||||
import * as relations from "@kksh/drizzle/relations"
|
import * as relations from "@kksh/drizzle/relations"
|
||||||
import * as schema from "@kksh/drizzle/schema"
|
import * as schema from "@kksh/drizzle/schema"
|
||||||
import { CmdType, Ext, ExtCmd, ExtData, SearchMode, SearchModeEnum, SQLSortOrder, SQLSortOrderEnum } from "@kunkunapi/src/models"
|
import {
|
||||||
|
CmdType,
|
||||||
|
Ext,
|
||||||
|
ExtCmd,
|
||||||
|
ExtData,
|
||||||
|
SearchMode,
|
||||||
|
SearchModeEnum,
|
||||||
|
SQLSortOrder,
|
||||||
|
SQLSortOrderEnum
|
||||||
|
} from "@kunkunapi/src/models"
|
||||||
import * as orm from "drizzle-orm"
|
import * as orm from "drizzle-orm"
|
||||||
import type { SelectedFields } from "drizzle-orm/sqlite-core"
|
import type { SelectedFields } from "drizzle-orm/sqlite-core"
|
||||||
import * as v from "valibot"
|
import * as v from "valibot"
|
||||||
@ -292,7 +301,9 @@ export async function searchExtensionData(searchParams: {
|
|||||||
conditions.push(orm.like(schema.extensionData.searchText, `%${searchParams.searchText}%`))
|
conditions.push(orm.like(schema.extensionData.searchText, `%${searchParams.searchText}%`))
|
||||||
break
|
break
|
||||||
case SearchModeEnum.FTS:
|
case SearchModeEnum.FTS:
|
||||||
conditions.push(orm.sql`${schema.extensionDataFts.searchText} MATCH ${searchParams.searchText}`)
|
conditions.push(
|
||||||
|
orm.sql`${schema.extensionDataFts.searchText} MATCH ${searchParams.searchText}`
|
||||||
|
)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -314,20 +325,22 @@ export async function searchExtensionData(searchParams: {
|
|||||||
? orm.asc(schema.extensionData.createdAt)
|
? orm.asc(schema.extensionData.createdAt)
|
||||||
: orm.desc(schema.extensionData.createdAt)
|
: orm.desc(schema.extensionData.createdAt)
|
||||||
: searchParams.orderByUpdatedAt
|
: searchParams.orderByUpdatedAt
|
||||||
? searchParams.orderByUpdatedAt === SQLSortOrderEnum.Asc
|
? searchParams.orderByUpdatedAt === SQLSortOrderEnum.Asc
|
||||||
? orm.asc(schema.extensionData.updatedAt)
|
? orm.asc(schema.extensionData.updatedAt)
|
||||||
: orm.desc(schema.extensionData.updatedAt)
|
: orm.desc(schema.extensionData.updatedAt)
|
||||||
: orm.asc(schema.extensionData.createdAt) // Default ordering
|
: orm.asc(schema.extensionData.createdAt) // Default ordering
|
||||||
)
|
)
|
||||||
.limit(searchParams.limit ?? 100) // Default limit
|
.limit(searchParams.limit ?? 100) // Default limit
|
||||||
.offset(searchParams.offset ?? 0) // Default offset
|
.offset(searchParams.offset ?? 0) // Default offset
|
||||||
|
|
||||||
// Execute query and convert results
|
// Execute query and convert results
|
||||||
const results = await query.all()
|
const results = await query.all()
|
||||||
return results.map((rawData) => {
|
return results
|
||||||
// @ts-expect-error - rawData is unknown, but will be safe parsed with valibot
|
.map((rawData) => {
|
||||||
return convertRawExtDataToExtData(rawData)
|
// @ts-expect-error - rawData is unknown, but will be safe parsed with valibot
|
||||||
}).filter((item): item is ExtData => item !== undefined)
|
return convertRawExtDataToExtData(rawData)
|
||||||
|
})
|
||||||
|
.filter((item): item is ExtData => item !== undefined)
|
||||||
}
|
}
|
||||||
|
|
||||||
// export async function getNCommands(n: number):
|
// export async function getNCommands(n: number):
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
import * as v from "valibot"
|
import * as v from "valibot"
|
||||||
|
|
||||||
let searchText = $state("")
|
let searchText = $state("")
|
||||||
|
/* eslint-disable */
|
||||||
let data: any = $state(null)
|
let data: any = $state(null)
|
||||||
let inspectTitle = $state("")
|
let inspectTitle = $state("")
|
||||||
</script>
|
</script>
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
import { relations } from "drizzle-orm/relations";
|
import { relations } from "drizzle-orm/relations"
|
||||||
import { extensions, commands, extensionData } from "./schema";
|
import { commands, extensionData, extensions } from "./schema"
|
||||||
|
|
||||||
export const commandsRelations = relations(commands, ({one}) => ({
|
export const commandsRelations = relations(commands, ({ one }) => ({
|
||||||
extension: one(extensions, {
|
extension: one(extensions, {
|
||||||
fields: [commands.extId],
|
fields: [commands.extId],
|
||||||
references: [extensions.extId]
|
references: [extensions.extId]
|
||||||
}),
|
})
|
||||||
}));
|
}))
|
||||||
|
|
||||||
export const extensionsRelations = relations(extensions, ({many}) => ({
|
export const extensionsRelations = relations(extensions, ({ many }) => ({
|
||||||
commands: many(commands),
|
commands: many(commands),
|
||||||
extensionData: many(extensionData),
|
extensionData: many(extensionData)
|
||||||
}));
|
}))
|
||||||
|
|
||||||
export const extensionDataRelations = relations(extensionData, ({one}) => ({
|
export const extensionDataRelations = relations(extensionData, ({ one }) => ({
|
||||||
extension: one(extensions, {
|
extension: one(extensions, {
|
||||||
fields: [extensionData.extId],
|
fields: [extensionData.extId],
|
||||||
references: [extensions.extId]
|
references: [extensions.extId]
|
||||||
}),
|
})
|
||||||
}));
|
}))
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
## Permission Table
|
## Permission Table
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
@ -7,7 +6,6 @@
|
|||||||
<th>Description</th>
|
<th>Description</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user