Adonis Integration
DevDb Pro provides zero-config database discovery for AdonisJS projects using Lucid ORM, automatically reading your .env configuration to connect to your database.
Zero-Config Discovery
DevDb automatically detects Adonis databases from your project configuration.
How It Works
- Open an Adonis project in VS Code
- DevDb reads
.envfile - Extracts database config for Lucid ORM
- Auto-connects to your database
Requirements
- AdonisJS project with Lucid ORM
.envfile with database configuration- Database server running and accessible
Supported Databases
DevDb works with these Adonis database connections:
- MySQL (
DB_CONNECTION=mysql) - PostgreSQL (
DB_CONNECTION=pg)
SQLite Support
SQLite support for Adonis projects is coming soon.
Configuration Examples
MySQL
.env:
DB_CONNECTION=mysql
MYSQL_HOST=127.0.0.1
MYSQL_PORT=3306
MYSQL_USER=root
MYSQL_PASSWORD=secret
MYSQL_DB_NAME=adonis_appDevDb reads these variables and connects to MySQL automatically.
PostgreSQL
.env:
DB_CONNECTION=pg
PG_HOST=localhost
PG_PORT=5432
PG_USER=postgres
PG_PASSWORD=secret
PG_DB_NAME=adonis_appDevDb connects to PostgreSQL using these credentials.
Environment Files
Adonis supports multiple environment files:
.env- Main environment file.env.local- Local overrides (takes precedence).env.testing- Test environment
DevDb reads in this order:
.env.local(if exists).env
Multiple Connections
Adonis supports multiple database connections:
config/database.ts:
{
connection: Env.get('DB_CONNECTION'),
connections: {
mysql: {
client: 'mysql2',
connection: {
host: Env.get('MYSQL_HOST'),
port: Env.get('MYSQL_PORT'),
user: Env.get('MYSQL_USER'),
password: Env.get('MYSQL_PASSWORD'),
database: Env.get('MYSQL_DB_NAME'),
},
},
analytics: {
client: 'mysql2',
connection: {
host: Env.get('ANALYTICS_HOST'),
port: Env.get('ANALYTICS_PORT'),
user: Env.get('ANALYTICS_USER'),
password: Env.get('ANALYTICS_PASSWORD'),
database: Env.get('ANALYTICS_DB_NAME'),
},
},
},
}.env:
DB_CONNECTION=mysql
# Primary database
MYSQL_HOST=127.0.0.1
MYSQL_PORT=3306
MYSQL_USER=root
MYSQL_PASSWORD=secret
MYSQL_DB_NAME=adonis_app
# Analytics database
ANALYTICS_HOST=127.0.0.1
ANALYTICS_PORT=3306
ANALYTICS_USER=root
ANALYTICS_PASSWORD=secret
ANALYTICS_DB_NAME=analyticsDevDb detects and lists both databases in the sidebar.
Features
Database Client
Full Database Client features:
- Browse tables and data
- Inline editing
- Schema viewer
- JSON preview
Quick Table Access
Use Cmd+K Cmd+G (Mac) or Ctrl+K Ctrl+G (Windows/Linux):
- Quickly open any Lucid model table
- Search across all databases
- Instant navigation
Context Menu
Right-click table/model names in code:
- "Open table at cursor" - View table in DevDb
- Works with model class names
- Works with custom table names
Example:
// Right-click "User" and select "DevDb > Open table at cursor"
export default class User extends BaseModel {
// ...
}
// Also works with custom table names
export default class Product extends BaseModel {
public static table = 'inventory_items'
}Data Export
- JSON format - For seeders or testing
- SQL format - For migrations or backups
- Copy to clipboard or save to file
Workflow Examples
Example 1: Inspect Models
After creating models and running migrations:
- Run migrations:
node ace migration:run - Open DevDb (
Cmd+K Cmd+DorCtrl+K Ctrl+D) - Browse tables to verify schema
- Check indexes in Schema tab
- Add test data directly
Example 2: Debug Data Issues
When investigating data problems:
- Open relevant model in code
- Right-click model name → "Open table at cursor"
- Browse actual data in database
- Edit test records to reproduce issue
- Verify fix by refreshing data
Example 3: Create Seed Data
Generate seed data:
- Create test data in DevDb
- Export as JSON using Data Export
- Add to seeder:
// database/seeders/User.ts
import User from 'App/Models/User'
export default class UserSeeder extends BaseSeeder {
public async run () {
const data = [
// ... paste exported JSON
]
await User.createMany(data)
}
}- Run:
node ace db:seed
Example 4: Migration Verification
After writing migrations:
- Apply migration:
node ace migration:run - Refresh DevDb connection
- View schema changes in Schema tab
- Verify constraints and indexes
- Test with sample data
Adonis-Specific Features
Lucid Model Table Names
DevDb handles Lucid's table naming conventions:
Default naming (snake_case plural):
export default class User extends BaseModel {
// Table: users
}
export default class BlogPost extends BaseModel {
// Table: blog_posts
}Custom naming:
export default class User extends BaseModel {
public static table = 'app_users' // Table: app_users
}DevDb recognizes both patterns.
Migration History
View migration history:
- Open
adonis_schematable - See applied migrations
- Check batch numbers
- Verify migration order
Timestamps
View Lucid's automatic timestamps:
created_atupdated_at- Preview in DevDb's date format
Troubleshooting
Database Not Detected
If DevDb doesn't find your Adonis database:
- Check
.envfile exists in workspace root - Verify
DB_CONNECTIONis set - Check database credentials are correct
- Ensure database is running
- Reload VS Code window
Connection Fails
If connection doesn't work:
- Test Adonis connection:
node ace replthenawait Database.rawQuery('SELECT 1') - Check credentials in
.env - Verify database server is accessible
- Review environment variables are loaded
Multiple Environment Files
If using .env.local:
- DevDb prioritizes
.env.local - Ensure credentials are consistent
- Check which file Adonis is using
Docker/Container Setup
For containerized Adonis:
- Expose database port in docker-compose.yml:
services:
mysql:
ports:
- "3306:3306"- Use host port in
.env:
MYSQL_HOST=localhost
MYSQL_PORT=3306- DevDb connects to exposed port
Best Practices
Development
- Use
.env.localfor local overrides - Keep
.env.exampleupdated for team - Add database dumps to
.gitignore - Export fixtures for test data
Team Collaboration
- Document database setup in README
- Share
.env.examplein version control - Never commit
.envwith credentials - Use consistent database versions
Security
- Never commit
.envto git - Use strong passwords in development
- Exclude
.devdbrcfrom version control - Sanitize exports before sharing
Integration with Other Tools
Adonis REPL
Use DevDb alongside REPL:
- DevDb for visual inspection
- REPL for complex queries
- Export from DevDb for scripting
Example REPL usage:
// In node ace repl
const users = await User.all()
// Then verify in DevDbAce Commands
Combine with Ace commands:
- Generate migration:
node ace make:migration - Run migration:
node ace migration:run - Verify in DevDb
Testing
Use DevDb for test data:
- Create test data in DevDb
- Export as JSON
- Use in tests:
// tests/functional/users.spec.ts
test('list users', async ({ client }) => {
// Create from exported data
await User.createMany(exportedData)
const response = await client.get('/users')
// Verify in DevDb if needed
})Environment-Specific Tips
Development
- Use DevDb for quick data inspection
- Edit seed data directly
- Test relationships by browsing data
Testing
- Verify test database schema
- Check seeders load correctly
- Debug test failures visually
Staging
- Use database dump for local inspection:
mysqldump staging_db > staging_dump.sql
mysql local_staging < staging_dump.sql- Browse safely in DevDb
Next Steps
- Database Client - Master the interface
- Quick Table Access - Navigate efficiently
- Data Export - Export fixtures
- Configuration - Manual setup if needed