rdb

package
v1.186.1 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2024 License: MIT Imports: 31 Imported by: 3

Documentation

Index

Constants

View Source
const (
	FieldIndexingExact  = "Exact"
	FieldIndexingSearch = "Search"
)
View Source
const SearchOptionAnd = SearchOption("and")
View Source
const SearchOptionOr = SearchOption("or")

Variables

View Source
var (
	ErrNoSuchEntity          = errors.New("rdb: no such entity")
	ErrConcurrentTransaction = errors.New("rdb: concurrent transaction")
	ErrDatabaseDoesNotExists = errors.New("rdb: database does not exists")
)

Functions

func EscapeSearch

func EscapeSearch(str string) string

Types

type AdminOperation added in v1.87.0

type AdminOperation interface {
	URL() string
	Body() interface{}
}

type AdvancedError

type AdvancedError struct {
	URL     string `json:"Url"`
	Type    string
	Message string
	Stack   string `json:"Error"`
}

func (*AdvancedError) Error

func (err *AdvancedError) Error() string

type Collection

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

func (*Collection) ConfigureRevisions

func (collection *Collection) ConfigureRevisions(ctx context.Context, config *api.RevisionConfig) error

ConfigureRevisions for this collection to store every change.

func (*Collection) Delete

func (collection *Collection) Delete(ctx context.Context, model Model) error

func (*Collection) Enforce

func (collection *Collection) Enforce(enforcer Enforcer) *Collection

func (*Collection) Exists

func (collection *Collection) Exists(ctx context.Context, id string) (bool, error)

func (*Collection) Get

func (collection *Collection) Get(ctx context.Context, id string, dest interface{}, opts ...IncludeOption) error

Get fetchs an entity by its ID. If it doesn't exists or it's enforced it returns ErrNoSuchEntity.

func (*Collection) GetMulti

func (collection *Collection) GetMulti(ctx context.Context, ids []string, dest interface{}, opts ...IncludeOption) error

GetMulti fetches multiple models. If one of them doesn't exists it will return ErrNoSuchEntity.

func (*Collection) Put

func (collection *Collection) Put(ctx context.Context, model Model) error

func (*Collection) TryGet

func (collection *Collection) TryGet(ctx context.Context, id string, model interface{}, opts ...IncludeOption) error

TryGet tries to fetch the entity, but returns successfully even if it doesn't exist. The model will be untouched in case it doesn't exists.

type ConfigureExpirationOperation added in v1.87.0

type ConfigureExpirationOperation struct {
	Disabled             bool
	DeleteFrequencyInSec *int
}

func DisableExpiration added in v1.87.0

func DisableExpiration() *ConfigureExpirationOperation

func EnableExpiration added in v1.87.0

func EnableExpiration() *ConfigureExpirationOperation

func (*ConfigureExpirationOperation) Body added in v1.87.0

func (op *ConfigureExpirationOperation) Body() interface{}

func (*ConfigureExpirationOperation) SetFrequency added in v1.87.0

func (op *ConfigureExpirationOperation) SetFrequency(freq int)

func (*ConfigureExpirationOperation) URL added in v1.87.0

type Counter

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

func (*Counter) Decrement

func (counter *Counter) Decrement(ctx context.Context, delta int64) error

func (*Counter) Delete

func (counter *Counter) Delete(ctx context.Context) error

func (*Counter) Increment

func (counter *Counter) Increment(ctx context.Context, delta int64) error

func (*Counter) Value

func (counter *Counter) Value() int64

type Credentials added in v1.94.0

type Credentials struct {
	Address string
	Key     string
	Cert    string
	CACert  string
}

type Database

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

func Open

func Open(address, dbname string, opts ...OpenOption) (*Database, error)

func OpenCredentials added in v1.94.0

func OpenCredentials(credentials Credentials, dbname string, opts ...OpenOption) (*Database, error)

func OpenSecret added in v1.94.0

func OpenSecret(secret *secrets.Value, dbname string, opts ...OpenOption) (*Database, error)

func (*Database) Collection

func (db *Database) Collection(golden Model) *Collection

func (*Database) ConfigureDefaultRevisions

func (db *Database) ConfigureDefaultRevisions(ctx context.Context, config *api.RevisionConfig) error

ConfigureDefaultRevisions for all the collections of this database storing every change.

func (*Database) Create

