init ana page with apis

This commit is contained in:
2025-03-21 12:08:37 +08:00
commit 271230fca7
71 changed files with 15699 additions and 0 deletions

1266
lib/analytics.ts Normal file

File diff suppressed because it is too large Load Diff

47
lib/clickhouse.ts Normal file
View File

@@ -0,0 +1,47 @@
import { createClient } from '@clickhouse/client';
// Create configuration object using the URL approach
const config = {
url: process.env.CLICKHOUSE_URL || 'http://localhost:8123',
username: process.env.CLICKHOUSE_USER || 'default',
password: process.env.CLICKHOUSE_PASSWORD || '',
database: process.env.CLICKHOUSE_DATABASE || 'limq'
};
// Log configuration (removing password for security)
console.log('ClickHouse config:', {
...config,
password: config.password ? '****' : ''
});
// Create ClickHouse client with proper URL format
export const clickhouse = createClient(config);
// Log connection status
console.log('ClickHouse client created with URL:', config.url);
/**
* Execute ClickHouse query and return results
*/
export async function executeQuery<T>(query: string): Promise<T[]> {
try {
const result = await clickhouse.query({
query,
format: 'JSONEachRow',
});
const data = await result.json();
return data as T[];
} catch (error) {
console.error('ClickHouse query error:', error);
throw error;
}
}
/**
* Execute ClickHouse query and return a single result
*/
export async function executeQuerySingle<T>(query: string): Promise<T | null> {
const results = await executeQuery<T>(query);
return results.length > 0 ? results[0] : null;
}