-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.go
41 lines (32 loc) · 854 Bytes
/
db.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
package database
import (
"context"
"github.com/zeiss/typhoon/internal/accounts/ports"
"github.com/zeiss/typhoon/internal/api/models"
seed "github.com/zeiss/gorm-seed"
"gorm.io/gorm"
)
var _ ports.ReadTx = (*readTxImpl)(nil)
type readTxImpl struct {
conn *gorm.DB
}
// GetToken is returning a token.
func (r *readTxImpl) GetToken(ctx context.Context, token *models.Token) error {
return r.conn.WithContext(ctx).Where(token).First(token).Error
}
// NewReadTx ...
func NewReadTx() seed.ReadTxFactory[ports.ReadTx] {
return func(db *gorm.DB) (ports.ReadTx, error) {
return &readTxImpl{conn: db}, nil
}
}
type writeTxImpl struct {
conn *gorm.DB
readTxImpl
}
// NewWriteTx ...
func NewWriteTx() seed.ReadWriteTxFactory[ports.ReadWriteTx] {
return func(db *gorm.DB) (ports.ReadWriteTx, error) {
return &writeTxImpl{conn: db}, nil
}
}