Answer the question
In order to leave comments, you need to log in
How to implement polyphorism in Go?
I have the nsql abstract package. I want to make drivers for different nosql databases. (ala analogue of the database/sql package only for nosql). How to do it right in general?
Answer the question
In order to leave comments, you need to log in
Why if there is?
https://github.com/avelino/awesome-go#database-drivers
func InitDatabase(driver, dbPath string) error {
var db gorm.DB
var err error
switch driver {
case "sqlite3":
db, err = gorm.Open("sqlite3", dbPath)
if err != nil {
return err
}
break
case "mysql":
db, err = gorm.Open("mysql", dbPath)
if err != nil {
return err
}
break
case "postgres":
db, err = gorm.Open("postgres", dbPath)
if err != nil {
return err
}
break
default:
return fmt.Errorf("Unknown database driver of %v", driver)
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question