Documentation ¶
Index ¶
- Variables
- func Count[T Object](db Storage, q Query) (int, error)
- func Create[T Object](db Storage, constructor func(obj T) error, namespace, createdBy string) (T, error)
- func Delete[T Object](db Storage, urn URN, deletedBy string) (T, error)
- func Fetch[T Object](db Storage, urn URN) (T, error)
- func Insert[T Object](db Storage, v T, createdBy string) (T, error)
- func IsConflict(err error) bool
- func IsNotFound(err error) bool
- func New[T Object](namespace string, funcs ...func(obj T) error) (T, error)
- func Search[T Object](db Storage, q Query) (iter.Seq[T], error)
- func ToJSON(v Object) ([]byte, error)
- func Update[T Object](db Storage, v T, updatedBy string) (T, error)
- func Upsert[T Object](db Storage, v T, updatedBy string) (T, error)
- type Embed
- type Indexer
- type Kind
- type Meta
- type Namespace
- type Object
- type Options
- type Path
- type Query
- type Registry
- type Storage
- type Type
- type URN
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("storage: document was not found") ErrConflict = errors.New("storage: update of an outdated document") )
var (
ErrKindNotFound = errors.New("resource: kind not found")
)
Functions ¶
func Create ¶ added in v0.0.2
func Create[T Object](db Storage, constructor func(obj T) error, namespace, createdBy string) (T, error)
Create creates a new resource and inserts it into the storage.
func IsConflict ¶
IsConflict returns true if the specified error is a conflict error.
func IsNotFound ¶
IsNotFound returns true if the specified error is a not found error.
Types ¶
type Embed ¶
Embedded represents a generic embedded document for unmarshaling
func (Embed) MarshalJSON ¶
MarshalJSON marshals the JSON from the embedded document
func (*Embed) UnmarshalJSON ¶
UnmarshalJSON unmarshals the JSON into the embedded document
type Indexer ¶
type Indexer interface {
Index() string
}
Indexer represents a resource that provides an index.
type Meta ¶
type Meta struct { ID string `json:"id" form:"-"` // Globally unique identifier (e.g. "9m4e2mr0ui3e8a215n4g") Kind Kind `json:"kind" form:"-"` // Meta kind (e.g. "deployment") Namespace string `json:"namespace" form:"-"` // Namespace of the object (e.g. "my_project") State string `json:"state,omitempty" form:"-"` // State is the current state of the resource CreatedBy string `json:"createdBy,omitempty" form:"-"` // CreatedBy is the user who created the resource CreatedAt int64 `json:"createdAt,omitempty" form:"-"` // CreatedAt is the time when the resource was created UpdatedBy string `json:"updatedBy,omitempty" form:"-"` // UpdatedBy is the user who last updated the resource UpdatedAt int64 `json:"updatedAt,omitempty" form:"-"` // UpdatedAt is the time when the resource was last updated }
Meta represents a metadata of the object.
type Namespace ¶
type Namespace struct { Meta `kind:"namespace" json:",inline"` Name string `json:"name" form:"rw" is:"required,lowercase,alphanum,minlen(2),maxlen(25)"` Label string `json:"label" form:"rw" is:"required,minlen(2),maxlen(50)"` Desc string `json:"desc" form:"rw" is:"maxlen(255)"` }
Namespace represents a namespace in the system.
type Object ¶
type Object interface { URN() URN // URN returns the uniform identifier of the object Status() string // Status returns the current state Created() (string, time.Time) // Created returns createdBy and createdAt information Updated() (string, time.Time) // Updated returns updatedBy and updatedAt information }
Object represents an object in the system.
type Options ¶
type Options struct { Icon string `json:"icon,omitempty"` // Icon name from https://lucide.dev/icons Title string `json:"title,omitempty"` // Title of the document (e.g. Person) Plural string `json:"plural,omitempty"` // Plural name of the document (e.g. People) Sort string `json:"sort,omitempty"` // Sort field }
Options represents the options for a document
type Path ¶
type Path string
Path represents a rendering path for a particular field.
type Query ¶
type Query struct { Namespace string // Namespaces is a list of namespaces to filter by States []string // States is a list of states to filter by Indexes []string // Indexes is a list of indexes to filter by Filters map[string][]string // Filters is a map of filters to apply Match string // Match is the full-text search query SortBy []string // Sort is the set of fields to order by Offset int // Offset is the number of records to skip Limit int // Limit is the maximum number of records to return }
Query represents a query to filter records.
func ParseQuery ¶
ParseQuery parses a string query into a Query struct. The query format is structured as a semicolon-separated list of key-value pairs. Example query: "namespace=company;state=active;filter=age:30;match={Name}" - The query is limited to `company` namespace. - Only records with an `active` state will be considered. - A filter is applied to only include records where `age` is `30`. - It matches records containing the person's name from the placeholder `{Name}`.
**namespace**: Specifies the namespaces to filter by. Multiple namespaces can be separated by commas. Example: `namespace=company,person`
**state**: Indicates the states to filter by. Multiple states can be separated by commas. Example: `state=active,inactive`
**filter**: Defines filters to apply. Each filter is specified as `field:value`, and multiple filters can be separated by commas. Example: `filter=age:30,income:1000`
**match**: A full-text search query. This can include any search terms. Example: `match=software engineer`
type Storage ¶
type Storage interface { io.Closer Insert(v Object, createdBy string) (Object, error) Update(v Object, updatedBy string) (Object, error) Upsert(v Object, updatedBy string) (Object, error) Delete(urn URN, deletedBy string) (Object, error) Fetch(urn URN) (Object, error) Search(kind Kind, query Query) (iter.Seq[Object], error) Count(kind Kind, query Query) (int, error) }
Storage represents a storage layer for records.
type Type ¶
type Type struct { Kind Kind // Kind of the resource Type reflect.Type // Type of the resource Options // Options of the resource // contains filtered or unexported fields }
Type represents a registration of a resource kind.
type URN ¶
type URN struct { Namespace string `json:"-" uri:"namespace" binding:"required"` // Namespace name (e.g. "my_project") Kind Kind `json:"-" uri:"kind" binding:"required"` // Object kind (e.g. "my_document") ID string `json:"-" uri:"id"` // Globally unique identifier (e.g. "9m4e2mr0ui3e8a215n4g") }
URN represents a uniform resource name for accessing resources. The following are the general formats for URNs: urn:namespace:kind:id (e.g. "urn:my_project:my_document:9m4e2mr0ui3e8a215n4g")
func (URN) MarshalJSON ¶
MarshalJSON marshals the URN to JSON.
func (*URN) UnmarshalJSON ¶
UnmarshalJSON unmarshals the JSON into a URN.