Documentation ¶
Index ¶
- Variables
- func ErrWithQueryAndParams(err error, q string, p []interface{}) error
- func ErrWithQueryAndParamsP(err error, q string, p ...interface{}) error
- type DB
- func (db DB) Close() error
- func (db DB) CreateChildDoc(table string, parentID uuid.UUID, doc []byte) (int64, error)
- func (db DB) CreateChildDocument(id uuid.UUID, doc interface{}, data []byte) (int64, error)
- func (db DB) CreateDocument(doc interface{}, data []byte) (int64, error)
- func (db DB) CreateDocumentWithID(id uuid.UUID, doc interface{}) error
- func (db DB) DeleteChildDocs(table string, parentID uuid.UUID) error
- func (db DB) DeleteChildDocuments(id uuid.UUID, doc interface{}) error
- func (db DB) ExecRaw(st string, params ...interface{}) (int64, error)
- func (db DB) GetAllDocs(table string) ([][]byte, error)
- func (db DB) GetAllDocsFromDocType(doc interface{}) ([][]byte, error)
- func (db DB) GetAllDocsFromDocTypeWithLimit(doc interface{}, offset, limit uint32) ([][]byte, error)
- func (db DB) GetAllDocsWithLimit(table string, offset, limit uint32) ([][]byte, error)
- func (db DB) GetChildDoc(table string, parentID, id uuid.UUID) ([]byte, error)
- func (db DB) GetChildDocs(table string, parentID uuid.UUID) ([][]byte, error)
- func (db DB) GetChildDocsFromDocType(doc interface{}, parentID uuid.UUID) ([][]byte, error)
- func (db DB) GetChildDocsFromDocTypeWithCondition(doc interface{}, parentID uuid.UUID, cond string, params ...interface{}) ([][]byte, error)
- func (db DB) GetChildDocsStatsForField(table, field string, parentID uuid.UUID) (map[string]int, error)
- func (db DB) GetChildDocsStatsFromDocType(doc interface{}, field string, parentID uuid.UUID) (map[string]int, error)
- func (db DB) GetChildDocsWithCondition(table string, parentID uuid.UUID, cond string, params ...interface{}) ([][]byte, error)
- func (db DB) GetDocByID(table string, id uuid.UUID) ([]byte, error)
- func (db DB) GetDocByIDFromDocType(doc interface{}, id uuid.UUID) error
- func (db DB) GetDocIDsWithCondFromDocType(doc interface{}, condition string, params ...interface{}) ([]string, error)
- func (db DB) GetDocIDsWithCondition(table, condition string, params ...interface{}) ([]string, error)
- func (db DB) GetDocsByField(table string, value string, path ...interface{}) ([][]byte, error)
- func (db DB) GetDocsByFieldFromDocType(doc interface{}, value string, path ...interface{}) ([][]byte, error)
- func (db DB) GetDocsByFieldLimit(table string, value string, offset, limit uint32, path ...interface{}) ([][]byte, error)
- func (db DB) GetDocsByFieldLimitFromDocType(doc interface{}, value string, offset, limit uint32, path ...interface{}) ([][]byte, error)
- func (db DB) GetParentID(childDoc interface{}, childID uuid.UUID) (uuid.UUID, error)
- func (db DB) GetParentIDDoc(table string, childID uuid.UUID) (uuid.UUID, error)
- func (db DB) InsertChildDocIfNotExists(table string, parentID uuid.UUID, childID uuid.UUID, index string, data []byte) (string, error)
- func (db DB) InsertChildDocIfNotExistsFromDocType(doc interface{}, parentID, id uuid.UUID, index string, data []byte) (string, error)
- func (db DB) InsertDoc(table string, doc []byte) (int64, error)
- func (db DB) InsertDocWithID(table string, id uuid.UUID, doc []byte) error
- func (db DB) Ping() error
- func (db DB) QueryRaw(query string, result []interface{}, params ...interface{}) error
- func (db DB) ReleaseLock(l *Lock) error
- func (db DB) TryGetLock(id string) (*Lock, error)
- func (db DB) UpsertChildDoc(table string, parentID, id uuid.UUID, doc []byte) error
- func (db DB) UpsertChildDocWithCondition(table string, parentID, id uuid.UUID, doc []byte, condition string, ...) (int64, error)
- func (db DB) UpsertChildDocumentWithData(parentID, id uuid.UUID, doc interface{}, data []byte, condition string, ...) (int64, error)
- func (db DB) UpsertDocWithCondition(table string, id uuid.UUID, doc []byte, condition string, ...) (int64, error)
- func (db DB) UpsertDocument(id uuid.UUID, doc interface{}, condition string, args ...interface{}) (int64, error)
- type Lock
Constants ¶
This section is empty.
Variables ¶
var ( // ErrAnonymousType error returned when a anonymous type is passed to UpdateDocument functions. ErrAnonymousType = errors.Default("anonymous types are not supported") )
Functions ¶
func ErrWithQueryAndParams ¶
ErrWithQueryAndParams includes information regarding the query that caused the error.
func ErrWithQueryAndParamsP ¶
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 (DB) CreateChildDoc ¶
CreateChildDoc inserts a new weak entity in a given table.
func (DB) CreateChildDocument ¶
CreateChildDocument creates a child document in the underlaying store.
func (DB) CreateDocument ¶
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 ¶
CreateDocumentWithID creates a document in the underlaying store
func (DB) DeleteChildDocs ¶
DeleteChildDocs deletes all the docs with the given parent id.
func (DB) DeleteChildDocuments ¶
DeleteChildDocuments deletes all the documents related to a given parent id.
func (DB) ExecRaw ¶
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 ¶
GetAllDocs gets all documents for a given table.
func (DB) GetAllDocsFromDocType ¶
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 ¶
GetAllDocsWithLimit returns all documents for a given table applying the given offset and limit.
func (DB) GetChildDoc ¶
GetChildDoc gets an existing child document from database
func (DB) GetChildDocs ¶
GetChildDocs gets all the child documents of a given parent.
func (DB) GetChildDocsFromDocType ¶
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 ¶
GetDocByID gets a document given its id.
func (DB) GetDocByIDFromDocType ¶
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 ¶
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 ¶
GetParentID returns the parent ID of the first row with the given childID.
func (DB) GetParentIDDoc ¶
GetParentIDDoc gets the parent id from a given ChildID
func (DB) InsertChildDocIfNotExists ¶
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) InsertDocWithID ¶
InsertDocWithID Creates a new document.
func (DB) Ping ¶
Ping pings the underlaying db to check its connected and prepared to receive commands.
func (DB) QueryRaw ¶
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) UpsertChildDoc ¶
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.