diff --git a/node/src/remote/client.ts b/node/src/remote/client.ts index 5f594578..3bcbd421 100644 --- a/node/src/remote/client.ts +++ b/node/src/remote/client.ts @@ -104,4 +104,34 @@ export class HttpLancedbClient { } return response } + + /** + * Sent POST request. + */ + public async post (path: string, data?: any, params?: Record): Promise { + const response = await axios.post( + `${this._url}${path}`, + data, + { + headers: { + 'Content-Type': 'application/json', + 'x-api-key': this._apiKey(), + ...(this._dbName !== undefined ? { 'x-lancedb-database': this._dbName } : {}) + }, + params, + timeout: 30000 + } + ).catch((err) => { + console.error('error: ', err) + return err.response + }) + if (response.status !== 200) { + const errorData = new TextDecoder().decode(response.data) + throw new Error( + `Server Error, status: ${response.status as number}, ` + + `message: ${response.statusText as string}: ${errorData}` + ) + } + return response + } } diff --git a/node/src/remote/index.ts b/node/src/remote/index.ts index 4078a04d..84429025 100644 --- a/node/src/remote/index.ts +++ b/node/src/remote/index.ts @@ -77,7 +77,7 @@ export class RemoteConnection implements Connection { } async dropTable (name: string): Promise { - throw new Error('Not implemented') + await this._client.post(`/v1/table/${name}/drop/`) } }