Package: redasql
RedaSQLRedaSQL is querying tool for redash.
I likepsql(PostgreSQL CLI). so redasql resemble psql in some respects.Installpipinstallredasqlsupported readsh versionRedaSQL supports Redash v8, v9 and v10.RedaSQL supports Redash v8, v9 and v10.How To Useredasql need some arguments or environment variables.
redasql prioritizes arguments over environment variables.argumentenvmeanrequired-k/--api-keyREDASQL_REDASH_APIKEYAPI KEY(user api key)True-s/--server-hostREDASQL_REDASH_ENDPOINTRedash server hostname. ex)https://your.redash.server.host/True-p/--proxyREDASQL_HTTP_PROXYif your redash server restricted by Proxy, set url format. ex)http://user:pass@your.proxy.server:proxy-portFalse-d/--data-sourceNoneinitial connect datasource name.False--ignore-rcNoneignore.redasqlrcfileFalse(default false)--wait-interval-secNoneWait Job Pooling Interval SecFalse(default 0.1)--timeout-countNoneWait Job Pooling Count(int)False(default 600)--debugNonedebug modeFalse(default false)if you want to use redasql with direnv, rename.envrc.sampleto.envrcand set attributes.special commandsredasql has management commands.metadata=# \?
\?: HELP META COMMANDS.
\q: EXIT.
\d: DESCRIBE TABLE
\c: SELECT DATASOURCE.
\x: QUERY RESULT TOGGLE PIVOT.
\f: CHANGE RESULT FORMATTER ['table', 'markdown', 'markdown_with_sql', 'csv'].
\l: LOAD QUERY FROM REDASH.
\o: CHANGE THE OUTPUT DESTINATION TO ['stdout', 'stdout_and_clipboard', 'file'].
\i: LOAD QUERY FROM LOCAL FILE.execute querysee belowstart$ redasql

 ____          _       ____   ___  _     
