r3toml

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package r3toml converts r3 query types (r3.Filters, r3.Sorts, r3.PaginationSpec, r3.Fields) to and from TOML for configuration files, using human-readable names (field/operator/value) like the YAML dialect.

Limitation: TOML has no null type. Filters with nil values (IS NULL checks) cannot be encoded to TOML. FilterToTOML returns an error for such filters.

Index

Constants

This section is empty.

Variables

View Source
var ErrTOMLDialectorFailed = errors.New("toml dialector failed")

ErrTOMLDialectorFailed is a generic error for r3toml dialector failures.

View Source
var ErrTOMLNullValue = errors.New("TOML does not support null values")

ErrTOMLNullValue is returned when trying to encode a nil value to TOML, which does not support null.

Functions

func IsErrDialectorFailure

func IsErrDialectorFailure(err error) bool

IsErrDialectorFailure checks if the given error is a r3toml failure.

func TOMLToField

func TOMLToField(tf TOMLField) *r3.FieldSpec

TOMLToField converts a TOMLField to a FieldSpec.

func TOMLToFilter

func TOMLToFilter(tf *TOMLFilter) (*r3.FilterSpec, error)

TOMLToFilter converts a TOMLFilter to a FilterSpec.

func TOMLToFilters

func TOMLToFilters(tfs TOMLFilters) (r3.Filters, error)

TOMLToFilters converts a slice of TOMLFilters to r3.Filters.

func TOMLToPagination

func TOMLToPagination(tp *TOMLPagination) (*r3.PaginationSpec, error)

TOMLToPagination converts a TOMLPagination to a PaginationSpec.

func TOMLToSort

func TOMLToSort(ts *TOMLSort) (*r3.SortSpec, error)

TOMLToSort converts a TOMLSort to a SortSpec.

Types

type TOMLCursorPagination

type TOMLCursorPagination struct {
	After  string `toml:"after,omitempty"`
	Before string `toml:"before,omitempty"`
	Limit  int    `toml:"limit,omitempty"`
}

TOMLCursorPagination represents cursor-based pagination in TOML format.

func (*TOMLCursorPagination) ToCursorSpec

func (tc *TOMLCursorPagination) ToCursorSpec() *r3.CursorSpec

ToCursorSpec converts TOMLCursorPagination to an r3.CursorSpec. Returns nil if no cursor parameters are set.

type TOMLField

type TOMLField string

TOMLField is a string value representing a field name in TOML.

func FieldToTOML

func FieldToTOML(f *r3.FieldSpec) TOMLField

FieldToTOML converts a FieldSpec to a TOMLField.

func (TOMLField) String

func (f TOMLField) String() string

String returns the string representation of the field.

type TOMLFields

type TOMLFields []TOMLField

TOMLFields is a collection of TOMLField values.

type TOMLFilter

type TOMLFilter struct {
	Field    string        `toml:"field,omitempty"`
	Operator string        `toml:"operator,omitempty"` // canonical: "eq", "gt", etc.
	Value    any           `toml:"value,omitempty"`
	And      []*TOMLFilter `toml:"and,omitempty"`
	Or       []*TOMLFilter `toml:"or,omitempty"`
}

TOMLFilter represents a filter criteria in TOML format.

func FilterToTOML

func FilterToTOML(f *r3.FilterSpec) (*TOMLFilter, error)

FilterToTOML converts a FilterSpec to a TOMLFilter. Returns ErrTOMLNullValue for a nil filter value, since TOML has no null type.

func (*TOMLFilter) ToFilterSpec

func (tf *TOMLFilter) ToFilterSpec() (*r3.FilterSpec, error)

ToFilterSpec converts a TOMLFilter to an r3.FilterSpec.

type TOMLFilters

type TOMLFilters []*TOMLFilter

TOMLFilters is a slice of TOMLFilter.

type TOMLPagination

type TOMLPagination struct {
	PageNum  int `toml:"page_num,omitempty"`
	PageSize int `toml:"page_size,omitempty"`
}

TOMLPagination represents pagination in TOML format.

func PaginationToTOML

func PaginationToTOML(p *r3.PaginationSpec) *TOMLPagination

PaginationToTOML converts a PaginationSpec to a TOMLPagination.

func (*TOMLPagination) ToPaginationSpec

func (tp *TOMLPagination) ToPaginationSpec() (*r3.PaginationSpec, error)

ToPaginationSpec converts a TOMLPagination to an r3.PaginationSpec.

type TOMLSort

type TOMLSort struct {
	Field         string `toml:"field"`
	Direction     string `toml:"direction,omitempty"`
	NullsPosition string `toml:"nulls_position,omitempty"`
}

TOMLSort represents a sort criteria in TOML format.

func SortToTOML

func SortToTOML(s *r3.SortSpec) *TOMLSort

SortToTOML converts a SortSpec to a TOMLSort.

func (*TOMLSort) ToSortSpec

func (ts *TOMLSort) ToSortSpec() (*r3.SortSpec, error)

ToSortSpec converts a TOMLSort to an r3.SortSpec.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL