dao

package
v4.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2022 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package dao provides abstraction of persistence layer used by pydio services.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterDAODriver

func RegisterDAODriver(name string, daoF DaoProviderFunc, connF ConnProviderFunc)

RegisterDAODriver registers factories for DAOs and Connections

func RegisterIndexerDriver

func RegisterIndexerDriver(name string, daoF IndexerWrapperFunc)

RegisterIndexerDriver registers factories for Indexers

Types

type Conn

type Conn interface{}

func NewConn

func NewConn(d string, dsn string) (Conn, error)

type ConnDriver

type ConnDriver interface {
	Open(dsn string) (Conn, error)
	GetConn() Conn
	SetMaxConnectionsForWeight(int)
}

type ConnProviderFunc

type ConnProviderFunc func(driver, dsn string) ConnDriver

type DAO

type DAO interface {
	Init(configx.Values) error
	GetConn() Conn
	SetConn(Conn)
	CloseConn() error
	Driver() string

	// Prefix is used to prevent collision between table names
	// in case this DAO accesses a shared DB.
	Prefix() string
	// LocalAccess returns true if DAO relies on an on-file DB
	LocalAccess() bool
	// Stats may return info about the underlying driver/conn
	Stats() map[string]interface{}
}

DAO interface definition

func AbstractDAO

func AbstractDAO(conn Conn, driver string, prefix string) DAO

AbstractDAO returns a reference to a newly created struct that contains the necessary information to access a database. Prefix parameter is used to specify a prefix to avoid collision between table names in case this DAO accesses a shared DB: it thus will be an empty string in most of the cases.

func InitDAO

func InitDAO(driver, dsn, prefix string, wrapper func(DAO) DAO, cfg ...configx.Values) (DAO, error)

InitDAO finalize DAO creation based on registered drivers

func InitIndexer

func InitIndexer(driver, dsn, prefix string, wrapper func(DAO) DAO, cfg ...configx.Values) (DAO, error)

InitIndexer looks up in the register to initialize a DAO and wrap it as an IndexDAO

type DaoProviderFunc

type DaoProviderFunc func(driver, dsn, prefix string) (DAO, error)

type DriverProviderFunc

type DriverProviderFunc func() (string, string)

type FacetParser

type FacetParser interface {
	UnmarshalFacet(data interface{}, facets chan interface{})
	FlushCustomFacets() []interface{}
}

FacetParser adds additional capacities to IndexCodex for understanding search results Facets

type IndexCodex

type IndexCodex interface {
	// Marshal prepares an document for storing in index
	Marshal(input interface{}) (interface{}, error)
	// Unmarshal decodes a document found in index
	Unmarshal(indexed interface{}) (interface{}, error)
	// BuildQuery prepares a query to be executed. It returns a request object and optionnaly an aggregationRequest object
	BuildQuery(query interface{}, offset, limit int32) (interface{}, interface{}, error)
	// GetModel reads initialization schema to be loaded
	GetModel(sc configx.Values) (interface{}, bool)
}

IndexCodex is the coder/decoder used by an Indexer.

type IndexDAO

type IndexDAO interface {
	DAO
	// SetCodex sets the IndexCodex to be used for marshalling/unmarshalling data. Can be locally overriden during FindMany requests.
	SetCodex(c IndexCodex)
	// InsertOne stores one document. Write operations may be batched underneath.
	InsertOne(ctx context.Context, data interface{}) error
	// DeleteOne deletes one document. It can only be used if documents are providing IDs.
	DeleteOne(ctx context.Context, data interface{}) error
	// Flush triggers internal buffers to be written to storage
	Flush(ctx context.Context) error
	// DeleteMany deletes documents by a search query.
	DeleteMany(ctx context.Context, query interface{}) (int32, error)
	// FindMany sends a search query to indexer. A custom IndexCodex can be used to accumulate some information during results parsing.
	FindMany(ctx context.Context, query interface{}, offset, limit int32, customCodec IndexCodex) (chan interface{}, error)
	// Resync should clear the index and rewrite it from scratch. Used by bolt implementations for defragmentation.
	Resync(ctx context.Context, logger func(string)) error
	// Truncate should free some disk space. Used by bleve implementation in conjunction with rotationSize parameter.
	Truncate(ctx context.Context, max int64, logger func(string)) error
	// Close closes the index connection
	Close() error
}

IndexDAO is a rich DAO with ready-to-use inserts + search capacities. It must be initialised with a proper DAO and a proper IndexCodex.

type IndexIDProvider

type IndexIDProvider interface {
	IndexID() string
}

IndexIDProvider can be implemented by marshaled data to be indexed for providing an index ID.

type IndexerWrapperFunc

type IndexerWrapperFunc func(DAO) (IndexDAO, error)

type MigratorFunc

type MigratorFunc func(from DAO, to DAO, dryRun bool) (map[string]int, error)

type QueryOptionsProvider

type QueryOptionsProvider interface {
	BuildQueryOptions(query interface{}, offset, limit int32) (interface{}, error)
}

QueryOptionsProvider adds additional capacities to IndexCodex for building search Query

Directories

Path Synopsis
Package bleve provides tools for using Bolt as a standard persistence layer for services.
Package bleve provides tools for using Bolt as a standard persistence layer for services.
Package BoltDB provides tools for using Bolt as a standard persistence layer for services
Package BoltDB provides tools for using Bolt as a standard persistence layer for services

Jump to

Keyboard shortcuts

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