From f0c5f5ba62349bd7caf7ecd9276a05f001c09974 Mon Sep 17 00:00:00 2001 From: Will Jones Date: Tue, 12 Mar 2024 13:25:56 -0700 Subject: [PATCH] fix: handle uri in object (#1091) Fixes #1078 --- node/src/index.ts | 25 +++++++++++++++---------- node/src/test/test.ts | 3 ++- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/node/src/index.ts b/node/src/index.ts index 69aea280..a11b5d85 100644 --- a/node/src/index.ts +++ b/node/src/index.ts @@ -176,16 +176,21 @@ export async function connect ( opts = { uri: arg } } else { // opts = { uri: arg.uri, awsCredentials = arg.awsCredentials } - opts = Object.assign( - { - uri: '', - awsCredentials: undefined, - awsRegion: defaultAwsRegion, - apiKey: undefined, - region: defaultAwsRegion - }, - arg - ) + const keys = Object.keys(arg) + if (keys.length === 1 && keys[0] === 'uri' && typeof arg.uri === 'string') { + opts = { uri: arg.uri } + } else { + opts = Object.assign( + { + uri: '', + awsCredentials: undefined, + awsRegion: defaultAwsRegion, + apiKey: undefined, + region: defaultAwsRegion + }, + arg + ) + } } if (opts.uri.startsWith('db://')) { diff --git a/node/src/test/test.ts b/node/src/test/test.ts index 433d7fc8..62fd9b45 100644 --- a/node/src/test/test.ts +++ b/node/src/test/test.ts @@ -288,7 +288,8 @@ describe('LanceDB client', function () { it('create a table from an Arrow Table', async function () { const dir = await track().mkdir('lancejs') - const con = await lancedb.connect(dir) + // Also test the connect function with an object + const con = await lancedb.connect({ uri: dir }) const i32s = new Int32Array(new Array(10)) const i32 = makeVector(i32s)