Skip to main content

Display a quick view of sql databases (and make quick edits)

Project description

[![Build Status](https://travis-ci.org/paulfitz/catsql.svg?branch=master)](https://travis-ci.org/paulfitz/catsql)

catsql
======

A `cat` for SQL databases.

Installation
------------

`pip install catsql`

Examples
--------

`catsql example.sqlite`

Prints contents of entire database. Suitable for small databases.

`catsql $DATABASE_URL --color green`

Print row(s) with column `color` equal to `green` in any table.
On large databases, it would be a good idea to specify the table(s) to
look in, but on smaller databases it is convenient to let `catsql`
figure that out. Tables without a column called `color` will be
omitted from search.

`catsql $DATABASE_URL --grep paul`

Search for `paul` across the entire database. Search is done on the
database server so only results are transmitted across network.

`catsql $DATABASE_URL --table users`

Print a single named table from the database. When the table is specified,
a step of probing all tables in the database can be skipped, speeding things
up.

`catsql $DATABASE_URL --count`

Prints number of rows in each table of the database. Suitable for medium
size databases.

`catsql $DATABASE_URL --limit 3`

Print 3 rows from every table in the database. Suitable for medium
databases.

`catsql $DATABASE_URL --table users --id 20`

Print row(s) with column `id` (or any other name) equal to 20 in the
table called `users`. This is usable on large databases. The `--id
20` filter can also be written as `--value id=20`. This form is useful
for columns whose name collides with another parameter of `catsql`.

`catsql $DATABASE_URL --table users --grep paul`

Search all columns in the `users` table for the (case-insensitive)
sequence `paul`. The search is done by a SQL query on the database
server, but is nevertheless a relatively expensive operation - best for
small to medium databases.

`catsql $DATABASE_URL --grep paul --csv`

Output strictly in csv format, useful for piping into other tools
such as `csvlook` in the `csvkit` package.

`catsql $DATABASE_URL --sql "total < 1000"`

Return rows matching a SQL condition across entire database. Tables for
whih the condition makes no sense are omitted. Can be combined with
all other flags, such as specifying the table(s), column values, etc.

`catsql $DATABASE_URL --table users --grep paul --edit`

Edit whatever slice of the database you are viewing using your default
`$EDITOR`. Only a single table can be edited at a time, since it is
edited strictly in CSV format, which is a single-table format.

`catsql $DATABASE_URL --column id,first_name`

Show just the `id` and `first_name` columns of any tables that have both
those columns.

Demo
----

![Terminal demo](https://cloud.githubusercontent.com/assets/118367/13240849/048e2834-d9b4-11e5-9510-7812f2fc1b71.gif)

Usage
-----

```
usage: main.py [-h] [--column COLUMN] [--count] [--csv] [--distinct] [--edit]
[--grep GREP] [--json JSON] [--limit LIMIT] [--load-bookmark]
[--output OUTPUT] [--safe-null] [--save-bookmark SAVE_BOOKMARK]
[--sql SQL] [--table TABLE] [--terse] [--types] [--value VALUE]
[--verbose] [--order ORDER]
catsql_database_url

Quickly display and edit a slice of a database.

positional arguments:
catsql_database_url Database url or filename. Examples: sqlite:///data.db,
mysql://user:pass@host/db,
postgres[ql]://user:pass@host/db, data.sqlite3

optional arguments:
-h, --help show this help message and exit
--column COLUMN Column to include (defaults to all columns). Can be a
comma separated list of multiple columns.
--count Show row counts instead of actual data.
--csv Output strictly in CSV format. Only one table can be
shown.
--distinct Show distinct rows only, hiding duplicates.
--edit Edit original table in your favorite editor. Respects
$EDITOR environment variable.
--grep GREP Search cells for occurrence of a text fragment.
Translated to SQL query, performed by database.
--json JSON Save results to a json file. Only one table allowed.
--limit LIMIT Maximum number of rows per table.
--load-bookmark Load a set of filters from a file.
--output OUTPUT Save output to specified file. Incompatible with
--edit.
--safe-null Encode nulls in a reversible way.
--save-bookmark SAVE_BOOKMARK
Save the current set of filters specified to a file.
--sql SQL Add a raw SQL filter for rows to include. Example:
"total < 1000", "created_at > now() - interval '1
day'". Tables that don't have the columns mentioned
are omitted.
--table TABLE Table to include (defaults to all tables). Can be a
comma separated list of multiple tables.
--terse Hide any columns with predetermined values.
--types Show column types instead of actual data.
--value VALUE Add a column=value filter. Example:
--value id=ID --value name=Jupiter
As a shortcut you can also do:
--id ID --name Jupiter
--verbose Show raw SQL queries as they are made.
--order ORDER Columns to order by. Can be a comma separated list of
columns names. Add + or - to end of name to specify
ascending or descending order. Specify "none" to
disable ordering completely (by default we always try
to apply some order)
```

License
-------

MIT

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

catsql-0.2.14.tar.gz (10.6 kB view details)

Uploaded Source

File details

Details for the file catsql-0.2.14.tar.gz.

File metadata

  • Download URL: catsql-0.2.14.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for catsql-0.2.14.tar.gz
Algorithm Hash digest
SHA256 0a81d157dc85c1b1d1a6c8b4316e560ba298ac53f38742f10432866754b9a63a
MD5 a5d8decd00806d0d28f6e9bb02e305e2
BLAKE2b-256 0f76817990217969bca799f4f6e92eb2dc1d7a9bdbf9f72cd24450f02a401a4c

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