mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-29 16:06:16 -06:00
return error instead of panic on sql.Open("sqlite")
Signed-off-by: kim (grufwub) <grufwub@gmail.com>
This commit is contained in:
parent
4ed448662e
commit
5747af915e
1 changed files with 6 additions and 10 deletions
|
|
@ -90,7 +90,12 @@ func NewBunDBService(ctx context.Context, c *config.Config, log *logrus.Logger)
|
|||
conn = bun.NewDB(sqldb, pgdialect.New())
|
||||
case dbTypeSqlite:
|
||||
// SQLITE
|
||||
sqldb = mustOpenSQLite(c.DBConfig.Address)
|
||||
var err error
|
||||
|
||||
sqldb, err = sql.Open("sqlite", c.DBConfig.Address)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not open sqlite db: %s", err)
|
||||
}
|
||||
conn = bun.NewDB(sqldb, sqlitedialect.New())
|
||||
|
||||
if strings.HasPrefix(strings.TrimPrefix(c.DBConfig.Address, "file:"), ":memory:") {
|
||||
|
|
@ -283,15 +288,6 @@ func deriveBunDBPGOptions(c *config.Config) (*pgx.ConnConfig, error) {
|
|||
return cfg, nil
|
||||
}
|
||||
|
||||
// mustOpenSQLite opens an SQLite sql.DB instance, panicking on error (indicates missing import)
|
||||
func mustOpenSQLite(dataSrc string) *sql.DB {
|
||||
db, err := sql.Open("sqlite", dataSrc)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return db
|
||||
}
|
||||
|
||||
/*
|
||||
CONVERSION FUNCTIONS
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue