xdb

package module
v0.0.0-...-47fa911 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MIT Imports: 6 Imported by: 0

README

XDB

The architecture & development of XDB is covered in the following blog posts:

  1. Building XDB
  2. Designing XDB API

Documentation

Index

Constants

View Source
const (
	OpEq     = "=="
	OpNe     = "!="
	OpGt     = ">"
	OpGe     = ">="
	OpLt     = "<"
	OpLe     = "<="
	OpIn     = "IN"
	OpNotIn  = "NOT IN"
	OpSearch = "SEARCH"
	ASC      = "ASC"
	DESC     = "DESC"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Condition

type Condition struct {
	// contains filtered or unexported fields
}

Condition defines an operator and a value to filter records.

func (*Condition) Eq

func (c *Condition) Eq(val any) *Query

Eq adds an equality filter to the condition.

func (*Condition) Ge

func (c *Condition) Ge(val any) *Query

Ge adds a greater-than-or-equal filter to the condition.

func (*Condition) Gt

func (c *Condition) Gt(val any) *Query

Gt adds a greater-than filter to the condition.

func (*Condition) In

func (c *Condition) In(vals ...any) *Query

In adds a set membership filter to the condition.

func (*Condition) Le

func (c *Condition) Le(val any) *Query

Le adds a less-than-or-equal filter to the condition.

func (*Condition) Lt

func (c *Condition) Lt(val any) *Query

Lt adds a less-than filter to the condition.

func (*Condition) Ne

func (c *Condition) Ne(val any) *Query

Ne adds a non-equality filter to the condition.

func (*Condition) NotIn

func (c *Condition) NotIn(vals ...any) *Query

NotIn adds a set non-membership filter to the condition.

func (*Condition) Op

func (c *Condition) Op() string

Op returns the operator of the condition.

func (*Condition) Search

func (c *Condition) Search(val any) *Query

Search adds a full-text search filter to the condition.

func (*Condition) Value

func (c *Condition) Value() any

Value returns the value of the condition.

func (*Condition) ValueList

func (c *Condition) ValueList() []any

ValueList returns the list of values of the condition.

type Empty

type Empty struct{}

type Key

type Key struct {
	// contains filtered or unexported fields
}

Key is a unique identifier for a record.

func NewKey

func NewKey(kind, id string) *Key

NewKey creates a new key.

func (*Key) ID

func (k *Key) ID() string

ID returns the id of the key.

func (*Key) Kind

func (k *Key) Kind() string

Kind returns the kind of the key.

func (*Key) String

func (k *Key) String() string

String returns a readable form of the key.

type Query

type Query struct {
	// contains filtered or unexported fields
}

Query is a commmon abstraction for querying, filtering, and sorting records.

func Select

func Select(attrs ...string) *Query

Select creates a new query to fetch records with the given attributes. Example:

q := Select("name", "age")
q := Select("*") // fetch all attributes

func (*Query) And

func (q *Query) And(field string) *Condition

And adds a logical AND filter to the query.

func (*Query) From

func (q *Query) From(kind string) *Query

From sets the kind of the query.

func (*Query) GetAttributes

func (q *Query) GetAttributes() []string

GetAttributes returns the attributes of the query.

func (*Query) GetConditions

func (q *Query) GetConditions() map[string][]*Condition

GetConditions returns the conditions of the query.

func (*Query) GetLimit

func (q *Query) GetLimit() int

GetLimit returns the limit of the query.

func (*Query) GetOrderBy

func (q *Query) GetOrderBy() []string

GetOrderBy returns the sorting order of the query.

func (*Query) GetSkip

func (q *Query) GetSkip() int

GetSkip returns the offset of the query.

func (*Query) Kind

func (q *Query) Kind() string

Kind returns the record kind of the query.

func (*Query) Limit

func (q *Query) Limit(limit int) *Query

Limit adds a limit to the query.

func (*Query) OrderBy

func (q *Query) OrderBy(args ...string) *Query

OrderBy adds a sorting order to the query. Accepts pairs of attribute and direction. Example:

q.OrderBy("name", "asc")
q.OrderBy("age", "desc")

func (*Query) Skip

func (q *Query) Skip(offset int) *Query

Skip adds an offset to the query.

func (*Query) String

func (q *Query) String() string

String returns a string representation of the query.

func (*Query) Where

func (q *Query) Where(attr string) *Condition

Where adds a filter to the query.

type Record

type Record struct {
	// contains filtered or unexported fields
}

func NewRecord

func NewRecord(k *Key, tuples ...*Tuple) *Record

NewRecord creates a new record with the given tuples.

func (*Record) Key

func (r *Record) Key() *Key

func (*Record) Set

func (r *Record) Set(tuples ...*Tuple) *Record

func (*Record) Tuples

func (r *Record) Tuples() []*Tuple

type RecordQueryer

type RecordQueryer interface {
	QueryRecords(ctx context.Context, q *Query) (*RecordSet, error)
}

RecordQueryer defines the interface for querying records.

type RecordSet

type RecordSet = ResultSet[Record]

type RecordStorer

type RecordStorer interface {
	GetRecord(ctx context.Context, key *Key) (*Record, error)
	PutRecord(ctx context.Context, record *Record) error
	DeleteRecord(ctx context.Context, key *Key) error
}

RecordStorer defines the interface for storing and retrieving records.

type ResultSet

type ResultSet[T any] struct {
	// contains filtered or unexported fields
}

ResultSet is a paginated list of T.

func NewResultSet

func NewResultSet[T any](t []*T, offset, limit int) *ResultSet[T]

NewResultSet creates a new ResultSet.

func (*ResultSet[T]) List

func (rs *ResultSet[T]) List() []*T

List returns the list of T.

func (*ResultSet[T]) Next

func (rs *ResultSet[T]) Next() int

Next returns the next offset.

func (*ResultSet[T]) Page

func (rs *ResultSet[T]) Page() int

Page returns the current page number.

type Tuple

type Tuple struct {
	// contains filtered or unexported fields
}

Tuple is a key-attribute-value tuple.

func NewTuple

func NewTuple[T Value](key *Key, name string, value T) *Tuple

NewTuple creates a new tuple.

func (*Tuple) Hash

func (t *Tuple) Hash() string

func (*Tuple) Key

func (t *Tuple) Key() *Key

func (*Tuple) Name

func (t *Tuple) Name() string

func (*Tuple) Value

func (t *Tuple) Value() any

type Value

type Value interface {
	int | int32 | uint32 | int64 | uint64 |
		float32 | float64 | string | bool | []byte |
		time.Time | Empty |
		[]int | []int32 | []uint32 | []int64 | []uint64 |
		[]float32 | []float64 | []string | []bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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