-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
query macro with multiple databases #224
Comments
That is correct. See here: #121 (comment) We do want to support this. We were thinking a decent approach would be to generate a set of macros with a higher level macro.. e.g., mod one { sqlx::database!(env!("ONE_DATABASE_URL")); }
mod two { sqlx::database!(env!("TWO_DATABASE_URL")); }
one::query!("...") // mysql://...
two::query!("...") // postgres://... |
My code consists of 3 applications (and a library) in a single workspace, and one of the apps has a postgresql db and I'd like to add db's to to the other 2 apps. The apps run on different machines and will have different databases. I have just setup the first app to use offline compilation by using cargo sqxl prepare to generate the query .json files in a .sqlx/ directory in the workspace directory. I also tried cargo sqlx prepare in the package directory of the first app, and it works nicely, generating the .sqlx/ directory in the directory of the first app, but these .json files are not used for compiling the workspace. Above here, this was mentioned "The only possibility that comes to mind is to setup a workspace and somehow dynamically change the environment variable when building separate library packages". The question is: suppose I copy the .sqlx/*.json files from the apps's package directories into the .sqx/ directory of the workspace, Looking at the .json content this might work when the hash in the .json file name is independent of the directory location of the generated .json files. |
Just tried using cargo sqlx prepare in the workspace directory and the package subdirectory. The output of this command makes me hopeful:
|
I have a utility I am writing that will be connecting to multiple databases most MySQL and one Postgres and read data out and store the data in another format in another database. Looking at documentation and the source code it doesn't seem obvious if there is a way to support this scenario. The only possibility that comes to mind is to setup a workspace and somehow dynamically change the environment variable when building separate library packages. Would that be the only approach right now or am I missing something?
Thank you.
The text was updated successfully, but these errors were encountered: