bucket

package module
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2019 License: GPL-3.0 Imports: 19 Imported by: 0

README

Bucket

Build Status Go Report Card Documentation

Simply Couchbase framework.

Project specifically focus on the one bucket as database approach and makes it easier to manage complex data sets. It tries to get rid of the embedded jsons per document and separate them into different documents behind the scenes.

Features:

  • Automatic index generator with indexable tags.
  • Simple usage through the handler.
  • Following best practices of Couchbase usage behind the scenes, which doesn't affect the user of the library.

Documentation

Index

Constants

View Source
const (
	FacetDate = iota
	FacetNumeric
	FacetTerm
)

Available facet types

Variables

View Source
var (
	// ErrDocumentTypeAlreadyExists document type already exist
	ErrDocumentTypeAlreadyExists = errors.New("document type already exists")

	// ErrDocumentTypeDoesntExists document type doesn't exist
	ErrDocumentTypeDoesntExists = errors.New("document type doesn't exist")

	// ErrEmptyField field must be filled
	ErrEmptyField = errors.New("field must be filled")

	// ErrEmptyIndex index must be filled
	ErrEmptyIndex = errors.New("index must be filled")

	// ErrEmptyType source type must be filled
	ErrEmptyType = errors.New("source type must set")

	// ErrEmptySource source name must be filled
	ErrEmptySource = errors.New("source name must set")

	// ErrEmptyRefTag referenced tag must be filled
	ErrEmptyRefTag = errors.New("referenced tag must set")

	// ErrConjunctionAndDisjunctionIsNil conjunction and disjunction are nil
	ErrConjunctionAndDisjunctionIsNil = errors.New("conjunction and disjunction are nil")

	// ErrEndAsTimeZero end as Time is zero instant
	ErrEndAsTimeZero = errors.New("endAsTime is zero instant")

	// ErrFirstParameterNotStruct first parameter is not a struct
	ErrFirstParameterNotStruct = errors.New("first parameter is not a struct")

	// ErrInputStructPointer input struct must be a pointer
	ErrInputStructPointer = errors.New("input struct must be pointer")

	// ErrInvalidBulkContainer bulk container type definition error
	ErrInvalidBulkContainer = errors.New("container must be *[]T, with length of ids array")

	// ErrInvalidGetDocumentTypesParam represents value for get document types should be pointer
	ErrInvalidGetDocumentTypesParam = errors.New("internal error: value should be pointer for getDocumentTypes")
)

Functions

This section is empty.

Types

type Cas

type Cas map[string]gocb.Cas

Cas is the container of Cas operation of all documents

type CompoundQueries

type CompoundQueries struct {
	Conjunction []SearchQuery `json:"conjuncts,omitempty"`
	Disjunction []SearchQuery `json:"disjuncts,omitempty"`

	Limit  int `json:"-"`
	Offset int `json:"-"`
}

CompoundQueries is a representation of the available search option for a CompoundSearch

type Configuration

type Configuration struct {
	Username         string `json:"username"`
	Password         string `json:"password"`
	BucketName       string `json:"bucket_name"`
	BucketPassword   string `json:"bucket_password"`
	ConnectionString string `json:"connection_string"`
	Separator        string `json:"separator"`

	Opts Opts `json:"bucket_opts"`
}

Configuration the main library configuration

type FacetDef

type FacetDef struct {
	Name  string
	Type  int
	Field string
	Size  int
}

FacetDef is a configuration helper for the search's facets

type Handler

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

Handler is the main handler

func New

func New(c *Configuration) (*Handler, error)

New creates and returns a new Handler

func (*Handler) CompoundSearch

func (h *Handler) CompoundSearch(ctx context.Context, index string, q *CompoundQueries) ([]gocb.SearchResultHit, error)

CompoundSearch apply the configuration of CompoundQueries and do the search then returns the hits

func (*Handler) CompoundSearchWithFacets

func (h *Handler) CompoundSearchWithFacets(ctx context.Context, index string, q *CompoundQueries, facets []FacetDef) ([]gocb.SearchResultHit, map[string]gocb.SearchResultFacet, error)

CompoundSearchWithFacets apply the configuration of CompoundQueries and do the search then returns the hits and facets

func (*Handler) CreateFullTextSearchIndex

func (h *Handler) CreateFullTextSearchIndex(ctx context.Context, def *IndexDefinition) error

CreateFullTextSearchIndex ...

func (*Handler) DeleteFullTextSearchIndex

func (h *Handler) DeleteFullTextSearchIndex(ctx context.Context, indexName string) error

DeleteFullTextSearchIndex ...

func (*Handler) Get

