@lancedb/lancedb •Docs
@lancedb/lancedb / Connection
Class:abstract Connection
A LanceDB Connection that allows you to open tables and create new ones.
Connection could be local against filesystem or remote against a server.
A Connection is intended to be a long lived object and may hold openresources such as HTTP connection pools. This is generally fine anda single connection should be shared if it is going to be used manytimes. However, if you are finished with a connection, you may callclose to eagerly free these resources. Any call to a Connectionmethod after it has been closed will result in an error.
Closing a connection is optional. Connections will automaticallybe closed when they are garbage collected.
Any created tables are independent and will continue to work even ifthe underlying connection has been closed.
Methods
cloneTable()
Clone a table from a source table.
A shallow clone creates a new table that shares the underlying data fileswith the source table but has its own independent manifest. This allowsboth the source and cloned tables to evolve independently while initiallysharing the same data, deletion, and index files.
Parameters
targetTableName:
stringThe name of the target table to create.sourceUri:
stringThe URI of the source table to clone from.options? Clone options.
options.isShallow?:
booleanWhether to perform a shallow clone (defaults to true).options.sourceTag?:
stringThe tag of the source table to clone.options.sourceVersion?:
numberThe version of the source table to clone.options.targetNamespace?:
string[] The namespace for the target table (defaults to root namespace).
Returns
Promise<Table>
close()
Close the connection, releasing any underlying resources.
It is safe to call this method multiple times.
Any attempt to use the connection after it is closed will result in an error.
Returns
void
createEmptyTable()
createEmptyTable(name, schema, options)
Creates a new empty Table
Parameters
name:
stringThe name of the table.schema:
SchemaLikeThe schema of the tableoptions?:
Partial<CreateTableOptions> Additional options (backwards compatibility)
Returns
Promise<Table>
createEmptyTable(name, schema, namespace, options)
Creates a new empty Table
Parameters
name:
stringThe name of the table.schema:
SchemaLikeThe schema of the tablenamespace?:
string[] The namespace to create the table in (defaults to root namespace)options?:
Partial<CreateTableOptions> Additional options
Returns
Promise<Table>
createTable()
createTable(options, namespace)
Creates a new Table and initialize it with new data.
Parameters
options:
object&Partial<CreateTableOptions> The options object.namespace?:
string[] The namespace to create the table in (defaults to root namespace)
Returns
Promise<Table>
createTable(name, data, options)
Creates a new Table and initialize it with new data.
Parameters
name:
stringThe name of the table.data:
TableLike|Record<string,unknown>[] Non-empty Array of Records to be inserted into the tableoptions?:
Partial<CreateTableOptions> Additional options (backwards compatibility)
Returns
Promise<Table>
createTable(name, data, namespace, options)
Creates a new Table and initialize it with new data.
Parameters
name:
stringThe name of the table.data:
TableLike|Record<string,unknown>[] Non-empty Array of Records to be inserted into the tablenamespace?:
string[] The namespace to create the table in (defaults to root namespace)options?:
Partial<CreateTableOptions> Additional options
Returns
Promise<Table>
display()
Return a brief description of the connection
Returns
string
dropAllTables()
Drop all tables in the database.
Parameters
- namespace?:
string[] The namespace to drop tables from (defaults to root namespace).
Returns
Promise<void>
dropTable()
Drop an existing table.
Parameters
name:
stringThe name of the table to drop.namespace?:
string[] The namespace of the table (defaults to root namespace).
Returns
Promise<void>
isOpen()
Return true if the connection has not been closed
Returns
boolean
openTable()
Open a table in the database.
Parameters
name:
stringThe name of the tablenamespace?:
string[] The namespace of the table (defaults to root namespace)options?:
Partial<OpenTableOptions> Additional options
Returns
Promise<Table>
tableNames()
tableNames(options)
List all the table names in this database.
Tables will be returned in lexicographical order.
Parameters
- options?:
Partial<TableNamesOptions> options to control the paging / start point (backwards compatibility)
Returns
Promise<string[]>
tableNames(namespace, options)
List all the table names in this database.
Tables will be returned in lexicographical order.
Parameters
namespace?:
string[] The namespace to list tables from (defaults to root namespace)options?:
Partial<TableNamesOptions> options to control the paging / start point
Returns
Promise<string[]>