mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-18 04:13:10 -06:00
The general idea here is to have the wasm build have a `NewXXXDatabase` that doesn't import any postgres package and hence we never import `lib/pq`, which doesn't work under WASM (undefined `userCurrent`).
27 lines
707 B
Go
27 lines
707 B
Go
// +build !wasm
|
|
|
|
package devices
|
|
|
|
import (
|
|
"net/url"
|
|
|
|
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices/postgres"
|
|
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices/sqlite3"
|
|
"github.com/matrix-org/gomatrixserverlib"
|
|
)
|
|
|
|
func NewDatabase(dataSourceName string, serverName gomatrixserverlib.ServerName) (Database, error) {
|
|
uri, err := url.Parse(dataSourceName)
|
|
if err != nil {
|
|
return postgres.NewDatabase(dataSourceName, serverName)
|
|
}
|
|
switch uri.Scheme {
|
|
case "postgres":
|
|
return postgres.NewDatabase(dataSourceName, serverName)
|
|
case "file":
|
|
return sqlite3.NewDatabase(dataSourceName, serverName)
|
|
default:
|
|
return postgres.NewDatabase(dataSourceName, serverName)
|
|
}
|
|
}
|