polycule-connect/polyculeconnect/services/db/db.go

28 lines
574 B
Go
Raw Normal View History

2024-03-29 17:21:26 +00:00
package db
import (
"database/sql"
"errors"
"fmt"
"git.faercol.me/faercol/polyculeconnect/polyculeconnect/config"
)
type concreteDBService struct {
}
func connectSQLite(path string) (*sql.DB, error) {
return sql.Open("sqlite3", path)
}
func Connect(conf *config.AppConfig) (*sql.DB, error) {
switch conf.StorageType {
case string(config.Memory):
return nil, errors.New("no db for memory mode")
case string(config.SQLite):
return connectSQLite(conf.StorageConfig.File)
default:
return nil, fmt.Errorf("unsupported storage mode %q", conf.StorageType)
}
}