MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / query

Method query

packages/db/src/services/event.service.ts:842–999  ·  view source on GitHub ↗
({
    projectId,
    profileId,
    where,
    select,
    limit,
    filters,
  }: {
    projectId: string;
    profileId?: string;
    where?: {
      profile?: (query: Query<T>) => void;
      event?: (query: Query<T>) => void;
      session?: (query: Query<T>) => void;
    };
    select: {
      profile?: Partial<SelectHelper<IServiceProfile>>;
      event: Partial<SelectHelper<IServiceEvent>>;
    };
    limit?: number;
    orderBy?: keyof IClickhouseEvent;
    filters?: IChartEventFilter[];
  })

Source from the content-addressed store, hash-verified

840 constructor(private client: typeof ch) {}
841
842 query<T>({
843 projectId,
844 profileId,
845 where,
846 select,
847 limit,
848 filters,
849 }: {
850 projectId: string;
851 profileId?: string;
852 where?: {
853 profile?: (query: Query<T>) => void;
854 event?: (query: Query<T>) => void;
855 session?: (query: Query<T>) => void;
856 };
857 select: {
858 profile?: Partial<SelectHelper<IServiceProfile>>;
859 event: Partial<SelectHelper<IServiceEvent>>;
860 };
861 limit?: number;
862 orderBy?: keyof IClickhouseEvent;
863 filters?: IChartEventFilter[];
864 }) {
865 // Extract profile filters if any
866 const profileFilters =
867 filters
868 ?.filter((f) => f.name.startsWith('profile.'))
869 .map((f) => f.name.replace('profile.', '')) ?? [];
870
871 const events = clix(this.client)
872 .select<
873 Partial<IClickhouseEvent> & {
874 // profile
875 profileId: string;
876 profile_firstName: string;
877 profile_lastName: string;
878 profile_avatar: string;
879 profile_isExternal: boolean;
880 profile_createdAt: string;
881 }
882 >([
883 select.event.id && 'e.id as id',
884 select.event.deviceId && 'e.device_id as device_id',
885 select.event.name && 'e.name as name',
886 select.event.path && 'e.path as path',
887 select.event.country && 'e.country as country',
888 select.event.city && 'e.city as city',
889 select.event.os && 'e.os as os',
890 select.event.browser && 'e.browser as browser',
891 select.event.createdAt && 'e.created_at as created_at',
892 select.event.projectId && 'e.project_id as project_id',
893 'e.session_id as session_id',
894 'e.profile_id as profile_id',
895 ])
896 .from('events e')
897 .where('project_id', '=', projectId)
898 .when(profileFilters.length > 0, (q) => {
899 q.leftJoin(

Callers 15

getListMethod · 0.95
getGscOverviewFunction · 0.80
getGscPagesFunction · 0.80
getGscQueriesFunction · 0.80
getImportDateBoundsFunction · 0.80
client.tsFile · 0.80
chQueryWithMetaFunction · 0.80
getExistingTablesFunction · 0.80
checkFunction · 0.80

Calls 14

clixFunction · 0.90
replaceMethod · 0.80
orderByMethod · 0.80
whenMethod · 0.80
selectMethod · 0.80
leftJoinMethod · 0.80
joinMethod · 0.80
limitMethod · 0.80
groupByMethod · 0.80
unionMethod · 0.80
withMethod · 0.80
mapMethod · 0.45

Tested by

no test coverage detected