generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 7
/
types.go
40 lines (34 loc) · 807 Bytes
/
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
package sql
import (
"database/sql/driver"
"fmt"
"google.golang.org/protobuf/proto"
schemapb "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/schema"
"github.com/TBD54566975/ftl/backend/schema"
)
// 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
}