mirror of
https://github.com/umami-software/umami.git
synced 2026-02-06 21:57:16 +01:00
Add Search Api/Components.
This commit is contained in:
parent
45888fabe6
commit
dcf8b2edaa
37 changed files with 1069 additions and 287 deletions
|
|
@ -4,7 +4,7 @@ import { MYSQL, POSTGRESQL, getDatabaseType } from 'lib/db';
|
|||
import { FILTER_COLUMNS, SESSION_COLUMNS } from './constants';
|
||||
import { loadWebsite } from './load';
|
||||
import { maxDate } from './date';
|
||||
import { QueryFilters, QueryOptions } from './types';
|
||||
import { QueryFilters, QueryOptions, SearchFilter } from './types';
|
||||
|
||||
const MYSQL_DATE_FORMATS = {
|
||||
minute: '%Y-%m-%d %H:%i:00',
|
||||
|
|
@ -128,6 +128,37 @@ async function rawQuery(sql: string, data: object): Promise<any> {
|
|||
return prisma.rawQuery(query, params);
|
||||
}
|
||||
|
||||
function getPageFilters(filters: SearchFilter<any>): [
|
||||
{
|
||||
orderBy: {
|
||||
[x: string]: string;
|
||||
}[];
|
||||
take: number;
|
||||
skip: number;
|
||||
},
|
||||
{
|
||||
pageSize: number;
|
||||
page: number;
|
||||
orderBy: string;
|
||||
},
|
||||
] {
|
||||
const { pageSize = 10, page = 1, orderBy } = filters;
|
||||
|
||||
return [
|
||||
{
|
||||
...(pageSize > 0 && { take: pageSize, skip: pageSize * (page - 1) }),
|
||||
...(orderBy && {
|
||||
orderBy: [
|
||||
{
|
||||
[orderBy]: 'asc',
|
||||
},
|
||||
],
|
||||
}),
|
||||
},
|
||||
{ pageSize, page: +page, orderBy },
|
||||
];
|
||||
}
|
||||
|
||||
export default {
|
||||
...prisma,
|
||||
getAddMinutesQuery,
|
||||
|
|
@ -135,5 +166,6 @@ export default {
|
|||
getTimestampIntervalQuery,
|
||||
getFilterQuery,
|
||||
parseFilters,
|
||||
getPageFilters,
|
||||
rawQuery,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue