Skip to main content

CLI for SQL of InterSystems IRIS Databases with auto-completion and syntax highlighting.

Project description

A REPL for InterSystems IRIS SQL

This is a InterSystems IRIS client that does auto-completion and syntax highlighting.

Based on pgcli

irissqlcli

Quick Start

With Python

pip install -U irissqlcli

Or with homebrew

brew tap caretdev/tap
brew install irissqlcli

Usage

$ irissqlcli [uri]

or

$ irissqlcli iris://[user[:password]@][netloc][:port][/namespace]

or

$ irissqlcli iris+emb://[/namespace]

Examples:

$ irissqlcli iris://_SYSTEM:SYS@localhost:1972/USER

$ irissqlcli iris+emb:///

For more details:

$ irissqlcli --help
Usage: irissqlcli [OPTIONS] [URI] [USERNAME]

Options:
-h, --host TEXT         Host address of the IRIS instance.
-p, --port INTEGER      Port number at which the IRIS instance is listening.
-U, --username TEXT     Username to connect to the IRIS instance.
-u, --user TEXT         Username to connect to the IRIS instance.
-W, --password          Force password prompt.
-v, --version           Version of irissqlcli.
-n, --nspace TEXT       namespace name to connect to.
-q, --quiet             Quiet mode, skip intro on startup and goodbye on
                        exit.
-l, --logfile FILENAME  Log every query and its results to a file.
--irissqlclirc FILE     Location of irissqlclirc file.
--auto-vertical-output  Automatically switch to vertical output mode if the
                        result is wider than the terminal width.
--row-limit INTEGER     Set threshold for row limit prompt. Use 0 to disable
                        prompt.
-t, --table             Display batch output in table format.
--csv                   Display batch output in CSV format.
--warn / --no-warn      Warn before running a destructive query.
-e, --execute TEXT      Execute command and quit.
--help                  Show this message and exit.

irissqlcli also supports environment variables for login options (e.g. IRIS_HOSTNAME, IRIS_PORT, IRIS_NAMESPACE, IRIS_USERNAME, IRIS_PASSWORD).

Features

The irissqlcli is written using prompt_toolkit_.

  • Auto-completes as you type for SQL keywords as well as tables and columns in the database.

  • Syntax highlighting using Pygments.

  • Smart-completion (enabled by default) will suggest context-sensitive completion.

    • SELECT * FROM <tab> will only show table names.
    • SELECT * FROM users WHERE <tab> will only show column names.
  • Pretty prints tabular data.

Config

A config file is automatically created at ~/.config/irissqlcli/config at first launch. See the file itself for a description of all available options.

Docker

irisqlcli can be run from within Docker. This can be useful to try irissqlcli without installing it, or any dependencies, system-wide.

To create a container from the image:

$ docker run --rm -ti caretdev/irissqlcli irissqlcli <ARGS>

To access InterSystems IRIS databases listening on localhost, make sure to run the docker in "host net mode". E.g. to access a database called "foo" on the IRIS server running on localhost:1972 (the standard port):

$ docker run --rm -ti --net host caretdev/irissqlcli irissqlcli iris://_SYSTEM:SYS@localhost:1972/USER

or without `host net mode`

$ docker run --rm -ti caretdev/irissqlcli irissqlcli iris://_SYSTEM:SYS@host.docker.internal:1972/USER

IPython

irisqlcli can be run from within IPython console. When working on a query, it may be useful to drop into a irissqlcli session without leaving the IPython console, iterate on a query, then quit irissqlcli to find the query results in your IPython workspace.

Assuming you have IPython installed:

$ pip install sqlalchemy~=1.4.0 ipython-sql sqlalchemy-iris

After that, run ipython and load the irissqlcli.magic extension:

$ ipython

In [1]: %load_ext irissqlcli.magic

or 
$ ipython --ext irissqlcli.magic

Connect to a database:

In [2]: %irissqlcli iris://_SYSTEM:SYS@localhost:1972/USER
self.dialect <class 'sqlalchemy_iris.iris.IRISDialect_iris'>
sqlalchemy.MetaData <class 'sqlalchemy.sql.schema.MetaData'>
Server:  InterSystems IRIS Version 2022.2.0.368 xDBC Protocol Version 65
Version: 0.1.0
[SQL]_SYSTEM@localhost:USER> select top 10 table_schema,table_name from information_schema.tables
+--------------------+----------------+
| TABLE_SCHEMA       | TABLE_NAME     |
+--------------------+----------------+
| %CSP_Util          | CSPLogEvent    |
| %CSP_Util          | Performance    |
| %Calendar          | Hijri          |
| %Compiler_Informix | ConversionRule |
| %Compiler_Informix | ImportedObject |
| %Compiler_Informix | Symbol         |
| %Compiler_LG       | WrapperPropDef |
| %Compiler_TSQL     | sysSymbol      |
| %DeepSee           | IDList         |
| %DeepSee           | TempSourceId   |
+--------------------+----------------+
10 rows in set
Time: 0.074s
[SQL]_SYSTEM@localhost:USER>

Exit out of irissqlcli session with Ctrl + D and find the query results:

[SQL]_SYSTEM@localhost:USER>                                                                                                                                     
Goodbye!
Done.
Out[2]: 
[('%DocDB', 'Database'),
 ('%ExtentMgr', 'GUID'),
 ('%ExtentMgr', 'GlobalRegistry'),
 ('%ExtentMgr_Catalog', 'Extent'),
 ('%ExtentMgr_Catalog', 'Index'),
 ('%ExtentMgr_Catalog', 'Property'),
 ('%ExtentMgr_Catalog', 'ShardIdRanges'),
 ('%SYS_Maint', 'Bitmap'),
 ('%SYS_Maint', 'BitmapResults'),
 ('%SYS_Maint', 'Bitmap_Message')]

The results are available in special local variable _, and can be assigned to a variable of your choice:

In [3]: my_result = _

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

irissqlcli-0.4.0b3.tar.gz (135.3 kB view details)

Uploaded Source

Built Distribution

irissqlcli-0.4.0b3-py3-none-any.whl (162.3 kB view details)

Uploaded Python 3

File details

Details for the file irissqlcli-0.4.0b3.tar.gz.

File metadata

  • Download URL: irissqlcli-0.4.0b3.tar.gz
  • Upload date:
  • Size: 135.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.16

File hashes

Hashes for irissqlcli-0.4.0b3.tar.gz
Algorithm Hash digest
SHA256 0ceacb80f5a413b1dca7d10cce3d5834942d739c267881a7c03ddeb4c8915705
MD5 2759a03d33fce2d45dd0d7e8970fdda7
BLAKE2b-256 3dfb89d6c47cc1373fa63a23ff8f75dae9c3ae5f57990c4131ce61996fbc4290

See more details on using hashes here.

File details

Details for the file irissqlcli-0.4.0b3-py3-none-any.whl.

File metadata

  • Download URL: irissqlcli-0.4.0b3-py3-none-any.whl
  • Upload date:
  • Size: 162.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.16

File hashes

Hashes for irissqlcli-0.4.0b3-py3-none-any.whl
Algorithm Hash digest
SHA256 3c4bab7383482b8cf5f93439fdfaae136b4fcb8952010dbebb47ffdda00ee115
MD5 f543ad3216abffb4dc9d6c787669663a
BLAKE2b-256 5606d7bfdd310cef5c6ad58c6314a67ea229a53ef5222c9f115cb79fa5e1e53f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page