mirror of
https://github.com/supabase/supabase.git
synced 2026-10-08 19:05:06 +03:00
bugfix for where query building
This commit is contained in:
1 parent
635f3212ed
commit
46cbdd4d41
2 files changed
+7
-7
No files matched your search
@@ -70,10 +70,10 @@ export const LOG_TYPE_LABEL_MAPPING: { [k: string]: string } = {
|
||||
database: 'Database',
|
||||
}
|
||||
|
||||
export const genDefaultQuery = (table: string): string => `SELECT
|
||||
export const genDefaultQuery = (table: string, where: string = ''): string => `SELECT
|
||||
id, timestamp, event_message, metadata
|
||||
FROM
|
||||
${table}
|
||||
${table}${where ? '\nWHERE ' + where : ''}
|
||||
`
|
||||
|
||||
export const genCountQuery = (table: string): string => `SELECT count(*) as count FROM ${table}`
|
||||
export const genCountQuery = (table: string, where: string=""): string => `SELECT count(*) as count FROM ${table}${where ? '\nWHERE ' + where : ''}`
|
||||
@@ -71,7 +71,7 @@ export const LogPage: NextPage = () => {
|
||||
const checkIfSelectQuery = (value: string) =>
|
||||
value.toLowerCase().includes('select') ? true : false
|
||||
const isSelectQuery = checkIfSelectQuery(editorValue)
|
||||
|
||||
const table = type === 'api' ? 'edge_logs' : 'postgres_logs'
|
||||
useEffect(() => {
|
||||
setParams({ ...params, type: type as string })
|
||||
}, [type])
|
||||
@@ -148,7 +148,7 @@ export const LogPage: NextPage = () => {
|
||||
|
||||
const countUrl = `${API_URL}/projects/${ref}/analytics/endpoints/logs.${type}?${genQueryParams({
|
||||
...params,
|
||||
sql: genCountQuery(type === 'api' ? 'edge_logs' : 'postgres_logs'),
|
||||
sql: genCountQuery(table),
|
||||
period_start: String(latestRefresh),
|
||||
})}`
|
||||
const { data: countData } = useSWR<Count>(countUrl, get, { refreshInterval: 5000 })
|
||||
@@ -172,7 +172,7 @@ export const LogPage: NextPage = () => {
|
||||
setMode('custom')
|
||||
onSelectTemplate({
|
||||
mode: 'custom',
|
||||
searchString: genDefaultQuery(type === 'api' ? 'edge_logs' : 'postgres_logs'),
|
||||
searchString: genDefaultQuery(table),
|
||||
})
|
||||
} else {
|
||||
setMode('simple')
|
||||
@@ -202,7 +202,7 @@ export const LogPage: NextPage = () => {
|
||||
const handleEditorSubmit = () => {
|
||||
setParams((prev) => ({
|
||||
...prev,
|
||||
sql: editorValue,
|
||||
sql: checkIfSelectQuery(editorValue) ? editorValue : genDefaultQuery(table, editorValue),
|
||||
search_query: '',
|
||||
}))
|
||||
router.push({
|
||||
|
||||
Reference in new issue
Block a user