Editor Features
DevDb connects your code to your database. These features work when DevDb shows a database in the panel.
Go to table
Press Cmd+K Cmd+G (macOS) or Ctrl+K Ctrl+G (Windows, Linux). Or run Go to Table from the Command Palette.
Type part of the table name, then press Enter. DevDb opens the table.
Context menu
Right-click in the editor, then open the DevDb submenu.
| Item | Languages | Description |
|---|---|---|
| Open table at cursor | All | Opens the table for the word at the cursor |
| Generate Laravel Factory | PHP | Generates a factory for the model at the cursor |
| Explain query | PHP | Explains the selected query |
Open table at cursor
This works in all languages and frameworks. DevDb converts the word at the cursor to snake_case, then looks for a table with that name. If there is no table, it tries the plural form.
| Word at cursor | Tables that DevDb tries |
|---|---|
User | user, then users |
OrderItem | order_item, then order_items |
blog_posts | blog_posts |
Laravel
CodeLens for Eloquent models
In a Laravel Eloquent model file, DevDb shows CodeLens actions above the class:
- View table: opens the table of the model.
- Generate Factory: generates a factory for the model.
If DevDb is not connected, the CodeLens asks you to connect first.
Factory generator
DevDb creates a model factory that uses real data from your table.
- Open a model, then click Generate Factory. Or right-click the model name and select DevDb > Generate Laravel Factory.
- DevDb runs
php artisan make:factory, then fills in thedefinition()method with values from real rows in the table. - DevDb opens the new file in
database/factories/.
If the factory exists, DevDb asks you to select Open Existing or Overwrite.
Requirements:
- PHP in your
PATH, orDevdb.phpExecutablePathset to the PHP executable. php artisanworks in the project.
Query explainer
The query explainer uses MySQL Visual Explain to show the execution plan of a query.
- In a Laravel PHP file, select the code that runs one query. For example, an Eloquent query or a
DBfacade call. - Click the Explain query CodeLens, or right-click and select DevDb > Explain query.
- Select Open in Browser or Copy URL.
DevDb supports one query at a time. It works with MySQL and MariaDB.
WARNING
To get the SQL, DevDb runs the selected code in your Laravel app. Select only code that reads data.
DevDb sends the query, its bindings, the MySQL version and the execution plan to api.mysqlexplain.com. Do not use the explainer on queries that contain sensitive data.
To hide the Explain query CodeLens on selected text, set Devdb.enableCodeLensForTextSelection to false.
Export table data
Export the rows of a table as JSON or as SQL INSERT statements.
- Open a table.
- Click Export.
- Select the destination (Clipboard or File) and the format (SQL or JSON).
- Clipboard: DevDb copies the data.
- File: DevDb asks where to save the
.jsonor.sqlfile.
DevDb exports the rows of the current page. To export more rows, increase the page size or apply a filter first.
Multi-root workspaces
DevDb does not fully support multi-root workspaces yet. Track the progress in issue #68. Use Devdb.customBasePath to select the folder.