-
Notifications
You must be signed in to change notification settings - Fork 4
/
state.go
49 lines (41 loc) · 1.46 KB
/
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
44
45
46
47
48
49
package database
import (
"context"
"time"
"github.com/uptrace/bun"
)
// State -
type State struct {
//nolint
tableName struct{} `gorm:"-" bun:"-" pg:"dipdup_state" json:"-" comment:"Indexer state table"`
bun.BaseModel `gorm:"-" pg:"-" bun:"dipdup_state" json:"-" comment:"Indexer state table"`
IndexName string `gorm:"primaryKey" pg:",pk" bun:",pk" json:"index_name" comment:"Index name"`
IndexType string `json:"index_type" comment:"Index type"`
Hash string `json:"hash" comment:"Current hash"`
Timestamp time.Time `json:"timestamp" comment:"Current timestamp"`
Level uint64 `json:"level" comment:"Index level"`
UpdatedAt int `gorm:"autoUpdateTime" comment:"Last updated timestamp"`
CreatedAt int `gorm:"autoCreateTime" comment:"Created timestamp"`
}
// BeforeInsert -
func (s *State) BeforeInsert(ctx context.Context) (context.Context, error) {
s.UpdatedAt = int(time.Now().Unix())
s.CreatedAt = s.UpdatedAt
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(ctx context.Context, name string) (*State, error)
UpdateState(sctx context.Context, tate *State) error
CreateState(ctx context.Context, state *State) error
DeleteState(ctx context.Context, state *State) error
}