add support for host override (#335)

This commit is contained in:
Rob Meng
2023-07-18 21:21:39 -04:00
committed by GitHub
parent 5e3167da83
commit a636bb1075
4 changed files with 18 additions and 5 deletions

View File

@@ -44,6 +44,9 @@ export interface ConnectionOptions {
apiKey?: string
// Region to connect
region?: string
// override the host for the remote connections
hostOverride?: string
}
/**

View File

@@ -19,7 +19,11 @@ import { tableFromIPC, type Table as ArrowTable } from 'apache-arrow'
export class HttpLancedbClient {
private readonly _url: string
public constructor (url: string, private readonly _apiKey: string) {
public constructor (
url: string,
private readonly _apiKey: string,
private readonly _dbName?: string
) {
this._url = url
}
@@ -49,7 +53,8 @@ export class HttpLancedbClient {
{
headers: {
'Content-Type': 'application/json',
'x-api-key': this._apiKey
'x-api-key': this._apiKey,
...(this._dbName !== undefined ? { 'x-lancedb-database': this._dbName } : {})
},
responseType: 'arraybuffer',
timeout: 10000

View File

@@ -37,8 +37,13 @@ export class RemoteConnection implements Connection {
}
this._dbName = opts.uri.slice('db://'.length)
const server = `https://${this._dbName}.${opts.region}.api.lancedb.com`
this._client = new HttpLancedbClient(server, opts.apiKey)
let server: string
if (opts.hostOverride === undefined) {
server = `https://${this._dbName}.${opts.region}.api.lancedb.com`
} else {
server = opts.hostOverride
}
this._client = new HttpLancedbClient(server, opts.apiKey, opts.hostOverride === undefined ? undefined : this._dbName)
}
get uri (): string {