Skip to content

fromdb

Execute a select statement on a database and create a record stream from the results.

Synopsis

bash
recs fromdb [options]

Description

Execute a select statement on a database and create a record stream from the results. The keys of the record will be the column names and the values the row values.

Supports SQLite (default), PostgreSQL (--type pg), MySQL (--type mysql), and Oracle (--type oracle).

PostgreSQL and MySQL require the 'pg' and 'mysql2' packages respectively. Oracle requires the 'oracledb' package (optional, install with: bun add oracledb).

Options

FlagDescription
--table <table>Table name (shortcut for SELECT * FROM table).
--sql <statement>SQL select statement to run.
--dbfile <path>Path to the database file (sqlite).
--type <dbtype>Database type: sqlite (default), pg, mysql, oracle.
--host <hostname>Hostname for database connection. For pg, omit to use Unix domain socket. Required for mysql.
--port <port>Port for database connection (pg, mysql).
--db / --dbname <database>Database name. Required for pg, mysql. For oracle, this is the TNS name.
--user <user>Database user for authentication.
--password <password>Database password for authentication.

Examples

Dump a SQLite table

bash
recs fromdb --type sqlite --dbfile testDb --table recs

Run a SQLite select statement

bash
recs fromdb --dbfile testDb --sql 'SELECT * FROM recs WHERE id > 9'

Query PostgreSQL via Unix socket

bash
recs fromdb --type pg --db mydb --table users

Query PostgreSQL with host and credentials

bash
recs fromdb --type pg --host db.example.com --port 5432 --db mydb --user admin --password secret --sql 'SELECT * FROM users'

Query MySQL

bash
recs fromdb --type mysql --host localhost --db mydb --user root --table orders

Query Oracle

bash
recs fromdb --type oracle --db MYDB --user scott --password tiger --table emp

Released under the MIT License.