Push csv/tsv data to database
Database | Driver |
---|---|
postgresql | github.com/lib/pq |
mongodb | gopkg.in/mgo.v2 |
mysql | github.com/go-sql-driver/mysql |
sqlserver | github.com/denisenkom/go-mssqldb |
sqlite3 | github.com/mattn/go-sqlite3 |
go install github.com/eirannejad/pushcsv
Build process on Windows requires gcc
to support compiling the sqlite3 libraries. Therefore binaries are provided for convenience under Releases. Compiled pushcsv
binaries can be installed on Windows using Chocolatey package manager as well.
choco install pushcsv
Examples of pushing users.csv
into table (collection in case of mongodb) users
on supported databases:
$ pushcsv postgres://user:[email protected]/mydb users ~/users.csv --headers --purge
$ pushcsv mongodb://user:pass@localhost:27017/mydb users ~/users.csv --map=name:fullname --map=email:userid
$ pushcsv "mysql:user:pass@tcp(localhost:3306)/tests" users ~/users.csv --purge --map=name:fullname --map=email:userid
$ pushcsv sqlserver://user:[email protected]?database=mydb users ~/users.csv --purge --map=name:fullname --map=email:userid
$ pushcsv sqlite3:data.db users ~/users.csv
$ git clone [email protected]:eirannejad/pushcsv.git
$ cd pushcsv
$ go get -u ./...
$ go install .
$ pushcsv --help
To reduce the size of pushcsv compiled binary, install with -ldflags "-w"
option.
go install -ldflags "-w" .