db

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package db holds the database layer for the Proxeus core

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NotFound

func NotFound(err error) bool

NotFound returns whether an error in the used db engine is of type not found

Types

type DB

type DB interface {
	// Get a value from a bucket
	Get(bucketName string, key interface{}, to interface{}, opts ...*GetOptions) error
	// Set a key/value pair into a bucket
	Set(bucketName string, key interface{}, value interface{}, opts ...*SetOptions) error
	// Delete deletes a key from a bucket
	Delete(bucketName string, key interface{}) error

	// Begin starts a new transaction
	Begin(writable bool) (DB, error)

	// WithBatch returns a new Node with the batch mode enabled.
	WithBatch(enabled bool) DB

	// Rollback rolls back the transaction
	Rollback() error

	// Commit commits the transaction
	Commit() error

	// Select a list of records that match a list of matchers.
	Select(matchers ...q.Matcher) Query

	// Init creates the indexes and buckets for a given structure
	Init(data interface{}) error
	// ReIndex rebuilds all the indexes of a bucket
	ReIndex(data interface{}) error
	// Save a structure
	Save(data interface{}) error
	// Update a structure
	Update(data interface{}) error
	// DeleteStruct deletes a structure from the associated bucket
	DeleteStruct(data interface{}) error

	// One returns one record by the specified index
	One(fieldName string, value interface{}, to interface{}) error
	// Count all the matching records
	Count(data interface{}) (int, error)
	// All gets all the records of a bucket. If there are no records it returns no error and the 'to' parameter is set to an empty slice.
	All(to interface{}) error

	Close() error
}

DB represents common set of the db API.

func OpenDatabase

func OpenDatabase(engine, uri, name string) (DB, error)

OpenDatabase returns a handle to the respective database chosen by the engine specified

type GetOptions

type GetOptions struct {
	NoTTLRefresh bool
}

func OptionWithNoTTLRefresh

func OptionWithNoTTLRefresh() *GetOptions

type MongoQuery

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

func (*MongoQuery) Each

func (q *MongoQuery) Each(kind interface{}, fn func(interface{}) error) error

Execute the given function for each element

func (*MongoQuery) Find

func (q *MongoQuery) Find(to interface{}) error

Find a list of matching records

func (*MongoQuery) First

func (q *MongoQuery) First(to interface{}) error

First gets the first matching record

func (*MongoQuery) Limit

func (q *MongoQuery) Limit(i int) Query

Limit the results by the given number

func (*MongoQuery) OrderBy

func (q *MongoQuery) OrderBy(str ...string) Query

Order by the given fields, in descending precedence, left-to-right.

func (*MongoQuery) Reverse

func (q *MongoQuery) Reverse() Query

Reverse the order of the results

func (*MongoQuery) Skip

func (q *MongoQuery) Skip(i int) Query

Skip matching records by the given number

type MongoShim

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

func OpenMongo

func OpenMongo(dbURI string, dbName string) (*MongoShim, error)

OpenMongo connects to the database using the specified URI and database name and returns a handle for accessing it

func (*MongoShim) All

func (s *MongoShim) All(to interface{}) error

All gets all the records of a bucket. If there are no records it returns no error and the 'to' parameter is set to an empty slice.

func (*MongoShim) Begin

func (s *MongoShim) Begin(_ bool) (DB, error)

Begin starts a new transaction

func (*MongoShim) Close

func (s *MongoShim) Close() error

Close disconnects the db client from the database

func (*MongoShim) Commit

func (s *MongoShim) Commit() error

Commit applies yet uncommited transactions of the current session

func (*MongoShim) Count

func (s *MongoShim) Count(data interface{}) (int, error)

Count all the matching records

func (*MongoShim) Delete

func (s *MongoShim) Delete(bucketName string, key interface{}) error

Delete deletes a key from a bucket

func (*MongoShim) DeleteStruct

func (s *MongoShim) DeleteStruct(data interface{}) error

DeleteStruct deletes a structure from the associated bucket

func (*MongoShim) Get

func (s *MongoShim) Get(bucketName string, key interface{}, to interface{}, opts ...*GetOptions) error

Get a value from a bucket

func (*MongoShim) Init

func (s *MongoShim) Init(data interface{}) error

Init creates the indexes and buckets for a given structure

func (*MongoShim) One

func (s *MongoShim) One(fieldName string, value interface{}, to interface{}) error

One returns one record by the specified index

func (*MongoShim) ReIndex

func (s *MongoShim) ReIndex(data interface{}) error

ReIndex rebuilds all the indexes of a bucket

func (*MongoShim) Rollback

func (s *MongoShim) Rollback() error

