#postgresql #sql-database #sql #copy #command-line-tool

app copgy

CLI utility tool for copying data between and executing SQL on PostgreSQL databases

8 releases

0.2.6 May 26, 2024
0.2.5 Jan 29, 2024
0.1.0 Jan 18, 2024

#852 in Command line utilities

Download history 3/week @ 2024-02-26 50/week @ 2024-04-01 109/week @ 2024-05-20 38/week @ 2024-05-27

147 downloads per month

MIT license

15KB
329 lines

copgy

copgy is a CLI utility tool for copying data between and executing SQL on PostgreSQL databases.

Warning

Employ the readonly user approach when engaging with production databases to prevent inadvertent data loss.

Features

  • copy data using a single query
  • copy data using a script json file
  • copy data & execute SQL using a script json file

Installation

cargo install copgy

Usage

Single

copgy --source-db-url postgresql://host:5432/postgres --dest-db-url postgresql://host:5432/postgres single --source_sql select * from employees --dest_table employees_tmp

Script

copgy --source-db-url postgresql://host:5432/postgres --dest-db-url postgresql://host:5432/postgres script --file-path ~/Desktop/copgy.json

sample copgy.json

[
  {
    // execute on source db
    "execute": {
      "source_sql": "update employees set first_name = 'copgy' where emp_no = 0"
    }
  },
  {
    // execute on destination db
    "execute": {
      "dest_sql": "truncate employees_tmp"
    }
  },
  {
    // copy from source db to destination db
    "copy": {
      "source_sql": "select * from employees",
      "dest_table": "employees_tmp"
    }
  }
]

Info

Sample PostgreSQL connection string

postgresql://username:password@host:port/dbname

License

MIT

Dependencies

~11–23MB
~371K SLoC