Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion plugins/database-webui/client/edit-dialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ function parseValue(): ParseResult {
}
case 'bigint': {
try {
return { ok: true, value: BigInt(raw) as any }
const value = raw.trim()
BigInt(value)
return { ok: true, value }
} catch {
return { ok: false, error: '不是合法整数' }
}
Expand Down
14 changes: 13 additions & 1 deletion plugins/database-webui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ export const Config: z<Config> = z.object({
pageSize: z.natural().default(50).description('每页默认行数(客户端可改)。'),
})

function serializeValue(value: unknown): unknown {
if (typeof value === 'bigint') return value.toString()
if (Array.isArray(value)) return value.map(serializeValue)
if (value instanceof Date) return value
if (value && typeof value === 'object') {
return Object.fromEntries(
Object.entries(value).map(([key, item]) => [key, serializeValue(item)]),
)
}
return value
}

function describeFields(model: any): FieldInfo[] {
const primary = new Set<string>(([] as string[]).concat(model.primary ?? []))
const uniqueKeys = new Set<string>()
Expand Down Expand Up @@ -111,7 +123,7 @@ export function apply(ctx: Context, config: Config) {
const rows = await (model.get as any)(table, {}, cursor)
const stats = await model.stats().catch(() => ({ tables: {} as Record<string, { count: number; size: number }> }))
const total = stats.tables?.[table]?.count ?? rows.length
return { rows, total }
return { rows: rows.map(serializeValue), total }
},
async update({ table, where, field, value }) {
const model = ctx.model
Expand Down