func (h *Handler) Get(ctx context.Context, typ, id string, ptr interface{}) error

Get retrieves a document from the bucket

func (*Handler) GetAndTouch

func (h *Handler) GetAndTouch(ctx context.Context, typ, id string, ptr interface{}, ttl uint32) error

GetAndTouch retrieves documents and simultaneously updates its expiry time.

func (*Handler) GetBulk

func (h *Handler) GetBulk(ctx context.Context, hits []gocb.SearchResultHit, container interface{}) error

GetBulk accepts a set of hits from a search and a container represents the data-structure and fill it up with the hits where the container should be *[]T type

func (*Handler) GetManager

func (h *Handler) GetManager(ctx context.Context) *gocb.BucketManager

GetManager returns a BucketManager for performing management operations on this bucket

func (*Handler) Index

func (h *Handler) Index(ctx context.Context, v interface{}) error

Index creates secondary indexes for the interface v

func (*Handler) Insert

func (h *Handler) Insert(ctx context.Context, typ, id string, q interface{}, ttl uint32) (Cas, string, error)

Insert inserts new documents to the bucket

func (*Handler) InspectFullTextSearchIndex

func (h *Handler) InspectFullTextSearchIndex(ctx context.Context, indexName string) (bool, *IndexDefinition, error)

InspectFullTextSearchIndex checks the availability of the index and returns it if exists

func (*Handler) Ping

func (h *Handler) Ping(ctx context.Context, services []gocb.ServiceType) (*gocb.PingReport, error)

Ping will ping a list of services and verify they are active

func (*Handler) RangeSearch

func (h *Handler) RangeSearch(ctx context.Context, index string, q *RangeQuery) ([]gocb.SearchResultHit, error)

RangeSearch apply the configuration of RangeQuery and do the search then returns the hits

func (*Handler) RangeSearchWithFacets

func (h *Handler) RangeSearchWithFacets(ctx context.Context, index string, q *RangeQuery, facets []FacetDef) ([]gocb.SearchResultHit, map[string]gocb.SearchResultFacet, error)

RangeSearchWithFacets apply the configuration of RangeQuery and do the search then returns the hits and facets

func (*Handler) Remove

func (h *Handler) Remove(ctx context.Context, typ, id string, ptr interface{}) error

Remove removes a document from the bucket

func (*Handler) SetDocumentType

func (h *Handler) SetDocumentType(ctx context.Context, name, prefix string) error

SetDocumentType adds document type to state

func (*Handler) SimpleSearch

func (h *Handler) SimpleSearch(ctx context.Context, index string, q *SearchQuery) ([]gocb.SearchResultHit, error)

SimpleSearch apply the configuration of SearchQuery and do the search then returns the hits

func (*Handler) SimpleSearchWithFacets

func (h *Handler) SimpleSearchWithFacets(ctx context.Context, index string, q *SearchQuery, facets []FacetDef) ([]gocb.SearchResultHit, map[string]gocb.SearchResultFacet, error)

SimpleSearchWithFacets apply the configuration of SearchQuery and do the search then returns the hits and facets

func (*Handler) Touch

func (h *Handler) Touch(ctx context.Context, typ, id string, ptr interface{}, ttl uint32) error

Touch touches documents, specifying a new expiry time for it. The Cas value must be 0.

func (*Handler) Upsert

func (h *Handler) Upsert(ctx context.Context, typ, id string, q interface{}, ttl uint32) (Cas, string, error)

Upsert perform an update/insert operation on the bucket

func (*Handler) ValidateState

func (h *Handler) ValidateState() (bool, error)

ValidateState validates the state

type IndexDefaultMapping

type IndexDefaultMapping struct {
	Dynamic bool `json:"dynamic"`
	Enabled bool `json:"enabled"`
}

IndexDefaultMapping ...

type IndexDefinition

type IndexDefinition struct {
	Type       string          `json:"type"`
	Name       string          `json:"name"`
	SourceType string          `json:"sourceType"`
	SourceName string          `json:"sourceName"`
	PlanParams IndexPlanParams `json:"planParams"`
	Params     IndexParams     `json:"params"`
}

IndexDefinition ...

func DefaultFullTextSearchIndexDefinition

func DefaultFullTextSearchIndexDefinition(meta IndexMeta) (*IndexDefinition, error)

DefaultFullTextSearchIndexDefinition creates a default index def for full-text search and return it in purpose to change default values manually

type IndexDefs

type IndexDefs struct {
	UUID      string                     `json:"uuid"`
	IndexDefs map[string]IndexDefinition `json:"indexDefs"`
}

IndexDefs ...

type IndexDocConfig

