-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.go
34 lines (29 loc) · 864 Bytes
/
model.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
package andro
import (
"context"
"time"
)
// Base contains common fields for all tables
type Base struct {
ID int `json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt time.Time `json:"deleted_at,omitempty" pg:",soft_delete"`
}
// ListQuery holds company/location data used for list db queries
type ListQuery struct {
Query string
ID int
}
// BeforeInsert hooks into insert operations, setting createdAt and updatedAt to current time
func (b *Base) BeforeInsert(ctx context.Context) (context.Context, error) {
now := time.Now()
b.CreatedAt = now
b.UpdatedAt = now
return ctx, nil
}
// BeforeUpdate hooks into update operations, setting updatedAt to current time
func (b *Base) BeforeUpdate(ctx context.Context) (context.Context, error) {
b.UpdatedAt = time.Now()
return ctx, nil
}