MCPcopy
hub / github.com/umami-software/umami / rawQuery

Function rawQuery

src/lib/prisma.ts:413–440  ·  view source on GitHub ↗
(sql: string, data: Record<string, any>, name?: string)

Source from the content-addressed store, hash-verified

411}
412
413async function rawQuery(sql: string, data: Record<string, any>, name?: string): Promise<any> {
414 if (process.env.LOG_QUERY) {
415 log('QUERY:\n', sql);
416 log('PARAMETERS:\n', data);
417 log('NAME:\n', name);
418 }
419 const params = [];
420 const schema = getSchema();
421
422 if (schema) {
423 await client.$executeRawUnsafe(`SET search_path TO "${schema}";`);
424 }
425
426 const query = sql?.replaceAll(/\{\{\s*(\w+)(::\w+)?\s*}}/g, (...args) => {
427 const [, name, type] = args;
428
429 const value = data[name];
430
431 params.push(value);
432
433 return `$${params.length}${type ?? ''}`;
434 });
435
436 if (process.env.DATABASE_REPLICA_URL && '$replica' in client) {
437 return client.$replica().$queryRawUnsafe(query, ...params);
438 }
439 return client.$queryRawUnsafe(query, ...params);
440}
441
442async function pagedQuery<T>(model: string, criteria: T, filters?: QueryFilters) {
443 const { page = 1, pageSize, orderBy, sortDescending = false, search } = filters || {};

Callers 15

pagedRawQueryFunction · 0.70
relationalQueryFunction · 0.50
clickhouseQueryFunction · 0.50
relationalQueryFunction · 0.50
clickhouseQueryFunction · 0.50
relationalQueryFunction · 0.50
clickhouseQueryFunction · 0.50
relationalQueryFunction · 0.50
clickhouseQueryFunction · 0.50
relationalQueryFunction · 0.50
clickhouseQueryFunction · 0.50
relationalQueryFunction · 0.50

Calls 1

getSchemaFunction · 0.85

Tested by

no test coverage detected