func (db *Database) Create(ctx context.Context, replicationFactor int64) error

func (*Database) CreateIndex

func (db *Database) CreateIndex(ctx context.Context, name string, index Index) error

func (*Database) DebugNextIdentity added in v1.108.0

func (db *Database) DebugNextIdentity(ctx context.Context, name string) (int64, error)

DebugNextIdentity returns the expected ID for a new item. Do not use in production.

func (*Database) Descriptor

func (db *Database) Descriptor(ctx context.Context) (*api.Database, error)

func (*Database) Exists

func (db *Database) Exists(ctx context.Context) (bool, error)

func (*Database) Maintenance added in v1.87.0

func (db *Database) Maintenance(ctx context.Context, operations ...AdminOperation) error

Maintenance sends admin operations to the server one by one.

func (*Database) NewSession

func (db *Database) NewSession(ctx context.Context) (context.Context, *Session)

func (*Database) Patch

func (db *Database) Patch(ctx context.Context, query *RQLQuery) (*Operation, error)

func (*Database) QueryIndex

func (db *Database) QueryIndex(index string, golden Model) *Query

func (*Database) RQLQuery

func (db *Database) RQLQuery(query *RQLQuery) *DirectQuery

func (*Database) UpsertIdentity

func (db *Database) UpsertIdentity(ctx context.Context, name string, value int64) error

UpsertIdentity sets a new starting value for an identity that will be used for the next generated ID. If the value is less than the existing one it will be ignored by RavenDB.

type Date

type Date struct {
	time.Time
}

func NewDate

func NewDate(t time.Time) Date

func ZeroDate added in v1.108.0

func ZeroDate() Date

func (Date) MarshalJSON

func (value Date) MarshalJSON() ([]byte, error)

func (Date) String

func (value Date) String() string

func (*Date) UnmarshalJSON

func (value *Date) UnmarshalJSON(data []byte) error

type DateTime

type DateTime struct {
	time.Time
}

func NewDateTime

func NewDateTime(t time.Time) DateTime

func ZeroDateTime added in v1.108.0

func ZeroDateTime() DateTime

func (DateTime) MarshalJSON

func (value DateTime) MarshalJSON() ([]byte, error)

func (DateTime) String

func (value DateTime) String() string

func (*DateTime) UnmarshalJSON

func (value *DateTime) UnmarshalJSON(data []byte) error

type DirectQuery

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

func (*DirectQuery) Checksum

func (q *DirectQuery) Checksum() uint32

Checksum returns a checksum of the filters, conditions, table name, ... and other internal data of the collection that identifies it.

func (*DirectQuery) Clone

func (q *DirectQuery) Clone() *DirectQuery

func (*DirectQuery) ForceStrongConsistency

func (q *DirectQuery) ForceStrongConsistency() *DirectQuery

func (*DirectQuery) GetAll

func (q *DirectQuery) GetAll(ctx context.Context, dest interface{}) error

func (*DirectQuery) RQL

func (q *DirectQuery) RQL() (string, map[string]interface{})

func (*DirectQuery) Stats

func (q *DirectQuery) Stats() QueryStats

Stats return general statistics about the query AFTER it is performed. Calling it before retrieving results would return a nil value.

func (*DirectQuery) String

func (q *DirectQuery) String() string

type Enforcer

type Enforcer struct {
	Model ModelEnforcer
	Query QueryEnforcer
}

type FieldIndexing

type FieldIndexing string

type IncludeOption

type IncludeOption func(cnf *includesConfig)

func Include

func Include(includes ...string) IncludeOption

func IncludeAllCounters

func IncludeAllCounters() IncludeOption

type Index

type Index struct {
	Maps              []string
	Reduce            string
	Indexing          map[string]FieldIndexing
	Store             []string
	AdditionalSources []string
}

type IndexModel

type IndexModel struct {
}

func (*IndexModel) ChangeVector

func (model *IndexModel) ChangeVector() string

func (*IndexModel) Collection

func (model *IndexModel) Collection() string

func (*IndexModel) Tracking added in v1.87.0

func (model *IndexModel) Tracking() *ModelTracking

type Model

type Model interface {
	// To be implemented by the model struct. It should return the name of the
	// collection like "Users" or "Sites".
	Collection() string

	// Returns the change vector associated to the model when it was last
	// retrieved from the server. Automatically implemented with rdb.ModelTracking.
	// Deprecated: Use Tracking().ChangeVector() instead.
	ChangeVector() string

	// Returns tracking info like expiration or change vector.
	// Automatically implemented with rdb.ModelTracking.
	Tracking() *ModelTracking
	// contains filtered or unexported methods
}

type ModelEnforcer

type ModelEnforcer func(model Model) bool

type ModelMetadata

type ModelMetadata = api.ModelMetadata

type ModelTracking

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

func (*ModelTracking) ChangeVector

func (tracking *ModelTracking) ChangeVector() string

func (*ModelTracking) Expire added in v1.87.0

func (tracking *ModelTracking) Expire(t time.Time)

func (*ModelTracking) Expires added in v1.87.0

func (tracking *ModelTracking) Expires() time.Time

func (*ModelTracking) NeverExpire added in v1.87.0

func (tracking *ModelTracking) NeverExpire()

func (*ModelTracking) Tracking added in v1.87.0

func (tracking *ModelTracking) Tracking() *ModelTracking

type MultiError

type MultiError []error

MultiError stores a list of error when retrieving multiple models and only some of them may fail.

func (MultiError) Error

func (merr MultiError) Error() string

func (MultiError) HasError

func (merr MultiError) HasError() bool

HasError returns if the multi error really contains any error or all the rows have been successfully retrieved. You don't have to check this method most of the time because GetMulti, GetAll, etc. will return nil if there is no errors instead of an empty MultiError to avoid hard to debug bugs.

type OpenOption

type OpenOption func(db *Database)

func WithDebug

func WithDebug() OpenOption

WithDebug enables debug logging.

func WithLocalCreate

func WithLocalCreate() OpenOption

WithLocalCreate creates automatically the database if it doesn't exists. It can only be used in a local environment as it applies a pretty large hit to performance.

func WithStrongConsistency

func WithStrongConsistency() OpenOption

WithStrongConsistency forces every query to wait for the index to be ready and with no pending indexing operations.

This is probably only needed in tests and other rapidly changing environments, but not a normal production application.

func WithTestingMode

func WithTestingMode(t *testing.T) OpenOption

WithTestingMode enables flags and behaviours suited for unit tests. It implies WithLocalCreate() and WithStrongConsistency() and also creates a new database for each package tests.

We don't use the argument, but we require it to avoid errors when calling this function outside tests.

type Operation

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

func (*Operation) Progress

func (op *Operation) Progress(ctx context.Context) (OperationProgress, error)

func (*Operation) WaitFor

func (op *Operation) WaitFor(ctx context.Context, backoff time.Duration) error

type OperationProgress

type OperationProgress struct {
	Processed int64
	Total     int64
}

type Params

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

func NewParams

func NewParams() *Params

func (*Params) Next

func (p *Params) Next(value interface{}) string

type Query

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

func (*Query) Checksum

func (q *Query) Checksum() uint32

Checksum returns a checksum of the filters, conditions, table name, ... and other internal data of the collection that identifies it.

func (*Query) Clone

func (q *Query) Clone() *Query

func (*Query) Count

func (q *Query) Count(ctx context.Context) (int64, error)

func (*Query) DeleteEverything

func (q *Query) DeleteEverything(ctx context.Context) error

func (*Query) Filter

func (q *Query) Filter(field string, value interface{}) *Query

func (*Query) FilterBetween

func (q *Query) FilterBetween(field string, start, end interface{}) *Query

func (*Query) FilterContainsAll

func (q *Query) FilterContainsAll(field string, values ...interface{}) *Query

func (*Query) FilterEndsWith

func (q *Query) FilterEndsWith(field, suffix string) *Query

func (*Query) FilterHasField

func (q *Query) FilterHasField(field string) *Query

func (*Query) FilterIn

func (q *Query) FilterIn(field string, values ...interface{}) *Query

func (*Query) FilterNotExact

func (q *Query) FilterNotExact(field string, value interface{}) *Query

func (*Query) FilterSearch

func (q *Query) FilterSearch(field, search string, opts ...SearchOption) *Query

func (*Query) FilterStartsWith

func (q *Query) FilterStartsWith(field, prefix string) *Query

func (*Query) FilterSub

func (q *Query) FilterSub(filters ...QueryFilter) *Query

func (*Query) First

func (q *Query) First(ctx context.Context, dest interface{}, opts ...IncludeOption) error

