mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Fix for schema selection in pg adapter.
Some checks are pending
Node.js CI / build (postgresql, 18.18) (push) Waiting to run
Some checks are pending
Node.js CI / build (postgresql, 18.18) (push) Waiting to run
This commit is contained in:
parent
366c52d703
commit
e610de383a
6 changed files with 22 additions and 11 deletions
|
|
@ -40,5 +40,5 @@ export async function GET(
|
|||
endDate,
|
||||
});
|
||||
|
||||
return json({ ...data, comparison });
|
||||
return json({ ...data[0], comparison });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
export const percentFilter = (data: any[]) => {
|
||||
if (!data) return [];
|
||||
if (!Array.isArray(data)) return [];
|
||||
const total = data.reduce((n, { y }) => n + y, 0);
|
||||
return data.map(({ x, y, ...props }) => ({ x, y, z: total ? (y / total) * 100 : 0, ...props }));
|
||||
};
|
||||
|
|
|
|||
|
|
@ -170,6 +170,11 @@ async function rawQuery(sql: string, data: object): Promise<any> {
|
|||
log('PARAMETERS:\n', data);
|
||||
}
|
||||
const params = [];
|
||||
const schema = getSchema();
|
||||
|
||||
if (schema) {
|
||||
await client.$executeRawUnsafe(`SET search_path TO "${schema}";`);
|
||||
}
|
||||
|
||||
const query = sql?.replaceAll(/\{\{\s*(\w+)(::\w+)?\s*}}/g, (...args) => {
|
||||
const [, name, type] = args;
|
||||
|
|
@ -182,8 +187,8 @@ async function rawQuery(sql: string, data: object): Promise<any> {
|
|||
});
|
||||
|
||||
return process.env.DATABASE_REPLICA_URL
|
||||
? client.$replica().$queryRawUnsafe(query, ...params)
|
||||
: client.$queryRawUnsafe(query, ...params);
|
||||
? await client.$replica().$queryRawUnsafe(query, ...params)
|
||||
: await client.$queryRawUnsafe(query, ...params);
|
||||
}
|
||||
|
||||
async function pagedQuery<T>(model: string, criteria: T, filters?: QueryFilters) {
|
||||
|
|
@ -265,6 +270,12 @@ function transaction(input: any, options?: any) {
|
|||
return client.$transaction(input, options);
|
||||
}
|
||||
|
||||
function getSchema() {
|
||||
const connectionUrl = new URL(process.env.DATABASE_URL);
|
||||
|
||||
return connectionUrl.searchParams.get('schema');
|
||||
}
|
||||
|
||||
function getClient() {
|
||||
const prisma = new UmamiPrismaClient({
|
||||
url: process.env.DATABASE_URL,
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ async function relationalQuery(websiteId: string) {
|
|||
{ websiteId, startDate },
|
||||
);
|
||||
|
||||
return result[0] ?? null;
|
||||
return result?.[0] ?? null;
|
||||
}
|
||||
|
||||
async function clickhouseQuery(websiteId: string): Promise<{ x: number }> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue