https://github.com/amboxer21/insertable
Convert a select query into an insertable mysql command.
https://github.com/amboxer21/insertable
linux mysql ruby
Last synced: about 2 months ago
JSON representation
Convert a select query into an insertable mysql command.
- Host: GitHub
- URL: https://github.com/amboxer21/insertable
- Owner: amboxer21
- License: gpl-3.0
- Created: 2021-06-22T23:45:00.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-06-23T19:03:36.000Z (about 5 years ago)
- Last Synced: 2025-08-01T01:09:49.368Z (11 months ago)
- Topics: linux, mysql, ruby
- Language: Ruby
- Homepage:
- Size: 37.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Insertable
Convert a MySQL select query into a chain of insertable mysql commands. This is my version of the mysqldump `--where` command line argument.
---
Take the output of the program and put it into a file like so
```javascript
mysql -f -uusername -p'password' database << EOF
program output goes here
EOF
```
**Example query:**
```javascript
INSERTABLE_ENV=production ruby Insertable.rb -q"select * from cars where created_at > '2021-04-06 00:00:00' and created_at < '2021-04-06 23:59:59' and make = 'nissan' order by id desc limit 2" -tcars --fields id,model --without-id
```
**Example:**
> **-f** is for force. Remove this if you're absolutely not sure that this is what you want!
```javascript
mysql -f -uusername -p'password' database << EOF
insert into cars (created_at,make, model) values ('nissan', 'rogue', '2021-04-06 11:46:28');
insert into cars (created_at,make, model) values ('nissan', 'Murano', '2021-04-06 11:54:12');
EOF
```
Then execute that file containing your insertables with:
```javascript
chmod +x file
./file
```
**Usage:**
```javascript
Usage example: ruby Insertable.rb -q'select * from cdrs limit 10' -tcars --fields make, model --without-id
[ Option with * is mandatory! ]
Option:
--help, Display this help messgage.
* Option:
--table, -t, The name of the table that you are querying.
* Option:
--mysql-query, -q, MySQL query for the program to parse without ; or G terminator.
Option:
--without-id, Remove the id field name and the id from the printed insertable.
* Option:
--fields f1,f2 This is the first and last field of the specified table that you are querying.
```