mirror of
https://github.com/dstotijn/hetty.git
synced 2025-07-01 18:47:29 -04:00
Replace SQLite with BadgerDB
This commit is contained in:
31
pkg/api/models.go
Normal file
31
pkg/api/models.go
Normal file
@ -0,0 +1,31 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
|
||||
"github.com/oklog/ulid"
|
||||
)
|
||||
|
||||
type ULID ulid.ULID
|
||||
|
||||
func (u *ULID) UnmarshalGQL(v interface{}) (err error) {
|
||||
str, ok := v.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("ulid must be a string")
|
||||
}
|
||||
|
||||
id, err := ulid.Parse(str)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to parse ULID: %w", err)
|
||||
}
|
||||
|
||||
*u = ULID(id)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u ULID) MarshalGQL(w io.Writer) {
|
||||
fmt.Fprint(w, strconv.Quote(ulid.ULID(u).String()))
|
||||
}
|
Reference in New Issue
Block a user