migrate to postgres
This commit is contained in:
@@ -5,25 +5,23 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
_ "modernc.org/sqlite"
|
||||
_ "github.com/lib/pq"
|
||||
)
|
||||
|
||||
const driver = "sqlite"
|
||||
const driver = "postgres"
|
||||
|
||||
func Connect() (*sql.DB, error) {
|
||||
path := os.Getenv("DB_PATH")
|
||||
if path == "" {
|
||||
path = "vaultdrop.db"
|
||||
dsn := os.Getenv("DATABASE_URL")
|
||||
if dsn == "" {
|
||||
dsn = "postgres://localhost:5432/vaultdrop?sslmode=disable"
|
||||
}
|
||||
|
||||
dsn := fmt.Sprintf("file:%s?_journal_mode=WAL&_busy_timeout=5000&_foreign_keys=on", path)
|
||||
|
||||
database, err := sql.Open(driver, dsn)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("open db: %w", err)
|
||||
}
|
||||
|
||||
database.SetMaxOpenConns(1)
|
||||
database.SetMaxOpenConns(25)
|
||||
|
||||
if err := database.Ping(); err != nil {
|
||||
return nil, fmt.Errorf("ping db: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user