todb
Dumps a stream of input records into a database.
Synopsis
bash
recs todb [options] [files...]Description
Dumps a stream of input records into a database. The record fields you want inserted should have the same keys as the column names in the database, and the records should be key-value pairs. This command will attempt to create the table if it is not already present.
Supports SQLite (default), PostgreSQL (--type pg), and MySQL (--type mysql).
PostgreSQL requires the 'pg' package. MySQL requires the 'mysql2' package.
Options
| Flag | Description |
|---|---|
--drop | Drop the table before running create/insert commands. |
--table <name> | Name of the table to work with (default: 'recs'). |
--debug | Print all the executed SQL. |
--key / -k <fields> | Fields to insert. Can be a name or a name=SQL_TYPE pair. If any fields are specified, they will be the only fields put into the db. May be specified multiple times or comma separated. Type defaults to VARCHAR(255). |
--fields / -f <fields> | Fields to insert. Can be a name or a name=SQL_TYPE pair. Alias for --key. |
--dbfile <path> | Database file path (for SQLite). |
--type <type> | Database type: sqlite (default), pg, mysql. |
--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 and mysql. |
--user <user> | Database user for authentication. |
--password <password> | Database password for authentication. |
Examples
Put all records into the recs table (SQLite)
bash
recs todb --type sqlite --dbfile testDb --table recsSpecify fields and drop existing table
bash
recs todb --dbfile testDb --drop --key status,description=TEXT --key userInsert into PostgreSQL via Unix socket
bash
recs todb --type pg --db mydb --table usersInsert into PostgreSQL with credentials
bash
recs todb --type pg --host db.example.com --port 5432 --db mydb --user admin --password secretInsert into MySQL
bash
recs todb --type mysql --host localhost --db mydb --user root --table orders