|  _ \ ___  __| | __ _/ ___| / _ \| |    
| |_) / _ \/ _` |/ _` \___ \| | | | |    
|  _ <  __/ (_| | (_| |___) | |_| | |___ 
|_| \_\___|\__,_|\__,_|____/ \__\_\_____|

    - redash query cli tool -

SUCCESS CONNECT
- server version 8.0.0+b32245
- client version 0.1.0

(No DataSource)=#connect datasourceuse\c data_source_name. if not provide data_source_name, show all available data sources.(No DataSource)=# \c metadata
metadata=#describe tableuse\d table_name. if not provide table_name, show all table names. if provide table_name with wildcard(*), show describe matched tables.metadata=# \d
access_permissions
alembic_version
:
queries
query_results
query_snippets
users
visualizations
widgets
metadata=# \d queries
## queries
- schedule
- updated_at
- api_key
- name
- id
- version
- is_draft
- query
- is_archived
- tags
- last_modified_by_id
- org_id
- options
- query_hash
- description
- latest_query_data_id
- search_vector
- data_source_id
- schedule_failures
- created_at
- user_id
metadata=# \d query_*
## query_results
- id
- data
- org_id
- query_hash
- data_source_id
- runtime
- query
- retrieved_at
## query_snippets
- updated_at
- id
- description
- created_at
- user_id
- trigger
- snippet
- org_idexecute queryenter your SQL and semicolon.metadata=# select count(*) from queries;+-------+|count|+-------+|3606|+-------+1rowreturned.
Time:0.0159s\xpivot result.metadata=# \x
set pivoted [True]

metadata=# select id, user_id from queries limit 3;
-[RECORD 1]-------
     id: 543
user_id: 40
-[RECORD 2]-------
     id: 717
user_id: 40
-[RECORD 3]-------
     id: 515
user_id: 38


3 rows returned.
Time: 0.0281sformatsredasql support many formats.\f <format_name>and\xtable format(default)metadata=# select id, object_id, org_id, created_at from favorites limit 3;

+------+-------------+----------+--------------------------+
|   id |   object_id |   org_id | created_at               |
|------+-------------+----------+--------------------------|
|    2 |         513 |        1 | 2019-05-22T05:30:17.185Z |
|    3 |         514 |        1 | 2019-05-22T05:30:19.031Z |
|    4 |         230 |        1 | 2019-05-22T08:17:12.693Z |
+------+-------------+----------+--------------------------+

3 rows returned.
Time: 0.0219stable format(pivoted)metadata=# select id, object_id, org_id, created_at from favorites limit 3;

-[RECORD 1]----------
        id| 2
 object_id| 513
    org_id| 1
created_at| 2019-05-22T05:30:17.185Z
-[RECORD 2]----------
        id| 3
 object_id| 514
    org_id| 1
created_at| 2019-05-22T05:30:19.031Z
-[RECORD 3]----------
        id| 4
 object_id| 230
    org_id| 1
created_at| 2019-05-22T08:17:12.693Z


3 rows returned.
Time: 0.0223smarkdownmetadata=# \f markdown
set formatter [markdown]
metadata=# select id, object_id, org_id, created_at from favorites limit 3;

|   id |   object_id |   org_id | created_at               |
|------|-------------|----------|--------------------------|
|    2 |         513 |        1 | 2019-05-22T05:30:17.185Z |
|    3 |         514 |        1 | 2019-05-22T05:30:19.031Z |
|    4 |         230 |        1 | 2019-05-22T08:17:12.693Z |

3 rows returned.
Time: 0.0207smarkdown(pivoted)metadata=# select id, object_id, org_id, created_at from favorites limit 3;

| colum_name   | value                    |
|--------------|--------------------------|
| created_at   | 2019-05-22T05:30:17.185Z |
| org_id       | 1                        |
| id           | 2                        |
| object_id    | 513                      |
| -----        | -----                    |
| created_at   | 2019-05-22T05:30:19.031Z |
| org_id       | 1                        |
| id           | 3                        |
| object_id    | 514                      |
| -----        | -----                    |
| created_at   | 2019-05-22T08:17:12.693Z |
| org_id       | 1                        |
| id           | 4                        |
| object_id    | 230                      |

3 rows returned.
Time: 0.0106smarkdown_with_sql```sql
select id, object_id, org_id, created_at from favorites limit 3;
``` .

|   id |   object_id |   org_id | created_at               |
|------|-------------|----------|--------------------------|
|    2 |         513 |        1 | 2019-05-22T05:30:17.185Z |
|    3 |         514 |        1 | 2019-05-22T05:30:19.031Z |
|    4 |         230 |        1 | 2019-05-22T08:17:12.693Z |

3 rows returned.
Time: 0.0253scsvmetadata=# \f csv
set formatter [csv]
metadata=# select id, object_id, org_id, created_at from favorites limit 3;

id,object_id,org_id,created_at
2,513,1,2019-05-22T05:30:17.185Z
3,514,1,2019-05-22T05:30:19.031Z
4,230,1,2019-05-22T08:17:12.693Zchange output typestdout(default)result to stdout only.metadata=# \o stdout
set output [stdout]stdout_with_clipboardresult to stdout and clipboard.metadata=# \o stdout_and_clipboard
set output [stdout_and_clipboard]fileresult to stdout and File.metadata=# \o file /tmp/result.txt
set output [file(/tmp/result.txt)]run sqlfile\irun local sqlfile.metadata=# \i test.sql
select count(*) from queries;

+---------+
|   count |
|---------|
|    3876 |
+---------+

1 row returned.
Time: 0.018squitctrl + Dor\qquit redasql.metadata=# \q                                                                                                                                                                        
Sayonara!.redasqlrcif you create~/.redasqlrc, redasql reads the file at startup and performs initial settings.Contributionrun teststart up containers (redash, MySQL, postgresql)unittest necessary redash test server. use docker-compose.yml in./tests/docker/v{REDAHS_VERSION}8.0.2.b377479.0.0-beta.b4950910.0.0.b50363$cd./tests/docker/v8.0.2.b37747
$docker-composeup-drun test$python-munittestdiscover-stests/