xo / usql

Universal command-line interface for SQL databases
MIT License
8.92k stars 351 forks source link

(new) copying between databases? #473

Closed ghost closed 1 month ago

ghost commented 3 months ago

hey there!

I use usql a lot in testing environments and for personal projects. I wonder if we can't have something similar to ingestr(ingestr is a CLI tool to copy data between any databases with a single command seamlessly) in a simple way. I'm going to transcribe what I read from the documentation, and then ask something technical that I didn't find and that I consider important to ask.

"Copying Between Databases usql provides a \copy command that reads data from a source database DSN and writes to a destination database DSN:

(not connected)=> \cset PGDSN postgres://user:pass@localhost (not connected)=> \cset MYDSN mysql://user:pass@localhost (not connected)=> \copy PGDSN MYDSN 'select book_id, author_id from books' 'books(id, author_id)'

As demonstrated above, the \copy command does not require being connected to a database, and will not modify or change the current open database connection or state.

Why do I need to type so many sql commands when I could simply copy the database from one location to another if I just had to add their url or single command seamlessly? are pull requests about this welcome? would something similar to this be good for usql?

usql \copy 
    --source-uri 'postgresql://admin:admin@localhost:8837/web?sslmode=disable' \
    --source-table 'public.some_data' \
    --dest-uri 'bigquery://<your-project-name>?credentials_path=/path/to/service/account.json' \
    --dest-table 'usql-copy.some_data'

regards,

kenshaw commented 3 months ago

@stokebreakup we would be interested in a more robust/better implementation. Please feel free to make a PR and we'll consider it.