-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (40 loc) · 1.13 KB
/
main.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
package main
import (
"fmt"
"github.com/gofrs/uuid"
"go.riyazali.net/sqlite"
)
type v7String struct{}
func (*v7String) Args() int { return 0 }
func (*v7String) Deterministic() bool { return false }
func (*v7String) Apply(ctx *sqlite.Context, values ...sqlite.Value) {
u, err := uuid.NewV7()
if err != nil {
ctx.ResultError(fmt.Errorf("error generating uuidv7: %w", err))
return
}
ctx.ResultText(u.String())
}
type v7Byte struct{}
func (*v7Byte) Args() int { return 0 }
func (*v7Byte) Deterministic() bool { return false }
func (*v7Byte) Apply(ctx *sqlite.Context, values ...sqlite.Value) {
u, err := uuid.NewV7()
if err != nil {
ctx.ResultError(fmt.Errorf("error generating uuidv7: %w", err))
return
}
ctx.ResultBlob(u.Bytes())
}
func init() {
sqlite.Register(func(api *sqlite.ExtensionApi) (sqlite.ErrorCode, error) {
if err := api.CreateFunction("uuid_generate_v7", &v7String{}); err != nil {
return sqlite.SQLITE_ERROR, err
}
if err := api.CreateFunction("uuid_generate_v7_bytes", &v7Byte{}); err != nil {
return sqlite.SQLITE_ERROR, err
}
return sqlite.SQLITE_OK, nil
})
}
func main() {}