feat: Add support for Postgres

There aren't many connection string examples for the postgres GORM
driver, so a couple extra links are referenced.
Most changes to go.mod and go.sum are automated changes as a result of
running go mod tidy.
This commit is contained in:
Rafael Espinoza 2023-05-29 12:45:14 -07:00
parent 551a706358
commit e2fbfbb28a
4 changed files with 39 additions and 63 deletions

View file

@ -14,6 +14,7 @@ import (
"github.com/pushbits/server/internal/model"
"gorm.io/driver/mysql"
"gorm.io/driver/postgres"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
@ -51,6 +52,8 @@ func Create(cm *credentials.Manager, dialect, connection string) (*Database, err
db, err = gorm.Open(sqlite.Open(connection), &gorm.Config{})
case "mysql":
db, err = gorm.Open(mysql.Open(connection), &gorm.Config{})
case "postgres":
db, err = gorm.Open(postgres.Open(connection), &gorm.Config{})
default:
message := "Database dialect is not supported"
return nil, errors.New(message)