func (*Query) ForceStrongConsistency

func (q *Query) ForceStrongConsistency() *Query

func (*Query) GetAll

func (q *Query) GetAll(ctx context.Context, dest interface{}, opts ...IncludeOption) error

func (*Query) GetAllIDs

func (q *Query) GetAllIDs(ctx context.Context) ([]string, error)

func (*Query) GetAllMetadata

func (q *Query) GetAllMetadata(ctx context.Context) ([]ModelMetadata, error)

func (*Query) HasResults

func (q *Query) HasResults(ctx context.Context) (bool, error)

func (*Query) Limit

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

func (*Query) Offset

func (q *Query) Offset(offset int64) *Query

func (*Query) OrderBy

func (q *Query) OrderBy(field string) *Query

func (*Query) OrderByAlpha

func (q *Query) OrderByAlpha(field string) *Query

func (*Query) OrderByAlphaNumeric

func (q *Query) OrderByAlphaNumeric(field string) *Query

func (*Query) OrderByNumeric

func (q *Query) OrderByNumeric(field string) *Query

func (*Query) Project

func (q *Query) Project(golden interface{}, fields ...string) *Query

func (*Query) RQL

func (q *Query) RQL() (string, map[string]interface{})

func (*Query) RandomOrder

func (q *Query) RandomOrder() *Query

func (*Query) Select

func (q *Query) Select(fields ...string) *Query

func (*Query) Stats

func (q *Query) Stats() QueryStats

Stats return general statistics about the query AFTER it is performed. Calling it before retrieving results would return a nil value.

func (*Query) String

func (q *Query) String() string

type QueryEnforcer

type QueryEnforcer func(q *Query) *Query

type QueryFilter

type QueryFilter interface {
	RQL(params *Params) string
}

func And

func And(children ...QueryFilter) QueryFilter

func Filter

func Filter(field string, value interface{}) QueryFilter

func FilterBetween

func FilterBetween(field string, start, end interface{}) QueryFilter

func FilterContainsAll

func FilterContainsAll(field string, values ...interface{}) QueryFilter

func FilterEndsWith

func FilterEndsWith(field, suffix string) QueryFilter

func FilterHasField

func FilterHasField(field string) QueryFilter

func FilterIn

func FilterIn(field string, values ...interface{}) QueryFilter

func FilterNotExact

func FilterNotExact(field string, value interface{}) QueryFilter

func FilterSearch

func FilterSearch(field, search string, opts ...SearchOption) QueryFilter

func FilterStartsWith

func FilterStartsWith(field, prefix string) QueryFilter

func Or

func Or(children ...QueryFilter) QueryFilter

type QueryStats

type QueryStats struct {
	// Total number of results of the query or collection ignoring pagination.
	TotalResults int64

	// Number of fake results skipped server side. This occurs during Distinct
	// queries and fan out indexes only.
	SkippedResults int64

	// Duration server side in milliseconds.
	DurationInMs int64

	// If the results are from an index, this flag tells us if the results
	// might be stale because the index was being rebuilt.
	IsStale bool

	// Name of the index or collection used to extract the results.
	IndexName string

	// Number of results of this page, or TotalResults if pagination
	// with Limit and Offset was not applied.
	ResultSize int64
}

type RQLQuery

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

func NewRQLQuery

func NewRQLQuery(query string) *RQLQuery

func (*RQLQuery) Clone

func (q *RQLQuery) Clone() *RQLQuery

func (*RQLQuery) Set

func (q *RQLQuery) Set(param string, value interface{})

type SearchOption

type SearchOption string

type Session

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

func SessionFromContext

func SessionFromContext(ctx context.Context) *Session

func (*Session) Counter

func (sess *Session) Counter(docID string, name string) *Counter

func (*Session) Load

func (sess *Session) Load(id string, dest interface{}) error

func (*Session) SaveChanges

func (sess *Session) SaveChanges(ctx context.Context) error

type UnexpectedStatusError

type UnexpectedStatusError struct {
	RequestMethod string
	RequestURL    *url.URL
	Status        string
	StatusCode    int
	Advanced      *AdvancedError
}

func NewUnexpectedStatusError

func NewUnexpectedStatusError(r *http.Request, resp *http.Response) UnexpectedStatusError

func (UnexpectedStatusError) Error

func (err UnexpectedStatusError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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