Documentation ¶
Overview ¶
Package clent includes re-usable components for working with the Ent ORM.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Field = struct { CLID func(string, string) ent.Field }{ CLID: func(name, prefix string) ent.Field { if len(prefix) != clid.PrefixSize { panic("clent: clid prefix not of length: " + strconv.Itoa(clid.PrefixSize)) } return field.String(name). GoType(clid.ID{}). DefaultFunc(func() clid.ID { return clid.New(prefix) }). Validate(Validator.CLID(prefix)). SchemaType(map[string]string{ dialect.Postgres: fmt.Sprintf("varchar(%d)", clid.StorageSize), dialect.MySQL: fmt.Sprintf("varchar(%d)", clid.StorageSize), }) }, }
Field is a namespace for re-usable fields.
View Source
var Validator = struct { CLID func(string) func(string) error }{ CLID: func(expPrefix string) func(s string) error { return func(s string) error { before, after, found := strings.Cut(s, clid.Separator) if !found { return errors.New("clent: invalid clid, no separator") } if _, err := ulid.ParseStrict(after); err != nil { return fmt.Errorf("clent: invalid ulid: %w", err) } if before != expPrefix { return fmt.Errorf("clent: provided clid prefix '%s' is invalid, expected: '%s'", before, expPrefix) } return nil } }, }
Validator name-spaced re-usable (field validators).
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.