db

package
v1.1.27 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAnonymousType error returned when a anonymous type is passed to UpdateDocument functions.
	ErrAnonymousType = errors.Default("anonymous types are not supported")
)

Functions

func ErrWithQueryAndParams

func ErrWithQueryAndParams(err error, q string, p []interface{}) error

ErrWithQueryAndParams includes information regarding the query that caused the error.

func ErrWithQueryAndParamsP

func ErrWithQueryAndParamsP(err error, q string, p ...interface{}) error

ErrWithQueryAndParamsP includes information regarding the query that caused the error.

Types

type DB

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

DB implements a 'low level' access methos for interacting with postgres as a json document store.

func NewDB

func NewDB(pDialect, connectionString string) (DB, error)

NewDB returns a connection to a Postgres instance

func (DB) Close

func (db DB) Close() error

Close close Store db connection

func (DB) CreateChildDoc

func (db DB) CreateChildDoc(table string, parentID uuid.UUID, doc []byte) (int64, error)

CreateChildDoc inserts a new weak entity in a given table.

func (DB) CreateChildDocument

func (db DB) CreateChildDocument(id uuid.UUID, doc interface{}, data []byte) (int64, error)

CreateChildDocument creates a child document in the underlaying store.

func (DB) CreateDocument

func (db DB) CreateDocument(doc interface{}, data []byte) (int64, error)

CreateDocument creates a document in the underlaying store. The doc parameter is only use the derive the name of the table to store the data.

func (DB) CreateDocumentWithID

func (db DB) CreateDocumentWithID(id uuid.UUID, doc interface{}) error

CreateDocumentWithID creates a document in the underlaying store

func (DB) DeleteChildDocs

func (db DB) DeleteChildDocs(table string, parentID uuid.UUID) error

DeleteChildDocs deletes all the docs with the given parent id.

func (DB) DeleteChildDocuments

func (db DB) DeleteChildDocuments(id uuid.UUID, doc interface{}) error

DeleteChildDocuments deletes all the documents related to a given parent id.

func (DB) ExecRaw

func (db DB) ExecRaw(st string, params ...interface{}) (int64, error)

ExecRaw allows to execute a query on the underlaying Postgresql store directly passing parameters. The query must set the parameters in the query using ?. The function returns the number of rows affected by the query.

func (DB) GetAllDocs

func (db DB) GetAllDocs(table string) ([][]byte, error)

GetAllDocs gets all documents for a given table.

func (DB) GetAllDocsFromDocType

func (db DB) GetAllDocsFromDocType(doc interface{}) ([][]byte, error)

GetAllDocsFromDocType returns the list of docs for the given doc type.

func (DB) GetAllDocsFromDocTypeWithLimit

func (db DB) GetAllDocsFromDocTypeWithLimit(doc interface{}, offset, limit uint32) ([][]byte, error)

GetAllDocsFromDocTypeWithLimit returns the list of docs for the given doc type applying the given offset and limit parameters.

func (DB) GetAllDocsWithLimit

func (db DB) GetAllDocsWithLimit(table string, offset, limit uint32) ([][]byte, error)

GetAllDocsWithLimit returns all documents for a given table applying the given offset and limit.

func (DB) GetChildDoc

func (db DB) GetChildDoc(table string, parentID, id uuid.UUID) ([]byte, error)

GetChildDoc gets an existing child document from database

func (DB) GetChildDocs

func (db DB) GetChildDocs(table string, parentID uuid.UUID) ([][]byte, error)

GetChildDocs gets all the child documents of a given parent.

func (DB) GetChildDocsFromDocType

func (db DB) GetChildDocsFromDocType(doc interface{}, parentID uuid.UUID) ([][]byte, error)

GetChildDocsFromDocType returns all child documents for a given parent ID

func (DB) GetChildDocsFromDocTypeWithCondition

func (db DB) GetChildDocsFromDocTypeWithCondition(doc interface{}, parentID uuid.UUID, cond string, params ...interface{}) ([][]byte, error)

GetChildDocsFromDocTypeWithCondition returns child documents for a given parent ID complying with a specific condition.

func (DB) GetChildDocsStatsForField

func (db DB) GetChildDocsStatsForField(table, field string, parentID uuid.UUID) (map[string]int, error)

GetChildDocsStatsForField gets the stats of all the child documents belonging to a given parentID. The type of the field must be marshalable into a string by the scan method of the postgres driver.

func (DB) GetChildDocsStatsFromDocType

func (db DB) GetChildDocsStatsFromDocType(doc interface{}, field string, parentID uuid.UUID) (map[string]int, error)

GetChildDocsStatsFromDocType returns a document given its id. the doc param must always be a pointer to a struct.

func (DB) GetChildDocsWithCondition

func (db DB) GetChildDocsWithCondition(table string, parentID uuid.UUID, cond string, params ...interface{}) ([][]byte, error)

GetChildDocsWithCondition gets all the child documents for a given parent and condition.

func (DB) GetDocByID

func (db DB) GetDocByID(table string, id uuid.UUID) ([]byte, error)

GetDocByID gets a document given its id.

func (DB) GetDocByIDFromDocType

func (db DB) GetDocByIDFromDocType(doc interface{}, id uuid.UUID) error

GetDocByIDFromDocType returns a document given its id. the doc param must always be a pointer to a struct.

