mirror of
https://github.com/getAlby/lndhub.go.git
synced 2026-01-21 05:46:32 +01:00
* remove cmd folder as we are going to have only one entrypoint * get rid of pkg directory * rename test -> integration_tests as unit tests should reside next to the actual files they are testing * database migration WIP * reinstate gorm boilerplate in the addinvoice for now to make it compile * introduce migrations * add Makefile * don't use unsigned types for database mappings * migrations work now * add build target * use echo groups * gorm removed * add envconfig * fix comments
30 lines
647 B
Go
30 lines
647 B
Go
package db
|
|
|
|
import (
|
|
"database/sql"
|
|
"strings"
|
|
|
|
"github.com/uptrace/bun"
|
|
"github.com/uptrace/bun/dialect/pgdialect"
|
|
"github.com/uptrace/bun/dialect/sqlitedialect"
|
|
"github.com/uptrace/bun/driver/pgdriver"
|
|
"github.com/uptrace/bun/driver/sqliteshim"
|
|
)
|
|
|
|
func Open(dsn string) (*bun.DB, error) {
|
|
var db *bun.DB
|
|
switch {
|
|
case strings.HasPrefix(dsn, "postgres"):
|
|
dbConn := sql.OpenDB(pgdriver.NewConnector(pgdriver.WithDSN(dsn)))
|
|
db = bun.NewDB(dbConn, pgdialect.New())
|
|
default:
|
|
dbConn, err := sql.Open(sqliteshim.ShimName, dsn)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
db = bun.NewDB(dbConn, sqlitedialect.New())
|
|
}
|
|
|
|
return db, nil
|
|
}
|