Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidFieldName = errors.New("invalid field name")
ErrInvalidFieldName signals that a JSON field name does not match the allowed identifier pattern. Callers at the public API boundary should wrap this with den.ErrValidation so users can errors.Is against that sentinel. Kept separate here to avoid an import cycle with the root package.
Functions ¶
func CollectionName ¶
CollectionName derives the collection name from a Go type name. Simply lowercases the full name, no pluralization.
func EscapeLike ¶ added in v0.7.0
EscapeLike escapes LIKE special characters (%, _, \) in a value.
func ParseJSONTagName ¶
ParseJSONTagName extracts the field name from a json struct tag. Returns "" if no json tag or if tagged with "-".
func SanitizeFieldName ¶ added in v0.7.0
SanitizeFieldName strips characters that are not safe for JSON path interpolation. Allows letters, digits, underscores, and dots (for nested paths).
func ValidateFieldName ¶ added in v0.8.0
ValidateFieldName reports whether the given JSON field name is safe to interpolate into SQL and consistent with SQL identifier conventions. Returns an error wrapping ErrInvalidFieldName on rejection.
Types ¶
type Encoder ¶ added in v0.7.0
type Encoder struct{}
Encoder provides JSON encoding/decoding for document storage.
type FieldInfo ¶
type FieldInfo struct {
JSONName string
GoName string
Type reflect.Type
Index []int // reflect index path for nested access
Options TagOptions
IsPointer bool
}
FieldInfo describes a single field in a document struct.
type StructInfo ¶
type StructInfo struct {
CollectionName string
Fields []FieldInfo
GoType reflect.Type
HasDeletedAt bool
// Pre-resolved pointers to the base fields embedded by document.Base /
// document.SoftDelete / document.Tracked. Populated once by
// AnalyzeStruct so hot paths can skip per-op FieldByName lookups. Any
// of these may be nil if the struct does not embed the corresponding
// base field.
BaseID *FieldInfo
BaseRev *FieldInfo
BaseCreatedAt *FieldInfo
BaseUpdatedAt *FieldInfo
BaseDeletedAt *FieldInfo
// contains filtered or unexported fields
}
StructInfo holds analyzed metadata for a document struct.
func AnalyzeStruct ¶
func AnalyzeStruct(t reflect.Type) (*StructInfo, error)
AnalyzeStruct analyzes a struct type and extracts field metadata from json and den struct tags. Embedded structs are flattened.
func (*StructInfo) FieldByName ¶
func (s *StructInfo) FieldByName(jsonName string) *FieldInfo
FieldByName returns the FieldInfo for the given JSON field name, or nil.
func (*StructInfo) IndexedFields ¶
func (s *StructInfo) IndexedFields() []FieldInfo
IndexedFields returns all fields with the index option set.
func (*StructInfo) UniqueFields ¶
func (s *StructInfo) UniqueFields() []FieldInfo
UniqueFields returns all fields with the unique option set.
type TagOptions ¶
type TagOptions struct {
Index bool
Unique bool
FTS bool
OmitEmpty bool
Eager bool // valid on Link[T] / []Link[T] fields — auto-hydrate by default
UniqueTogether string // group name for composite unique index
IndexTogether string // group name for composite non-unique index
}
TagOptions holds the parsed options from a den struct tag.
func ParseDenTag ¶
func ParseDenTag(tag string) (TagOptions, error)
ParseDenTag parses a den struct tag for metadata options only. Format: "option1,option2,..." (no field name — that comes from json tag). Returns an error for unknown tag options to catch typos like "indx".