Wiki

Clone wiki

SASqlConsole / Home

SASqlConsole

An extended but sensible generic SQL prompt built on SQLAlchemy and thus supports any database backend supported by SQLAlchemy providing a consistent interface across each.

This project was forked originally from http://codeflow.org/projects/sqlalchemy_console - we seemed to be going in different directions so you might want to check that out too to see if it's better suited to your needs.

Thanks to Clovis Fabricio for his work on the project.

Dependencies

Features

  • Pretty colours
  • Tab completion for the entire table and column namespace and "all" SQL keywords.
  • ".ta" and ".sc table" sqlite-esque introspection that works consistently on all backends.
  • ".i" will take you into an interactive Python console with the SQLAlchemy objects available in the local namespace.
  • ".csv /path/to/foo.csv select ......." will dump the results to a csv file, with column names.
  • ".limit" to enable/disable/set the row limit of output.
  • ".source foo.sql" to source an external file and execute it. Also detects non-tty stdin.
  • Persistent (i.e. stored on disk in ~/.sasql_history) readline history.
  • Clever dynamic column resizing to display as much data as possible on the screen.
  • Optional automatic limit of output rows (defaults to 100).
  • Aliases can be stored in a config file for easy loading of URIs, e.g. "sasql myalias"
  • Time information: You can have time information, just set show_time to True in the config file (it's on by default)

Config File

The defaults are in sasqlconsole/config.py. Will look by default for a file named ~/.sasqlrc, or specify --rcfile for an alternate path.

# Save readline history here (set to None for no saving):
history_file = "~/.sqlac_history"

# Maximum number of rows to output (set to None for no limit)
max_rows = 100

# Enable/disable coloured output
color = True

# Enable/disable time information on queries
show_time = True

# Use available colours:
#   cyan, red, green, brown, blue, lightgray, purple, black, lightcyan,
#   lightred, lightgreen, yellow, lightblue, white, lightpurple, darkgray,
#   default (your terminal's default colour)
colors = {
    'info': 'cyan',
    'error': 'lightred',
    'message': 'green',
    'header': 'yellow',
    'column1': 'green',
    'column2': 'lightblue',
}

# Aliases should be a dict in the following form and will be accepted as
# command line arguments for loading a connection:
aliases = {
#     'somedb': 'sqlite:////some/sqlite/db.sqlite',
#     'anotherdb': 'postgres://me:password@server/db',
# This will be used if no url/alias is given in command line:
     'default': 'sqlite://', 
}

Updated