Skip to content

Commit

Permalink
feat(db) : newSQLinserter method
Browse files Browse the repository at this point in the history
  • Loading branch information
seipan committed Oct 27, 2023
1 parent 438c2bb commit 60bd67d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions lib/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,16 @@ func Exec(config Config) error {
return nil
}

func newSQLInserter(dbtype string) (query.Inserter, error) {
func newSQLInserter(dbtype string, tablename string, db *sql.DB) (query.Inserter, error) {
switch dbtype {
case "mysql":
return &mysql.MySQLInserter{}, nil
return mysql.NewMySQLInserter(tablename, db), nil
case "sqlite":
return &sqlite.SQLiteInserter{}, nil
return sqlite.NewSQLiteInserter(tablename, db), nil
case "postgresql":
return postgresql.NewPostgresSQLInserter(tablename, db), nil
case "mariadb":
return mariadb.NewMariaDBInserter(tablename, db), nil
default:
return nil, fmt.Errorf("invalid dbtype: %s", dbtype)
}
Expand Down
2 changes: 1 addition & 1 deletion mariadb/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (i *MariaDBSQLInserter) Insert() error {
return nil
}

func NewMariaDBSQLInserter(tableName string, db *sql.DB) query.Inserter {
func NewMariaDBInserter(tableName string, db *sql.DB) query.Inserter {
return &MariaDBSQLInserter{
tableName: tableName,
db: db,
Expand Down

0 comments on commit 60bd67d

Please sign in to comment.