X
Xata11mo 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!
4 Replies
kostas
kostas11mo 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
JFurnOP11mo ago
Perfect thanks for the quick response!
kostas
kostas11mo 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
Kaligraphy
Kaligraphy2mo ago
I have been looking for this thanks
Want results from more Discord servers?
Add your server