From 03b8f99dca2e30cfd7a0d8fee5c5bf2247bd319e Mon Sep 17 00:00:00 2001 From: gsilvestrin Date: Thu, 10 Aug 2023 09:21:36 -0700 Subject: [PATCH] feat(node) Remote drop table (#412) --- node/src/remote/client.ts | 30 ++++++++++++++++++++++++++++++ node/src/remote/index.ts | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) 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/`) } }