13. The miraj-cli console
miraj-cli is the MIRAJ interactive SQL console: it opens a data folder, executes SQL statements and displays the results. It is used both for interactive exploration (REPL) and for running .sql scripts in batch mode (scheduled tasks, migrations, deployments).
13.1 General syntax#
miraj-cli [--root <dossier>] [--config <fichier.xml>] [-d <base>] [-e "<SQL>"]
[--lang en|fr|zh|hi|es|ar|pt|ru|de|ja] [--json] [--timing] [--no-history]
[<fichier.sql>]Option names are case-insensitive (--ROOT is equivalent to --root).
Exit codes:
| Code | Meaning |
|---|---|
0 | Success (all statements succeeded) |
1 | At least one statement failed, or a .sql file given as an argument was not found |
2 | Error while opening the embedded server (root folder, configuration file) |
13.2 Command-line options#
| Option | Description | Example |
|---|---|---|
--root <dossier> | Root folder of the data to open (default: data, created if missing). All the databases it contains are loaded at startup. | miraj-cli --root C:\donnees\miraj |
--config <fichier.xml> | XML engine configuration file to use, instead of <root folder>\miraj.xml. A commented reference file is regenerated at each startup next to this file. | miraj-cli --config C:\conf\miraj-prod.xml |
-d <base> | Database to select after opening (equivalent to typing USE <base>; as the first statement). | miraj-cli -d shop |
-e "<SQL>" | Executes the given SQL statement (or script) then exits, without entering the REPL. Disables the history. | miraj-cli -d shop -e "SELECT COUNT(*) FROM articles" |
--lang <code> | Language of error and warning messages: en (default), fr, zh, hi, es, ar, pt, ru, de, ja. | miraj-cli --lang fr |
--json | Displays results as JSON instead of a text table. Can also be enabled during a session with \json. | miraj-cli --json -e "SELECT * FROM articles" |
--timing | Displays the execution time of each statement. Can also be enabled during a session with \timing. | miraj-cli --timing |
--no-history | Disables reading and writing of the persistent statement history. | miraj-cli --no-history |
<fichier.sql> | Executes this file in batch mode then exits (recognized by its .sql extension, without being the value of -e). The last .sql argument on the command line is the one retained. | miraj-cli migration.sql |
--help, -h, /? | Displays the syntax summary and exits. | miraj-cli --help |
Notes:
-eand<fichier.sql>take precedence over the REPL, in that order: if-eis present, it is executed and the console exits without reading any file or opening a REPL; otherwise, if there is a.sqlargument, that file is executed; otherwise, the REPL starts.-d <base>can be combined with-eor with a.sqlfile: the database is selected before execution.- The executed
.sqlfile may begin with a UTF-8 BOM, which is ignored automatically.
13.3 Internal REPL commands#
In the REPL, an SQL statement can span several lines; it is sent to the engine as soon as a line ends with ;. The following commands, most of them prefixed with \, are not SQL and run immediately, without a semicolon:
| Command | Purpose | Example |
|---|---|---|
\help, \h, help | Displays the list of commands. | \help |
\timing | Toggles the display of execution time (on/off). | \timing |
\json | Toggles the result display format between table and JSON. | \json |
\d | Lists the tables of the current database (SHOW TABLES). | \d |
\d <table> | Describes the columns of the given table (DESCRIBE <table>). | \d articles |
\l | Lists the databases of the server (SHOW DATABASES). | \l |
\history [n] | Displays the last n statements of the history (20 by default). A negative number displays nothing. | \history 50 |
\!n | Re-executes statement number n of the history (number shown by \history). | \!12 |
source <fichier.sql>, \. <fichier.sql> | Executes a .sql file without leaving the REPL. | source migration.sql |
\q, exit, quit | Exits the console. | \q |
| up / down arrows | Recall of previously typed lines (Windows console). | — |
13.4 Typical interactive use#
> miraj-cli --root C:\donnees\miraj --timing
MIRAJ 1.0 Standard - tapez \help pour l'aide, \q pour quitter.
miraj> \l
+----------+
| Database |
+----------+
| shop |
+----------+
1 ligne(s) (0.42 ms)
miraj> USE shop;
OK, 0 ligne(s) affectée(s) (0.10 ms)
shop> \d
+-----------+
| Table |
+-----------+
| articles |
+-----------+
1 ligne(s) (0.08 ms)
shop> \d articles
+--------+---------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+---------------+------+-----+---------+----------------+
| id | int | NO | PRI | NULL | auto_increment |
| nom | varchar(50) | NO | | NULL | |
| prix | decimal(10,2) | YES | | NULL | |
+--------+---------------+------+-----+---------+----------------+
3 ligne(s) (0.15 ms)
shop> SELECT nom, prix
-> FROM articles
-> WHERE prix > 10;
+---------+-------+
| nom | prix |
+---------+-------+
| Cahier | 12.90 |
+---------+-------+
1 ligne(s) (0.31 ms)
shop> \json
Résultats au format JSON
shop> SELECT nom, prix FROM articles WHERE prix > 10;
[
{"nom": "Cahier", "prix": 12.90}
]
1 ligne(s) (0.12 ms)
shop> \qThe prompt shows the current database (shop>) or miraj> if no database is selected; it becomes -> while continuing an unfinished multi-line statement.
13.5 Running SQL scripts in batch mode#
Three ways to run a script without going through the interactive REPL:
# File given as an argument: executed, then the console exits
miraj-cli --root C:\donnees\miraj -d shop migration.sql
# Inline statement or script with -e (several statements separated by ;)
miraj-cli --root C:\donnees\miraj -e "USE shop; DELETE FROM articles WHERE stock = 0;"
# From the REPL, without leaving the current session
miraj> source migration.sqlA non-zero exit code signals a failed script; combined with --json, the output of a script executed with -e can be consumed directly by another program:
miraj-cli --root C:\donnees\miraj -d shop --json -e "SELECT id, nom FROM articles" > articles.json
if ($LASTEXITCODE -ne 0) { Write-Error "Échec du script" }13.6 Practical tips#
- Persistent history: each statement submitted in the REPL is appended to
%APPDATA%\MIRAJ\cli-history.sql(or~/.config/MIRAJ/cli-history.sqloutside Windows), with up to 1000 entries kept. This history is reloaded at the next startup and feeds\historyand\!n.--no-history(or-e, which disables it automatically) ignores it, which is useful for scripts called in a loop from a scheduled task. - Timing:
--timing(or\timingduring a session) is useful for quickly comparing two formulations of the same query without instrumenting a client. - JSON format:
--json(or\json) makes it easy to pass results to another command-line tool (ConvertFrom-Jsonin PowerShell,jq, etc.) without writing a dedicated client. - Configuration file: at the first startup on a root folder,
miraj-cliwrites a commented XML configuration file (a template of the engine variables) next to the folder; customizing it and then restarting the console applies the settings via--config. - Warnings: session warnings (truncations, default values applied, etc.) are displayed after the result of each statement that produced any.