Overview
Qoder supports using database connections in JetBrains IDE as AI context. Through the @database feature, AI can generate SQL, perform schema analysis, or generate related code based on actual database table structures.Prerequisites
Before using database features, you need to configure database connections in JetBrains IDE:- Open the Database tool window
- Create a database connection
- Test if the connection is working
Usage
Referencing Database in Ask/Agent Mode
Add database to context:- Click “Add Context” in the Qoder input box
- Select @database
- Select the target database Schema
- SQL files added to context are generated based on the database schema
- If a database has multiple schemas, multiple corresponding schema SQL files will be generated
- Generate SQL to query a specific table
- Analyze table structure design
- Generate code based on table structure
Generate SQL in Query Console
- Open the database’s Query Console
- Press
Ctrl + Shift + I - Enter natural language description
- Press Enter to generate SQL
Using Slash Commands
You can create custom commands to quickly complete common operations. Create commands:- Click the profile icon in the Qoder window
- Select “Settings” → “Commands”
- Create a new command
/ followed by the command name to invoke it. For example, type /sql to invoke the SQL generation command.
Common command examples:
Generate SQL (/sql):
Using in DataGrip
Add Qoder to toolbar:- Click the ”…” icon at the top
- Select “Qoder”
- Click the pin icon to fix it
- Click the Qoder button in Query Console
- Or press the shortcut
Ctrl + Shift + I
Practical Scenarios
Database Design
Agent Mode (for complex scenarios)
Suitable for:- Need to reference design documents
- Need to generate SQL that complies with specific specifications
- Need to generate migration scripts in specific formats (such as Flyway)
- Add relevant documents to context in Agent mode
- Describe requirements in natural language
- Generate SQL file
- Open and execute the SQL file
Query Console Mode (for simple scenarios)
Suitable for:- Simple database structure design
- Table structure adjustments
- Minor modifications
- Open the database Schema’s Query Console
- Enter requirements
- Adjust and execute the generated SQL
Database Design Best Practices
Provide table structure examples: If you have standard table structure samples, you can provide them to Qoder as reference:- Use clear descriptive names; table and field names should directly express meaning (e.g., user, order_item), singular form recommended
- Maintain naming consistency; uniformly use snake_case or camelCase
- Avoid abbreviations; use customer_address instead of cust_addr
- Add prefixes for boolean fields, such as is_active, has_paid
- Clear primary keys; each table has a clear primary key, named id or table_name_id
- Clear foreign key relationships; foreign keys named like user_id, order_id, clearly pointing to associated tables
- Add timestamps; include created_at, updated_at fields
- Add table comments explaining the table’s purpose
- Add field comments explaining field meaning, value range, units, etc.
- Explain enum values; for status fields, comment on the meaning of each value
- Use appropriate data types; avoid using VARCHAR for everything
- Set reasonable length limits
- Clear NULL value strategy; which fields allow NULL, which are required
- Clear default values; specify if there are clear default values
Annotating Legacy Databases
For legacy databases with non-standard naming, you can use JSON files for annotation to help AI better understand the database structure. Example scenario: Suppose there is the following legacy database table:db-metadata.json file for annotation:
Notes
Very Large Number of Database Tables
If the database schema is very large (many tables, such as in ERP, CRM scenarios), it may exceed the Agent’s context limit. Solutions:- Export the database schema as multiple SQL files
- Add them to context in batches by adding files
- Only add tables relevant to the current task
Database Dialect
Qoder automatically adds the database dialect as a comment to the database schema, so you don’t need to manually declare the database type. If you need to manually add SQL files to context:- You can add comments in the SQL file to indicate the database type, for example:
-- dialect: mysql - You can also declare the database type in the global AGENTS.md