diff options
Diffstat (limited to 'mediaapi/storage/storage.go')
-rw-r--r-- | mediaapi/storage/storage.go | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/mediaapi/storage/storage.go b/mediaapi/storage/storage.go index 5ff114db..829d47b3 100644 --- a/mediaapi/storage/storage.go +++ b/mediaapi/storage/storage.go @@ -17,25 +17,21 @@ package storage import ( - "net/url" + "fmt" - "github.com/matrix-org/dendrite/internal/sqlutil" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/mediaapi/storage/postgres" "github.com/matrix-org/dendrite/mediaapi/storage/sqlite3" ) // Open opens a postgres database. -func Open(dataSourceName string, dbProperties sqlutil.DbProperties) (Database, error) { - uri, err := url.Parse(dataSourceName) - if err != nil { - return postgres.Open(dataSourceName, dbProperties) - } - switch uri.Scheme { - case "postgres": - return postgres.Open(dataSourceName, dbProperties) - case "file": - return sqlite3.Open(dataSourceName) +func Open(dbProperties *config.DatabaseOptions) (Database, error) { + switch { + case dbProperties.ConnectionString.IsSQLite(): + return sqlite3.Open(dbProperties) + case dbProperties.ConnectionString.IsPostgres(): + return postgres.Open(dbProperties) default: - return postgres.Open(dataSourceName, dbProperties) + return nil, fmt.Errorf("unexpected database type") } } |