Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

External SQL

mxcli can connect to external databases (PostgreSQL, Oracle, SQL Server) for querying, schema exploration, data import, and Database Connector generation. This enables workflows like importing reference data from external systems, exploring database schemas, and auto-generating Mendix integration code.

Supported Databases

DatabaseDriver NamesDSN Format
PostgreSQLpostgres, pg, postgresqlpostgres://user:pass@host:5432/dbname
Oracleoracle, oraoracle://user:pass@host:1521/service
SQL Serversqlserver, mssqlsqlserver://user:pass@host:1433?database=dbname

Security

Credentials are isolated from session output. The DSN (which contains username and password) is never displayed in session output, logs, or error messages. Only the alias and driver name are shown.

Capabilities

FeatureCommandDescription
ConnectSQL CONNECTEstablish a named connection
ExploreSQL <alias> SHOW TABLES/VIEWSBrowse database schema
DescribeSQL <alias> DESCRIBE <table>View column details
QuerySQL <alias> <any-sql>Run arbitrary SQL
ImportIMPORT FROM <alias>Import data into Mendix app DB
GenerateSQL <alias> GENERATE CONNECTORAuto-generate Database Connector MDL
DisconnectSQL DISCONNECT <alias>Close connection

Quick Start

-- Connect to an external database
SQL CONNECT postgres 'postgres://user:pass@localhost:5432/mydb' AS source;

-- Explore the schema
SQL source SHOW TABLES;
SQL source DESCRIBE employees;

-- Query data
SQL source SELECT * FROM employees WHERE active = true LIMIT 10;

-- Import into Mendix
IMPORT FROM source QUERY 'SELECT name, email FROM employees'
  INTO HR.Employee
  MAP (name AS Name, email AS Email);

-- Generate Database Connector MDL
SQL source GENERATE CONNECTOR INTO HRModule TABLES (employees, departments) EXEC;

-- Disconnect
SQL DISCONNECT source;

CLI Subcommand

For one-off queries without the REPL:

mxcli sql --driver postgres --dsn 'postgres://user:pass@localhost:5432/mydb' "SELECT * FROM users"