Database Shell
Database-enabled GoForj Apps include a generated shell command for opening configured database connections.
Use it when you want to inspect a local database, run one-off SQL, verify a named connection, or pass native client arguments without copying connection details out of App configuration.
Open A Connection
Open the default connection:
forj dbUse the canonical command when you want the full command name:
forj db:shellThe command is also available on the built App binary:
./bin/app dbNamed Connections
Pass a connection name when the App has multiple database connections:
forj db analytics
forj db --connection analyticsConnection names match the generated App resource names. For example, DB_ANALYTICS_* configuration maps to analytics.
When multiple shellable connections are available and the command runs in an interactive terminal, GoForj can show a compact selector if no connection name is provided. In scripts, pass the connection name explicitly when you do not want the default connection.
Launch Method
By default, GoForj tries to use a local database client first, such as mysql, psql, or sqlite3. If the client is missing and a generated Docker Compose service exists, it falls back to Compose.
Choose a method explicitly when you want predictable behavior:
forj db --method local
forj db --method composeUse --print to inspect the command before running it. Secrets are masked:
forj db --print
forj db analytics --method local --printNon-Interactive SQL
Use --exec to run a single SQL string:
forj db --exec "select count(*) from users"
forj db analytics --exec "select count(*) from events"The same command works through the built binary:
./bin/app db --exec "select 1"Client Arguments
Use -- to pass arguments directly to the underlying client:
forj db -- --batch -e "select count(*) from users"
forj db analytics -- -c "select count(*) from events"
forj db --connection analytics -- -c "select now()"GoForj adds configured connection arguments first, then appends the arguments after --.
This keeps common access simple while still allowing client-specific flags for scripts, exports, batch output, and maintenance commands.
Notes
forj dbis a generated App command. It is available only in Apps with database support.forj db:shellis the canonical command name;forj dbis the preferred day-to-day alias.- Local MySQL connections use TCP so the client does not fall back to a local socket unexpectedly.
- Use
--printwhen debugging which client, host, port, database, and connection method will be used.
