X
Xata8mo ago
JFurn

What is the best way to connect to two databases to the same project?

I have a Typescript project that needs to connect to two different Xata databases. I used xata init to initialise the project with one database and I was thinking it could be best to set up another XataClient with the other database URL, however this will mean the types will be out. Any help would be great!
3 Replies
kostas
kostas8mo ago
That's right, the Xata SDK is generally designed to work with a single database per project, which is set in .xatarc. So xata init leaves you with one database connected to the current project folder that all CLI commands correspond to. You can run xata init in a different path to generate the client (src/xata.ts) and copy that file into your project with a different name (src/xata2.ts for example) to add another db connection and its types.
JFurn
JFurn8mo ago
Perfect thanks for the quick response!
kostas
kostas8mo ago
Here is an example from a user's application utilizing multiple databases in the same project https://github.com/apprendamos/apprendamosdotcom/blob/main/xata/clients/index.ts
Want results from more Discord servers?
Add your server