-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathint.go.erb
More file actions
61 lines (49 loc) · 1.39 KB
/
Copy pathint.go.erb
File metadata and controls
61 lines (49 loc) · 1.39 KB
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
package zeronull
import (
"database/sql/driver"
"fmt"
"math"
"github.com/jackc/pgx/v5/pgtype"
)
<% [2, 4, 8].each do |pg_byte_size| %>
<% pg_bit_size = pg_byte_size * 8 %>
type Int<%= pg_byte_size %> int<%= pg_bit_size %>
// SkipUnderlyingTypePlan implements the [pgtype.SkipUnderlyingTypePlanner] interface.
func (Int<%= pg_byte_size %>) SkipUnderlyingTypePlan() {}
// ScanInt64 implements the [pgtype.Int64Scanner] interface.
func (dst *Int<%= pg_byte_size %>) ScanInt64(n pgtype.Int8) error {
if !n.Valid {
*dst = 0
return nil
}
if n.Int64 < math.MinInt<%= pg_bit_size %> {
return fmt.Errorf("%d is less than minimum value for Int<%= pg_byte_size %>", n.Int64)
}
if n.Int64 > math.MaxInt<%= pg_bit_size %> {
return fmt.Errorf("%d is greater than maximum value for Int<%= pg_byte_size %>", n.Int64)
}
*dst = Int<%= pg_byte_size %>(n.Int64)
return nil
}
// Scan implements the [database/sql.Scanner] interface.
func (dst *Int<%= pg_byte_size %>) Scan(src any) error {
if src == nil {
*dst = 0
return nil
}
var nullable pgtype.Int<%= pg_byte_size %>
err := nullable.Scan(src)
if err != nil {
return err
}
*dst = Int<%= pg_byte_size %>(nullable.Int<%= pg_bit_size %>)
return nil
}
// Value implements the [database/sql/driver.Valuer] interface.
func (src Int<%= pg_byte_size %>) Value() (driver.Value, error) {
if src == 0 {
return nil, nil
}
return int64(src), nil
}
<% end %>