commit 2 refactor

This commit is contained in:
Boki 2026-10-20 14:35:45 -04:00
parent 588f666943
commit 32e43c9243
310 changed files with 33318 additions and 31189 deletions

View file

@ -1,4 +1,6 @@
import type { PoolConfig, QueryResultRow } from 'pg';
import { Pool } from 'pg';
import type { LoggerLike } from '@stock-bot/logger';
import { QuestDBHealthMonitor } from './health';
import { QuestDBInfluxWriter } from './influx-writer';
import { QuestDBQueryBuilder } from './query-builder';
@ -20,13 +22,17 @@ export class QuestDBClient {
private pgPool: Pool | null = null;
private readonly config: QuestDBClientConfig;
private readonly options: QuestDBConnectionOptions;
private readonly logger: any;
private readonly logger: LoggerLike;
private readonly healthMonitor: QuestDBHealthMonitor;
private readonly influxWriter: QuestDBInfluxWriter;
private readonly schemaManager: QuestDBSchemaManager;
private isConnected = false;
constructor(config: QuestDBClientConfig, logger?: any, options?: QuestDBConnectionOptions) {
constructor(
config: QuestDBClientConfig,
logger?: LoggerLike,
options?: QuestDBConnectionOptions
) {
this.config = config;
this.logger = logger || console;
this.options = {
@ -128,7 +134,7 @@ export class QuestDBClient {
/**
* Execute a SQL query
*/
async query<T = any>(sql: string, params?: any[]): Promise<QueryResult<T>> {
async query<T = QueryResultRow>(sql: string, params?: unknown[]): Promise<QueryResult<T>> {
if (!this.pgPool) {
throw new Error('QuestDB client not connected');
}
@ -150,7 +156,7 @@ export class QuestDBClient {
executionTime,
metadata: {
columns:
result.fields?.map((field: any) => ({
result.fields?.map(field => ({
name: field.name,
type: this.mapDataType(field.dataTypeID),
})) || [],
@ -227,13 +233,13 @@ export class QuestDBClient {
/**
* Execute a time-series specific query with SAMPLE BY
*/
async sampleBy<T = any>(
async sampleBy<T = QueryResultRow>(
table: TableNames,
columns: string[],
interval: string,
_timeColumn: string = 'timestamp',
where?: string,
params?: any[]
params?: unknown[]
): Promise<QueryResult<T>> {
const columnsStr = columns.join(', ');
const whereClause = where ? `WHERE ${where}` : '';
@ -252,7 +258,7 @@ export class QuestDBClient {
/**
* Get latest values by symbol using LATEST BY
*/
async latestBy<T = any>(
async latestBy<T = QueryResultRow>(
table: TableNames,
columns: string | string[] = '*',
keyColumns: string | string[] = 'symbol'
@ -272,13 +278,13 @@ export class QuestDBClient {
/**
* Execute ASOF JOIN for time-series correlation
*/
async asofJoin<T = any>(
async asofJoin<T = QueryResultRow>(
leftTable: TableNames,
rightTable: TableNames,
joinCondition: string,
columns?: string[],
where?: string,
params?: any[]
params?: unknown[]
): Promise<QueryResult<T>> {
const columnsStr = columns ? columns.join(', ') : '*';
const whereClause = where ? `WHERE ${where}` : '';
@ -296,7 +302,7 @@ export class QuestDBClient {
/**
* Get database statistics
*/
async getStats(): Promise<any> {
async getStats(): Promise<QueryResultRow[]> {
const result = await this.query(`
SELECT
table_name,
@ -313,7 +319,7 @@ export class QuestDBClient {
/**
* Get table information
*/
async getTableInfo(tableName: string): Promise<any> {
async getTableInfo(tableName: string): Promise<QueryResultRow[]> {
const result = await this.query(`SELECT * FROM table_columns WHERE table_name = ?`, [
tableName,
]);
@ -412,8 +418,8 @@ export class QuestDBClient {
return { ...this.config };
}
private buildPgPoolConfig(): any {
const config: any = {
private buildPgPoolConfig(): PoolConfig {
const config: PoolConfig = {
host: this.config.host,
port: this.config.pgPort,
database: this.config.database,
@ -430,7 +436,7 @@ export class QuestDBClient {
// Only add user/password if they are provided
if (this.config.user) {
this.logger.debug('Adding user to QuestDB pool config:', this.config.user);
this.logger.debug('Adding user to QuestDB pool config', { user: this.config.user });
config.user = this.config.user;
} else {
this.logger.debug('No user provided for QuestDB connection');