@vulcan-sql/extension-driver-ksqldb
Version:
ksqlDB driver for VulcanSQL
83 lines (82 loc) • 2.62 kB
TypeScript
/// <reference types="node" />
import * as http2 from 'http2';
interface KsqlInfoResponse {
KsqlServerInfo: {
version: string;
kafkaClusterId: string;
ksqlServiceId: string;
serverStatus: string;
};
}
export declare type Header = {
header: {
queryId: string;
schema: string;
};
};
export declare type Row = {
row: {
columns: any[];
};
};
export declare type FinalMessage = {
finalMessage: string;
};
/**
* The example query response like below:
* [
* {
* "header": {
* "queryId": "transient_RIDERLOCATIONS_356492705638097482",
* "schema": "`PROFILEID` STRING, `LATITUDE` DOUBLE, `LONGITUDE` DOUBLE"
* }
* },
* { "row": {"columns": ["c2309eec",37.7877,-122.4205]} },
* { ...more rows },
*
* { "finalMessage": "Query Completed"}
* ]
*/
export declare type QueryResponse = Header | Row | FinalMessage;
export interface RestfulClientOptions {
host?: string;
username?: string;
password?: string;
timeout?: number;
}
export declare class RestfulClient {
private options;
client?: http2.ClientHttp2Session;
connected: boolean;
private startSession;
constructor(options: RestfulClientOptions);
/**
* The connect method will create a promise "startSession" method, not really to connect http2 immediately.
* To let users establish a "startSession" promise request only when they need to query or exec a statement.
*/
connect(): void;
closeSession(): Promise<void>;
checkConnection(): Promise<KsqlInfoResponse['KsqlServerInfo']['serverStatus']>;
checkConnectionRunning(): Promise<boolean>;
/**
* According to ksqldb restful API: https://docs.ksqldb.io/en/latest/developer-guide/ksqldb-rest-api/query-endpoint
* To run a SELECT statement and stream back the results.
* SELECT statement: https://docs.ksqldb.io/en/latest/developer-guide/ksqldb-reference/select-pull-query
*/
query({ query, query_params, }: {
query: string;
query_params?: Record<string, any>;
}): Promise<QueryResponse[]>;
/**
* According to ksqldb restful API: https://docs.ksqldb.io/en/latest/developer-guide/ksqldb-rest-api/ksql-endpoint
* All statements, except those starting with SELECT and PRINT, can be run on this exec method.
* To run SELECT and PRINT statements use the "query" method instead.
*/
exec({ query, query_params, }: {
query: string;
query_params?: Record<string, any>;
}): Promise<QueryResponse[]>;
private bindParams;
private request;
}
export {};