({
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[];
})
| 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( |
no test coverage detected