This feature is now deprecated for all new users. Existing paid users can
continue to use
ATTACH — read the
announcementATTACH statement enables you to link multiple databases within a single transaction, which is ideal for:
- Organizing data in a modular way
- Streamlining data access and enhancing scalability
- Aggregating data
How it works
- You enable the
ATTACHfeature on the databases you want to connect to. - You retrieve the Database ID for the database you want to
ATTACH. - You connect to the database
- CLI:
--attachflag to automatically create a token with the correct permissions. - SDK: Create a token with the
attachpermission for the database you want to attach.
- CLI:
- You invoke
ATTACHto connect to the other databases within the database shell or SDK.
Usage
You can use theATTACH statement to connect to other databases within a transaction using the CLI, or libSQL SDK. Once attached, you can query the attached databases as if they were part of the current database using the assigned alias.
Turso CLI
Make sure you have the Turso CLI installed, and logged in.1
Enable attach on required databases
You will first need to enable the
ATTACH feature on the database(s) you want to attach:2
Retrieve Database ID
You now need to retrieve the Database ID for the database you want to
ATTACH:3
Connect to any database with attach
Now pass the names of the databases via the
--attach flag when connecting to your database(s):4
ATTACH
Now once connected to the database you can invoke an
ATTACH statement to connect the other database(s):5
Query
Execute a query using the alias for any attached database(s):
libSQL SDKs
You can use one of the libSQL client SDKs with TypeScript, Rust, Go, Python, or over HTTP.1
Enable attach on required databases
You will first need to enable the
ATTACH feature on the database(s) you want to attach:2
Retrieve Database ID
You now need to retrieve the Database ID for the database you want to
ATTACH:3
Create token with ATTACH permissions
Now create a token for the libSQL client with the
attach permission for the database you want to attach:4
Connect to any database with ATTACH
Use a Client SDK to attach the desired database within a read transaction:
Things to know
- You can only attach databases that have the
attachfeature enabled. - You can only attach databases belonging to a group, and in the same group.
- There is a maximum of 10 databases that can be attached to a single transaction.
- The attached databases are read only.
ATTACHstatement can be used only within transactions.ATTACHdoesn’t support Embedded Replicas