/
sql_config.go
67 lines (59 loc) · 1.56 KB
/
sql_config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package eventstore
import (
"fmt"
"github.com/ThreeDotsLabs/esja"
"github.com/ThreeDotsLabs/esja/transport"
)
type SQLConfig[T any] struct {
SchemaAdapter schemaAdapter[T]
Mapper transport.Mapper[T]
Marshaler transport.Marshaler
}
func (c SQLConfig[T]) validate() error {
if c.SchemaAdapter == nil {
return fmt.Errorf("schema adapter is nil")
}
if c.Mapper == nil {
return fmt.Errorf("mapper is nil")
}
if c.Marshaler == nil {
return fmt.Errorf("marshaler is nil")
}
return nil
}
func NewPostgresSQLConfig[T any](
supportedEvents []esja.Event[T],
) SQLConfig[T] {
return SQLConfig[T]{
SchemaAdapter: NewPostgresSchemaAdapter[T](),
Mapper: transport.NewNoOpMapper[T](supportedEvents),
Marshaler: transport.JSONMarshaler{},
}
}
func NewMappingPostgresSQLConfig[T any](
supportedEvents []transport.Event[T],
) SQLConfig[T] {
return SQLConfig[T]{
SchemaAdapter: NewPostgresSchemaAdapter[T](),
Mapper: transport.NewDefaultMapper[T](supportedEvents),
Marshaler: transport.JSONMarshaler{},
}
}
func NewSQLiteConfig[T any](
supportedEvents []esja.Event[T],
) SQLConfig[T] {
return SQLConfig[T]{
SchemaAdapter: NewSQLiteSchemaAdapter[T](),
Mapper: transport.NewNoOpMapper[T](supportedEvents),
Marshaler: transport.JSONMarshaler{},
}
}
func NewMappingSQLiteConfig[T any](
supportedEvents []transport.Event[T],
) SQLConfig[T] {
return SQLConfig[T]{
SchemaAdapter: NewSQLiteSchemaAdapter[T](),
Mapper: transport.NewDefaultMapper[T](supportedEvents),
Marshaler: transport.JSONMarshaler{},
}
}