mirror of
https://github.com/Nezumi-2711/Sink.git
synced 2026-09-22 20:00:55 +00:00
feat: init
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import type { H3Event } from 'h3'
|
||||
import { z } from 'zod'
|
||||
import { QuerySchema } from '@/schemas/query'
|
||||
|
||||
const { select } = SqlBricks
|
||||
|
||||
const MetricsQuerySchema = QuerySchema.extend({
|
||||
type: z.string(),
|
||||
})
|
||||
|
||||
function query2sql(query: z.infer<typeof MetricsQuerySchema>, event: H3Event): string {
|
||||
const filter = query2filter(query)
|
||||
const { dataset } = useRuntimeConfig(event)
|
||||
|
||||
// @ts-expect-error todo
|
||||
const sql = select(`${logsMap[query.type]} as name, SUM(_sample_interval) as count`).from(dataset).where(filter).groupBy('name').orderBy('count DESC').limit(query.limit)
|
||||
appendTimeFilter(sql, query)
|
||||
return sql.toString()
|
||||
}
|
||||
|
||||
export default eventHandler(async (event) => {
|
||||
const query = await getValidatedQuery(event, MetricsQuerySchema.parse)
|
||||
const sql = query2sql(query, event)
|
||||
return useWAE(event, sql)
|
||||
})
|
||||
Reference in New Issue
Block a user