Rollback aborts the current session's uncommited transactions

func (*MongoShim) Save

func (s *MongoShim) Save(data interface{}) error

Save a structure

func (*MongoShim) Select

func (s *MongoShim) Select(matchers ...q.Matcher) Query

Select a list of records that match a list of matchers. Doesn't use indexes.

func (*MongoShim) Set

func (s *MongoShim) Set(bucketName string, key interface{}, value interface{}, opts ...*SetOptions) error

Set a key/value pair into a bucket

func (*MongoShim) Update

func (s *MongoShim) Update(data interface{}) error

Update a structure

func (*MongoShim) WithBatch

func (s *MongoShim) WithBatch(enabled bool) DB

type Query

type Query interface {
	// Skip matching records by the given number
	Skip(int) Query
	// Limit the results by the given number
	Limit(int) Query
	// Order by the given fields, in descending precedence, left-to-right
	OrderBy(str ...string) Query
	// Reverse the order of the results
	Reverse() Query
	// Find a list of matching records
	Find(to interface{}) error
	// First gets the first matching record
	First(to interface{}) error
	// Execute the given function for each element
	Each(kind interface{}, fn func(interface{}) error) error
}

Query allows to operate searches.

type SetOptions

type SetOptions struct {
	TTL time.Duration
}

func OptionWithTTL

func OptionWithTTL(ttl time.Duration) *SetOptions

type StormQueryShim

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

func (StormQueryShim) Each

func (s StormQueryShim) Each(kind interface{}, fn func(interface{}) error) error

Execute the given function for each element

func (StormQueryShim) Find

func (s StormQueryShim) Find(to interface{}) error

Find a list of matching records

func (StormQueryShim) First

func (s StormQueryShim) First(to interface{}) error

First gets the first matching record

func (StormQueryShim) Limit

func (s StormQueryShim) Limit(i int) Query

Limit the results by the given number

func (StormQueryShim) OrderBy

func (s StormQueryShim) OrderBy(str ...string) Query

Order by the given fields, in descending precedence, left-to-right

func (StormQueryShim) Reverse

func (s StormQueryShim) Reverse() Query

Reverse the order of the results

func (StormQueryShim) Skip

func (s StormQueryShim) Skip(i int) Query

Skip matching records by the given number

type StormShim

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

func OpenStorm

func OpenStorm(path string) (*StormShim, error)

OpenStorm opens a connection to the Storm database at the location specified by its path and returns a handle

func (*StormShim) All

func (s *StormShim) All(to interface{}) error

All gets all the records of a bucket. If there are no records it returns no error and the 'to' parameter is set to an empty slice.

func (*StormShim) Begin

func (s *StormShim) Begin(writable bool) (DB, error)

Begin starts a new transaction

func (*StormShim) Close

func (s *StormShim) Close() error

func (*StormShim) Commit

func (s *StormShim) Commit() error

Commit commits the current transaction

func (*StormShim) Count

func (s *StormShim) Count(data interface{}) (int, error)

Count all the matching records

func (*StormShim) Delete

func (s *StormShim) Delete(bucketName string, key interface{}) error

Delete deletes a key from a bucket

func (*StormShim) DeleteStruct

func (s *StormShim) DeleteStruct(data interface{}) error

DeleteStruct deletes a structure from the associated bucket

func (*StormShim) Get

func (s *StormShim) Get(bucketName string, key interface{}, to interface{}, opts ...*GetOptions) error

Get a value from a bucket

func (*StormShim) Init

func (s *StormShim) Init(data interface{}) error

Init creates the indexes and buckets for a given structure

func (*StormShim) One

func (s *StormShim) One(fieldName string, value interface{}, to interface{}) error

One returns one record by the specified index

func (*StormShim) ReIndex

func (s *StormShim) ReIndex(data interface{}) error

ReIndex rebuilds all the indexes of a bucket

func (*StormShim) Rollback

func (s *StormShim) Rollback() error

Rollback reverts the current transaction

func (*StormShim) Save

func (s *StormShim) Save(data interface{}) error

Save a structure

func (*StormShim) Select

func (s *StormShim) Select(matchers ...q.Matcher) Query

Select a list of records that match a list of matchers. Doesn't use indexes.

func (*StormShim) Set

func (s *StormShim) Set(bucketName string, key interface{}, value interface{}, opts ...*SetOptions) error

Set a key/value pair into a bucket

func (*StormShim) Update

func (s *StormShim) Update(data interface{}) error

Update a structure

func (*StormShim) WithBatch

func (s *StormShim) WithBatch(enabled bool) DB

Jump to

Keyboard shortcuts

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