mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-08-02 14:12:47 +00:00
Add push server component template
This commit is contained in:
parent
092edee210
commit
6843c3beee
22 changed files with 487 additions and 0 deletions
7
pushserver/storage/interface.go
Normal file
7
pushserver/storage/interface.go
Normal file
|
@ -0,0 +1,7 @@
|
|||
package storage
|
||||
|
||||
import "github.com/matrix-org/dendrite/internal"
|
||||
|
||||
type Database interface {
|
||||
internal.PartitionStorer
|
||||
}
|
31
pushserver/storage/postgres/storage.go
Normal file
31
pushserver/storage/postgres/storage.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package postgres
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/pushserver/storage/shared"
|
||||
"github.com/matrix-org/dendrite/setup/config"
|
||||
)
|
||||
|
||||
type Database struct {
|
||||
shared.Database
|
||||
sqlutil.PartitionOffsetStatements
|
||||
}
|
||||
|
||||
func Open(dbProperties *config.DatabaseOptions) (*Database, error) {
|
||||
var d Database
|
||||
var err error
|
||||
if d.DB, err = sqlutil.Open(dbProperties); err != nil {
|
||||
return nil, fmt.Errorf("sqlutil.Open: %w", err)
|
||||
}
|
||||
d.Writer = sqlutil.NewDummyWriter()
|
||||
|
||||
if err = d.PartitionOffsetStatements.Prepare(d.DB, d.Writer, "pushserver"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Create the tables.
|
||||
|
||||
return &d, nil
|
||||
}
|
12
pushserver/storage/shared/storage.go
Normal file
12
pushserver/storage/shared/storage.go
Normal file
|
@ -0,0 +1,12 @@
|
|||
package shared
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
)
|
||||
|
||||
type Database struct {
|
||||
DB *sql.DB
|
||||
Writer sqlutil.Writer
|
||||
}
|
31
pushserver/storage/sqlite3/storage.go
Normal file
31
pushserver/storage/sqlite3/storage.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package sqlite3
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/pushserver/storage/shared"
|
||||
"github.com/matrix-org/dendrite/setup/config"
|
||||
)
|
||||
|
||||
type Database struct {
|
||||
shared.Database
|
||||
sqlutil.PartitionOffsetStatements
|
||||
}
|
||||
|
||||
func Open(dbProperties *config.DatabaseOptions) (*Database, error) {
|
||||
var d Database
|
||||
var err error
|
||||
if d.DB, err = sqlutil.Open(dbProperties); err != nil {
|
||||
return nil, fmt.Errorf("sqlutil.Open: %w", err)
|
||||
}
|
||||
d.Writer = sqlutil.NewExclusiveWriter()
|
||||
|
||||
if err = d.PartitionOffsetStatements.Prepare(d.DB, d.Writer, "pushserver"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Create the tables.
|
||||
|
||||
return &d, nil
|
||||
}
|
23
pushserver/storage/storage.go
Normal file
23
pushserver/storage/storage.go
Normal file
|
@ -0,0 +1,23 @@
|
|||
// +build !wasm
|
||||
|
||||
package storage
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/matrix-org/dendrite/pushserver/storage/postgres"
|
||||
"github.com/matrix-org/dendrite/pushserver/storage/sqlite3"
|
||||
"github.com/matrix-org/dendrite/setup/config"
|
||||
)
|
||||
|
||||
// Open opens a database connection.
|
||||
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 nil, fmt.Errorf("unexpected database type")
|
||||
}
|
||||
}
|
20
pushserver/storage/storage_wasm.go
Normal file
20
pushserver/storage/storage_wasm.go
Normal file
|
@ -0,0 +1,20 @@
|
|||
package storage
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/matrix-org/dendrite/pushserver/storage/sqlite3"
|
||||
"github.com/matrix-org/dendrite/setup/config"
|
||||
)
|
||||
|
||||
// NewDatabase opens a new database
|
||||
func Open(dbProperties *config.DatabaseOptions) (Database, error) {
|
||||
switch {
|
||||
case dbProperties.ConnectionString.IsSQLite():
|
||||
return sqlite3.Open(dbProperties)
|
||||
case dbProperties.ConnectionString.IsPostgres():
|
||||
return nil, fmt.Errorf("can't use Postgres implementation")
|
||||
default:
|
||||
return nil, fmt.Errorf("unexpected database type")
|
||||
}
|
||||
}
|
1
pushserver/storage/tables/interface.go
Normal file
1
pushserver/storage/tables/interface.go
Normal file
|
@ -0,0 +1 @@
|
|||
package tables
|
Loading…
Add table
Add a link
Reference in a new issue