-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsql.go
35 lines (29 loc) · 843 Bytes
/
sql.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
// Copyright 2015 Rick Beton. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package period
import (
"database/sql/driver"
"fmt"
)
// Scan parses some value, which can be either string or []byte.
// It implements sql.Scanner, https://golang.org/pkg/database/sql/#Scanner
func (period *Period) Scan(value interface{}) (err error) {
if value == nil {
return nil
}
err = nil
switch v := value.(type) {
case []byte:
*period, err = Parse(string(v))
case string:
*period, err = Parse(v)
default:
err = fmt.Errorf("%T %+v is not a meaningful period", value, value)
}
return err
}
// Value converts the period to an ISO-8601 string. It implements [driver.Valuer],
func (period Period) Value() (driver.Value, error) {
return period.String(), nil
}