mirror of
https://github.com/lancedb/lancedb.git
synced 2026-01-04 10:52:56 +00:00
feat(node): let NODE API region default to us-east-1 (#1631)
Fixes #1622 To sync with python API
This commit is contained in:
@@ -60,7 +60,7 @@ export {
|
||||
type MakeArrowTableOptions
|
||||
} from "./arrow";
|
||||
|
||||
const defaultAwsRegion = "us-west-2";
|
||||
const defaultAwsRegion = "us-east-1";
|
||||
|
||||
const defaultRequestTimeout = 10_000
|
||||
|
||||
@@ -111,7 +111,7 @@ export interface ConnectionOptions {
|
||||
*/
|
||||
apiKey?: string
|
||||
|
||||
/** Region to connect */
|
||||
/** Region to connect. Default is 'us-east-1' */
|
||||
region?: string
|
||||
|
||||
/**
|
||||
@@ -197,28 +197,31 @@ export async function connect(
|
||||
export async function connect(
|
||||
arg: string | Partial<ConnectionOptions>
|
||||
): Promise<Connection> {
|
||||
let opts: ConnectionOptions;
|
||||
let partOpts: Partial<ConnectionOptions>;
|
||||
if (typeof arg === "string") {
|
||||
opts = { uri: arg };
|
||||
partOpts = { uri: arg };
|
||||
} else {
|
||||
const keys = Object.keys(arg);
|
||||
if (keys.length === 1 && keys[0] === "uri" && typeof arg.uri === "string") {
|
||||
opts = { uri: arg.uri };
|
||||
partOpts = { uri: arg.uri };
|
||||
} else {
|
||||
opts = Object.assign(
|
||||
{
|
||||
uri: "",
|
||||
awsCredentials: undefined,
|
||||
awsRegion: defaultAwsRegion,
|
||||
apiKey: undefined,
|
||||
region: defaultAwsRegion,
|
||||
timeout: defaultRequestTimeout
|
||||
},
|
||||
arg
|
||||
);
|
||||
partOpts = arg;
|
||||
}
|
||||
}
|
||||
|
||||
let defaultRegion = process.env.AWS_REGION ?? process.env.AWS_DEFAULT_REGION;
|
||||
defaultRegion = (defaultRegion ?? "").trim() !== "" ? defaultRegion : defaultAwsRegion;
|
||||
|
||||
const opts: ConnectionOptions = {
|
||||
uri: partOpts.uri ?? "",
|
||||
awsCredentials: partOpts.awsCredentials ?? undefined,
|
||||
awsRegion: partOpts.awsRegion ?? defaultRegion,
|
||||
apiKey: partOpts.apiKey ?? undefined,
|
||||
region: partOpts.region ?? defaultRegion,
|
||||
timeout: partOpts.timeout ?? defaultRequestTimeout,
|
||||
readConsistencyInterval: partOpts.readConsistencyInterval ?? undefined,
|
||||
storageOptions: partOpts.storageOptions ?? undefined
|
||||
}
|
||||
if (opts.uri.startsWith("db://")) {
|
||||
// Remote connection
|
||||
return new RemoteConnection(opts);
|
||||
|
||||
@@ -82,7 +82,7 @@ async function callWithMiddlewares (
|
||||
|
||||
interface MiddlewareInvocationOptions {
|
||||
responseType?: ResponseType
|
||||
timeout?: number,
|
||||
timeout?: number
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,8 +130,8 @@ export class HttpLancedbClient {
|
||||
url: string,
|
||||
apiKey: string,
|
||||
timeout?: number,
|
||||
private readonly _dbName?: string,
|
||||
|
||||
private readonly _dbName?: string
|
||||
|
||||
) {
|
||||
this._url = url
|
||||
this._apiKey = () => apiKey
|
||||
@@ -237,7 +237,7 @@ export class HttpLancedbClient {
|
||||
try {
|
||||
response = await callWithMiddlewares(req, this._middlewares, {
|
||||
responseType,
|
||||
timeout: this._timeout,
|
||||
timeout: this._timeout
|
||||
})
|
||||
|
||||
// return response
|
||||
|
||||
@@ -112,8 +112,8 @@ describe("LanceDB client", function () {
|
||||
name: 'name_2',
|
||||
price: 10,
|
||||
is_active: true,
|
||||
vector: [ 0, 0.1 ]
|
||||
},
|
||||
vector: [0, 0.1]
|
||||
}
|
||||
]);
|
||||
assert.equal(await table2.countRows(), 3);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user