func (DB) GetDocIDsWithCondFromDocType

func (db DB) GetDocIDsWithCondFromDocType(doc interface{}, condition string, params ...interface{}) ([]string, error)

GetDocIDsWithCondFromDocType returns all the id's of the documents that satisfy a given condition.

func (DB) GetDocIDsWithCondition

func (db DB) GetDocIDsWithCondition(table, condition string, params ...interface{}) ([]string, error)

GetDocIDsWithCondition returns the ID's of the documents that maches the given condition.

func (DB) GetDocsByField

func (db DB) GetDocsByField(table string, value string, path ...interface{}) ([][]byte, error)

GetDocsByField gets all documents that have a field in the specified path with a given value. The results are sorted by creation time.

func (DB) GetDocsByFieldFromDocType

func (db DB) GetDocsByFieldFromDocType(doc interface{}, value string, path ...interface{}) ([][]byte, error)

GetDocsByFieldFromDocType returns an slice of documents with a given a value for a given field in data. the doc param must always be a pointer to a struct.

func (DB) GetDocsByFieldLimit

func (db DB) GetDocsByFieldLimit(table string, value string, offset, limit uint32, path ...interface{}) ([][]byte, error)

GetDocsByFieldLimit gets all documents that have a field in the specified path with a given value. The results are sorted by the specified field and limited to the specified number of results. if limit the numbers of results is outbounded. The functions always returns the results sorted by creation time.

func (DB) GetDocsByFieldLimitFromDocType

func (db DB) GetDocsByFieldLimitFromDocType(doc interface{}, value string, offset, limit uint32, path ...interface{}) ([][]byte, error)

GetDocsByFieldLimitFromDocType returns an slice of documents with a given a value for a given field in data. The results are sorted by creation time and limited to the number of results specified by the limit param. The doc param must always be a pointer to a struct.

func (DB) GetParentID

func (db DB) GetParentID(childDoc interface{}, childID uuid.UUID) (uuid.UUID, error)

GetParentID returns the parent ID of the first row with the given childID.

func (DB) GetParentIDDoc

func (db DB) GetParentIDDoc(table string, childID uuid.UUID) (uuid.UUID, error)

GetParentIDDoc gets the parent id from a given ChildID

func (DB) InsertChildDocIfNotExists

func (db DB) InsertChildDocIfNotExists(table string, parentID uuid.UUID, childID uuid.UUID, index string, data []byte) (string, error)

func (DB) InsertChildDocIfNotExistsFromDocType

func (db DB) InsertChildDocIfNotExistsFromDocType(doc interface{}, parentID, id uuid.UUID, index string, data []byte) (string, error)

InsertChildDocIfNotExistsFromDocType this function inserts a new child doc, or updates a current one if it has the same parent id and index than the given ones.

func (DB) InsertDoc

func (db DB) InsertDoc(table string, doc []byte) (int64, error)

InsertDoc Creates a new document returning the assigned id.

func (DB) InsertDocWithID

func (db DB) InsertDocWithID(table string, id uuid.UUID, doc []byte) error

InsertDocWithID Creates a new document.

func (DB) Ping

func (db DB) Ping() error

Ping pings the underlaying db to check its connected and prepared to receive commands.

func (DB) QueryRaw

func (db DB) QueryRaw(query string, result []interface{}, params ...interface{}) error

QueryRaw executes a raw query and returns the data loaded in the given result structure. The result parameter must be a pointer to an structure, for instance &Example{} with fields matches the columns returned by the query. The function expects the query to return just one row.

func (DB) ReleaseLock

func (db DB) ReleaseLock(l *Lock) error

func (DB) TryGetLock

func (db DB) TryGetLock(id string) (*Lock, error)

func (DB) UpsertChildDoc

func (db DB) UpsertChildDoc(table string, parentID, id uuid.UUID, doc []byte) error

UpsertChildDoc adds or updates new document as a child of an existing one.

func (DB) UpsertChildDocWithCondition

func (db DB) UpsertChildDocWithCondition(table string, parentID, id uuid.UUID, doc []byte, condition string, params ...interface{}) (int64, error)

UpsertChildDocWithCondition adds or updates new document as child of an existing one protecting the update with a condition.

func (DB) UpsertChildDocumentWithData

func (db DB) UpsertChildDocumentWithData(parentID, id uuid.UUID, doc interface{}, data []byte, condition string, args ...interface{}) (int64, error)

UpsertChildDocumentWithData upserts a child document in the underlaying store if a condition is meet.

func (DB) UpsertDocWithCondition

func (db DB) UpsertDocWithCondition(table string, id uuid.UUID, doc []byte, condition string, params ...interface{}) (int64, error)

UpsertDocWithCondition Merges a document with the existing one depending on a condition. If the document does not exists returns and error. If it exists but does not meet the condition returns 0 rows affected. If exists and the condition is meet returns the number of rows affected.

func (DB) UpsertDocument

func (db DB) UpsertDocument(id uuid.UUID, doc interface{}, condition string, args ...interface{}) (int64, error)

UpsertDocument upserts a document in the underlaying store if a condition is meet.

type Lock

type Lock struct {
	Acquired bool
	ID       string
	// contains filtered or unexported fields
}

Lock represents the result of trying to acquire an advisory lock.

Jump to

Keyboard shortcuts

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