A web based SQL workbench

The SQL component allows you to execute any arbitrary SQL towards your database of choice. This component also allows you to export the result of some SQL to a CSV file, in addition to saving frequently used SQL statements by using its “Load” and “Save” buttons. Out of the box Magic also comes with a whole range of example SQL snippets, implying the SQL component in Magic is also a nice place to start out if you want to teach yourself SQL. Below is a screenshot of how loading an SQL snippet would look like in your SQL component.

Loading SQL snippets

The SQL component also provides you with syntax highlighting, in addition to autocomplete on tables and columns that can be shown by clicking CTRL+SPACE on Windows or FN+CONTROL+SPACE on a Mac. Below is a screenshot of how it would look like if you toggle autocomplete. Notice, it only shows you tables and columns within your currently selected database. If you don’t find the tables you’re looking for, make sure you have selected the correct database.

SQL autocomplete

The “Safe mode” checkbox above prevents you from selecting more than 200 rows from your database. If you need to select more rows you must click this checkbox off. However, if you return thousands of records in this component, your server might become unresponsive, and/or you may end up exhausting your server’s memory. You can save your frequently used SQL statements as “snippets” here similarly to how you can save frequently used Hyperlambda in your “Evaluator” component.

If you have some SQL Server script that creates a database, and/or contains “go” keywords, you’ll need to turn on “Batch mode” to have Magic understand your SQL. If you click the “Load” button you will also find several example “create database” types of scripts, for each database type Magic supports. This allows you to create some database in your database type of choice, and play around with for instance the “Crudifier” to generate web APIs automatically. If you execute a script that creates a database, you’ll have to empty your server side cache before you can select this database in your database select drop down. You can do this by clicking the circular “refresh” button next to the load button.