type IndexDocConfig struct {
	DocIDPrefixDelimiter string `json:"docid_prefix_delim"`
	DocIDRegexp          string `json:"docid_regexp"`
	Mode                 string `json:"mode"`
	TypeField            string `json:"type_field"`
}

IndexDocConfig ...

type IndexMapping

type IndexMapping struct {
	DefaultAnalyzer       string              `json:"default_analyzer"`
	DefaultDatetimeParser string              `json:"default_datetime_parser"`
	DefaultField          string              `json:"default_field"`
	DefaultMapping        IndexDefaultMapping `json:"default_mapping"`
	DefaultType           string              `json:"default_type"`
	DocvaluesDynamic      bool                `json:"docvalues_dynamic"`
	IndexDynamic          bool                `json:"index_dynamic"`
	StoreDynamic          bool                `json:"store_dynamic"`
	TypeField             string              `json:"type_field"`
}

IndexMapping ...

type IndexMeta

type IndexMeta struct {
	Name                 string
	SourceType           string
	SourceName           string
	DocIDPrefixDelimiter string
	DocIDRegexp          string
	TypeField            string
}

IndexMeta ...

type IndexParams

type IndexParams struct {
	DocConfig IndexDocConfig `json:"doc_config"`
	Mapping   IndexMapping   `json:"mapping"`
	Store     IndexStore     `json:"store"`
}

IndexParams ...

type IndexPlanParams

type IndexPlanParams struct {
	MaxPartitionsPerPIndex int64 `json:"maxPartitionsPerPIndex"`
}

IndexPlanParams ...

type IndexStore

type IndexStore struct {
	IndexType   string `json:"indexType"`
	KVStoreName string `json:"kvStoreName"`
}

IndexStore ...

type NullTimeout

type NullTimeout struct {
	Value time.Duration
	// contains filtered or unexported fields
}

NullTimeout is the library's built in NullTimeout type for Opts

func NullTimeoutFrom

func NullTimeoutFrom(dur time.Duration) NullTimeout

NullTimeoutFrom creates a NullTimeout with the given time.Duration

func NullTimeoutMillisec

func NullTimeoutMillisec(dur uint64) NullTimeout

NullTimeoutMillisec creates a NullTimeout with the given millisec

func NullTimeoutSec

func NullTimeoutSec(dur uint64) NullTimeout

NullTimeoutSec creates a NullTimeout with the given sec

type Opts

type Opts struct {
	OperationTimeout      NullTimeout `json:"operation_timeout"`
	BulkOperationTimeout  NullTimeout `json:"bulk_operation_timeout"`
	DurabilityTimeout     NullTimeout `json:"durability_timeout"`
	DurabilityPollTimeout NullTimeout `json:"durability_poll_timeout"`
	ViewTimeout           NullTimeout `json:"view_timeout"`
	N1qlTimeout           NullTimeout `json:"n1ql_timeout"`
	AnalyticsTimeout      NullTimeout `json:"analytics_timeout"`
}

Opts is the couchbase related configuration such as timeouts

type RangeQuery

type RangeQuery struct {
	StartAsTime time.Time `json:"-"`
	EndAsTime   time.Time `json:"-"`
	Start       string    `json:"start,omitempty"`
	End         string    `json:"end,omitempty"`

	Min int64 `json:"min,omitempty"`
	Max int64 `json:"max,omitempty"`

	InclusiveStart bool `json:"inclusive_start,omitempty"`
	InclusiveEnd   bool `json:"inclusive_end,omitempty"`
	InclusiveMin   bool `json:"inclusive_min,omitempty"`
	InclusiveMax   bool `json:"inclusive_max,omitempty"`

	Field string `json:"field,omitempty"`

	Limit  int `json:"-"`
	Offset int `json:"-"`
}

RangeQuery is a representation of the available search option for a RangeSearch

type SearchQuery

type SearchQuery struct {
	Query       string `json:"query,omitempty"`
	Match       string `json:"match,omitempty"`
	MatchPhrase string `json:"match_phrase,omitempty"`
	Term        string `json:"term,omitempty"`
	Prefix      string `json:"prefix,omitempty"`
	Regexp      string `json:"regexp,omitempty"`
	Wildcard    string `json:"wildcard,omitempty"`

	Field        string `json:"field,omitempty"`
	Analyzer     string `json:"analyzer,omitempty"`
	Fuzziness    int64  `json:"fuzziness,omitempty"`
	PrefixLength int64  `json:"prefix_length,omitempty"`

	Limit  int `json:"-"`
	Offset int `json:"-"`
}

SearchQuery is a representation of the available search option for a SimpleSearch

Jump to

Keyboard shortcuts

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