-
Notifications
You must be signed in to change notification settings - Fork 6
/
state.go
43 lines (36 loc) · 940 Bytes
/
state.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
package database
import (
"context"
"time"
)
// State -
type State struct {
//nolint
tableName struct{} `gorm:"-" pg:"dipdup_state" json:"-"`
IndexName string `gorm:"primaryKey" pg:",pk" json:"index_name"`
IndexType string `json:"index_type"`
Hash string `json:"hash,omitempty"`
Level uint64 `json:"level"`
UpdatedAt int `gorm:"autoUpdateTime"`
}
// BeforeInsert -
func (s *State) BeforeInsert(ctx context.Context) (context.Context, error) {
s.UpdatedAt = int(time.Now().Unix())
return ctx, nil
}
// BeforeUpdate -
func (s *State) BeforeUpdate(ctx context.Context) (context.Context, error) {
s.UpdatedAt = int(time.Now().Unix())
return ctx, nil
}
// TableName -
func (State) TableName() string {
return "dipdup_state"
}
// StateRepository -
type StateRepository interface {
State(name string) (State, error)
UpdateState(state State) error
CreateState(state State) error
DeleteState(state State) error
}