db-improt-tool is a Go application designed to read data from an Excel file and insert it into a specified database table. It supports both PostgreSQL and MySQL databases, and automatically handles inserting data without hardcoding table structures.
- Supports PostgreSQL and MySQL databases.
- Reads data from an Excel file.
- Dynamically generates SQL insert statements based on the table headers.
- Ignores empty fields during insertion.
- Allows disabling SSL for PostgreSQL connections.
- Go 1.16 or higher
- PostgreSQL or MySQL database
Clone the repository:
git clone https://github.com/litongjava/db-improt-tool.git
cd db-improt-tool
Install the dependencies:
go get -u github.com/xuri/excelize/v2
go get -u github.com/cloudwego/hertz/pkg/common/hlog
go get -u github.com/go-sql-driver/mysql
go get -u github.com/lib/pq
Compile the program:
go build -o db-improt-tool main.go
Run the program with the required parameters:
./db-improt-tool -dsn="your_database_dsn" -excel="path_to_your_excel_file.xlsx" -table="your_table_name"
For PostgreSQL:
./db-improt-tool -dsn="postgresql://username:password@127.0.0.1:15432/dbname?sslmode=false" -excel="path_to_your_excel_file.xlsx" -table="your_table_name"
For MySQL:
./db-improt-tool -dsn="your_mysql_dsn" -excel="path_to_your_excel_file.xlsx" -table="your_table_name"
-dsn
: The Data Source Name (DSN) for the database connection. The format depends on the database type.-excel
: The file path to the Excel file containing the data to be inserted.-table
: The name of the database table where the data will be inserted.
main.go
: Main application logic including initialization, database connection, reading Excel data, and inserting data into the database.
from https://github.com/litongjava/db-improt-tool
------
单词明显是写错了,应该为 db-import-tool
No comments:
Post a Comment