Multi-database query executor with unified JSON output
Archives of precompiled binaries for multi-query are available for macOS and Linux on every release.
Dual-licensed under MIT or the UNLICENSE.
Multi-database query executor with unified JSON output
Usage: multi-query [OPTIONS] --query <FILE>
Options:
-q, --query <FILE> Path to SQL query file to execute across all databases
-c, --connection-string <NAME,URI> Database connection string in format: <name>,<uri>
Examples:
prod-db,postgresql://user:pass@localhost/dbname
Can be specified multiple times to query multiple databases
--config <FILE> Path to config file [default: ~/.multi-query/config.json]
--generate-config Generate a default config file at the config path
-h, --help Print help
-V, --version Print versionExecute a query on a single database:
multi-query --query my-query.sql --connection-string prod-db,postgresql://user:pass@localhost/dbnameExecute a query on multiple databases:
multi-query \
--query my-query.sql \
--connection-string prod-region-1,postgresql://user:pass@localhost/dbname \
--connection-string prod-region-2,postgresql://user:pass@localhost:5433/dbnameExample output:
{"id":1,"name":"Alice","status":"active","db_name":"prod-region-1"}
{"id":2,"name":"Bob","status":"active","db_name":"prod-region-1"}
{"id":1,"name":"Charlie","status":"active","db_name":"prod-region-2"}Instead of passing connection strings every time, you can load them from a config file.
Generate a default config file:
multi-query --generate-configThis creates a default configuration file at ~/.multi-query/config.json.
Edit the config file with your connection strings:
{
"connection_strings": [
{
"name": "prod-region-1",
"uri": "postgresql://user:pass@localhost/dbname"
},
{
"name": "prod-region-2",
"uri": "postgresql://user:pass@localhost:5433/dbname"
}
]
}Now you can run queries without specifying connection strings:
multi-query --query my-query.sqlThis queries both prod-region-1 and prod-region-2 from the config file.
Use a custom config file location:
multi-query --query my-query.sql --config ./my-databases.jsonArchives are available on every release as well as .deb files for Linux.
Autocomplete for arguments and man pages are included.
Tap the repository by running this command:
brew tap w00fmeow/multi-query https://github.com/w00fmeow/multi-queryand install the package:
brew install multi-queryDownload .deb file from latest release and install it using one of the commands:
sudo apt install ./path/to/multi-query.debor
sudo dpkg -i ./path/to/multi-query.debcargo run- for developmentcargo test- to run testscargo build -r- to build in release mode