generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 7
/
types.go
69 lines (58 loc) · 1.81 KB
/
types.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
68
69
package sql
import (
"database/sql"
"database/sql/driver"
"fmt"
"time"
"github.com/alecthomas/types/optional"
"github.com/google/uuid"
"google.golang.org/protobuf/proto"
"github.com/TBD54566975/ftl/backend/controller/leases"
schemapb "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/schema"
"github.com/TBD54566975/ftl/backend/schema"
"github.com/TBD54566975/ftl/internal/model"
)
type NullType = optional.Option[Type]
type NullRef = optional.Option[schema.RefKey]
type NullUUID = optional.Option[uuid.UUID]
type NullLeaseKey = optional.Option[leases.Key]
type NullTime = optional.Option[time.Time]
type NullDuration = optional.Option[time.Duration]
type NullRunnerKey = optional.Option[model.RunnerKey]
type NullCronJobKey = optional.Option[model.CronJobKey]
type NullDeploymentKey = optional.Option[model.DeploymentKey]
type NullRequestKey = optional.Option[model.RequestKey]
var _ sql.Scanner = (*NullRunnerKey)(nil)
var _ driver.Valuer = (*NullRunnerKey)(nil)
var _ sql.Scanner = (*NullCronJobKey)(nil)
var _ driver.Valuer = (*NullCronJobKey)(nil)
var _ sql.Scanner = (*NullDeploymentKey)(nil)
var _ driver.Valuer = (*NullDeploymentKey)(nil)
var _ sql.Scanner = (*NullRequestKey)(nil)
var _ driver.Valuer = (*NullRequestKey)(nil)
// Type is a database adapter type for schema.Type.
//
// It encodes to/from the protobuf representation of a Type.
type Type struct {
schema.Type
}
func (t *Type) Scan(src interface{}) error {
switch src := src.(type) {
case []byte:
pb := &schemapb.Type{}
if err := proto.Unmarshal(src, pb); err != nil {
return err
}
t.Type = schema.TypeFromProto(pb)
return nil
default:
return fmt.Errorf("cannot scan %T", src)
}
}
func (t *Type) Value() (driver.Value, error) {
data, err := proto.Marshal(t.Type.ToProto())
if err != nil {
return nil, err
}
return data, nil
}