[Node] implement remote db.TableNames (#334)

This commit is contained in:
Lei Xu
2023-07-18 16:56:47 -07:00
committed by GitHub
parent 980f910f50
commit 1d343edbd4
2 changed files with 35 additions and 4 deletions

View File

@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import axios from 'axios'
import axios, { type AxiosResponse } from 'axios'
import { tableFromIPC, type Table as ArrowTable } from 'apache-arrow'
@@ -60,10 +60,41 @@ export class HttpLancedbClient {
})
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}`)
throw new Error(
`Server Error, status: ${response.status as number}, ` +
`message: ${response.statusText as string}: ${errorData}`
)
}
const table = tableFromIPC(response.data)
return table
}
/**
* Sent GET request.
*/
public async get (path: string, params?: Record<string, string | number>): Promise<AxiosResponse> {
const response = await axios.get(
`${this._url}${path}`,
{
headers: {
'Content-Type': 'application/json',
'x-api-key': this._apiKey
},
params,
timeout: 10000
}
).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
}
}

View File

@@ -47,7 +47,8 @@ export class RemoteConnection implements Connection {
}
async tableNames (): Promise<string[]> {
throw new Error('Not implemented')
const response = await this._client.get('/v1/table/')
return response.data.tables
}
async openTable (name: string): Promise<Table>
@@ -83,7 +84,6 @@ export class RemoteQuery<T = number[]> extends Query<T> {
// TODO: refactor this to a base class + queryImpl pattern
async execute<T = Record<string, unknown>>(): Promise<T[]> {
// TODO: remove as any hack once we refactor
const embeddings = this._embeddings
const query = (this as any)._query
let queryVector: number[]