File size: 616 Bytes
fea99b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
package entutils

import (
	"database/sql/driver"

	"github.com/oklog/ulid/v2"
)

// ULID implements a valuer (and Scanner) that can serialize string ULIDs into postgres
// instead of the binary representation, as postgres interprets those as UTF-8 strings
type ULID struct {
	ulid.ULID
}

func (v ULID) Value() (driver.Value, error) {
	return v.ULID.String(), nil
}

func (v *ULID) ULIDPointer() *ulid.ULID {
	if v == nil {
		return nil
	}
	return &v.ULID
}

func Ptr(u *ulid.ULID) *ULID {
	if u == nil {
		return nil
	}

	return &ULID{
		ULID: *u,
	}
}

func Wrap(u ulid.ULID) ULID {
	return ULID{
		ULID: u,
	}
}