Documentation
¶
Index ¶
- Constants
- Variables
- func BoolPtrFromNullableBool(sqlBool sql.NullBool) *bool
- func CreateSingleTenantAccess(ctx context.Context, m2mTable string, tenantAccess *TenantAccess) error
- func CreateTenantAccessRecursively(ctx context.Context, m2mTable string, tenantAccess *TenantAccess) error
- func DeleteTenantAccessFromDirective(ctx context.Context, m2mTable string, resourceIDs, rootTenantIDs []string) error
- func DeleteTenantAccessFromParent(ctx context.Context, m2mTable string, childTenantID, parentTenantID string) error
- func DeleteTenantAccessRecursively(ctx context.Context, m2mTable string, tenant string, resourceIDs []string, ...) error
- func IntPtrFromNullableInt(i sql.NullInt32) *int
- func IsLockClauseProvided(lockClause string) bool
- func JSONRawMessageFromNullableString(sqlString sql.NullString) json.RawMessage
- func NewNullableBool(boolean *bool) sql.NullBool
- func NewNullableInt(i *int) sql.NullInt32
- func NewNullableString(text *string) sql.NullString
- func NewNullableStringFromJSONRawMessage(json json.RawMessage) sql.NullString
- func NewValidNullableBool(boolean bool) sql.NullBool
- func NewValidNullableString(text string) sql.NullString
- func StringPtrFromNullableString(sqlString sql.NullString) *string
- type AdvisoryLockResult
- type BaseEntity
- func (e *BaseEntity) GetCreatedAt() time.Time
- func (e *BaseEntity) GetDeletedAt() time.Time
- func (e *BaseEntity) GetError() sql.NullString
- func (e *BaseEntity) GetID() string
- func (e *BaseEntity) GetReady() bool
- func (e *BaseEntity) GetUpdatedAt() time.Time
- func (e *BaseEntity) SetCreatedAt(t time.Time)
- func (e *BaseEntity) SetDeletedAt(t time.Time)
- func (e *BaseEntity) SetError(err sql.NullString)
- func (e *BaseEntity) SetReady(ready bool)
- func (e *BaseEntity) SetUpdatedAt(t time.Time)
- type ChildEntity
- type Collection
- type Condition
- func NewEqualCondition(field string, val interface{}) Condition
- func NewExistsConditionForSubQuery(subQuery string, args []interface{}) Condition
- func NewInConditionForStringValues(field string, values []string) Condition
- func NewInConditionForSubQuery(field, subQuery string, args []interface{}) Condition
- func NewJSONArrAnyMatchCondition(field string, val []interface{}) Condition
- func NewJSONArrMatchAnyStringCondition(field string, values ...string) Condition
- func NewJSONCondition(field string, val interface{}) Condition
- func NewLessThanCondition(field string, val interface{}) Condition
- func NewLikeCondition(field string, val interface{}) Condition
- func NewNotEqualCondition(field string, val interface{}) Condition
- func NewNotNullCondition(field string) Condition
- func NewNotRegexConditionString(field string, value string) Condition
- func NewNullCondition(field string) Condition
- func NewTenantIsolationCondition(resourceType resource.Type, tenant string, ownerCheck bool) (Condition, error)
- func NewTenantIsolationConditionForNamedArgs(resourceType resource.Type, tenant string, ownerCheck bool) (Condition, error)
- type ConditionTree
- type ConditionTreeLister
- type ConditionTreeListerGlobal
- type Conditions
- type Creator
- type CreatorGlobal
- type Deleter
- type DeleterConditionTree
- type DeleterGlobal
- type Entity
- type EntityWithExternalTenant
- type ExistQuerier
- type ExistQuerierGlobal
- type ExistQuerierGlobalWithConditionTree
- type FunctionerGlobal
- type GroupByParams
- type IDs
- type Identifiable
- type Lister
- func NewLister(tableName string, selectedColumns []string) Lister
- func NewListerWithEmbeddedTenant(tableName string, tenantColumn string, selectedColumns []string) Lister
- func NewListerWithOrderBy(tableName string, selectedColumns []string, orderByParams OrderByParams) Lister
- func NewOwnerLister(tableName string, selectedColumns []string, ownerCheck bool) Lister
- type ListerGlobal
- type Operator
- type OrderBy
- type OrderByDir
- type OrderByParams
- type PageableQuerier
- type PageableQuerierGlobal
- type QueryBuilder
- type QueryBuilderGlobal
- type SingleGetter
- type SingleGetterGlobal
- type TenantAccess
- type TenantAccessCollection
- type UnionLister
- type UnionListerGlobal
- type UnsafeCreator
- type Updater
- type UpdaterGlobal
- type Upserter
- type UpserterGlobal
Constants ¶
const ( // ForUpdateLock Represents FOR UPDATE lock clause in SELECT queries. ForUpdateLock string = "FOR UPDATE" // NoLock Represents missing lock clause in SELECT queries. NoLock string = "" // NoLimit Represents missing limit clause in SELECT queries. NoLimit int = 0 // MaxINClauseArgsLimit Represents a limit for arguments for queries with IN clause. MaxINClauseArgsLimit int = 65500 )
const ( // M2MTenantIDColumn is the column name of the tenant_id in each tenant access table / view. M2MTenantIDColumn = "tenant_id" // M2MResourceIDColumn is the column name of the resource id in each tenant access table / view. M2MResourceIDColumn = "id" // M2MOwnerColumn is the column name of the owner in each tenant access table / view. M2MOwnerColumn = "owner" // M2MSourceColumn is the column name of the source in each tenant access table / view. M2MSourceColumn = "source" // CreateSingleTenantAccessQuery is a SQL query that creates a tenant access record CreateSingleTenantAccessQuery = `INSERT INTO %s ( %s ) VALUES ( %s ) ON CONFLICT ON CONSTRAINT tenant_applications_pkey DO NOTHING` // RecursiveCreateTenantAccessCTEQuery is a recursive SQL query that creates a tenant access record for a tenant and all its parents. RecursiveCreateTenantAccessCTEQuery = `` /* 1023-byte string literal not displayed */ // RecursiveDeleteTenantAccessCTEQuery is a recursive SQL query that deletes tenant accesses based on given conditions for a tenant and all its parents. RecursiveDeleteTenantAccessCTEQuery = `` /* 2410-byte string literal not displayed */ // DeleteDirectiveAccess is a query that deletes all the tenant accesses that have come from the directive. DeleteDirectiveAccess = `DELETE FROM %s a WHERE %s AND %s AND NOT EXISTS (SELECT 1 FROM %s ta WHERE ta.tenant_id = a.source AND ta.id = a.id);` // DeleteTenantAccessGrantedByParentQuery is a delete SQL query that deletes tenant accesses based on given tenant id and source. DeleteTenantAccessGrantedByParentQuery = `DELETE FROM %s WHERE tenant_id = ? AND source = ?` )
Variables ¶
var M2MColumns = []string{M2MTenantIDColumn, M2MResourceIDColumn, M2MOwnerColumn, M2MSourceColumn}
M2MColumns are the column names of the tenant access tables / views.
var NoOrderBy = OrderByParams{}
NoOrderBy represents default ordering (no order specified)
Functions ¶
func BoolPtrFromNullableBool ¶
BoolPtrFromNullableBool returns a bool pointer based on the given sql.NullBool
func CreateSingleTenantAccess ¶
func CreateSingleTenantAccess(ctx context.Context, m2mTable string, tenantAccess *TenantAccess) error
CreateSingleTenantAccess create a tenant access for a single entity
func CreateTenantAccessRecursively ¶
func CreateTenantAccessRecursively(ctx context.Context, m2mTable string, tenantAccess *TenantAccess) error
CreateTenantAccessRecursively creates the given tenantAccess in the provided m2mTable while making sure to recursively add it to all the parents of the given tenant. In case of conflict the entry is not updated
func DeleteTenantAccessFromDirective ¶
func DeleteTenantAccessFromDirective(ctx context.Context, m2mTable string, resourceIDs, rootTenantIDs []string) error
DeleteTenantAccessFromDirective deletes all the accesses to the provided resource IDs created from the directive for which the root tenant no longer has access record
func DeleteTenantAccessFromParent ¶
func DeleteTenantAccessFromParent(ctx context.Context, m2mTable string, childTenantID, parentTenantID string) error
DeleteTenantAccessFromParent deletes all the accesses to resources that were granted to childTenantID from parentTenantID. Such tenant accesses are granted through the directive
func DeleteTenantAccessRecursively ¶
func DeleteTenantAccessRecursively(ctx context.Context, m2mTable string, tenant string, resourceIDs []string, childTenant string) error
DeleteTenantAccessRecursively deletes all the accesses to the provided resource IDs for the given tenant and all its parents.
func IntPtrFromNullableInt ¶
IntPtrFromNullableInt returns an int pointer based on the given sql.NullInt32
func IsLockClauseProvided ¶
IsLockClauseProvided true if there is a non-empty lock clause provided, and false otherwise.
func JSONRawMessageFromNullableString ¶
func JSONRawMessageFromNullableString(sqlString sql.NullString) json.RawMessage
JSONRawMessageFromNullableString returns a json.RawMessage based on the given sql.NullString
func NewNullableBool ¶
NewNullableBool returns a new sql.NullBool based on the given bool pointer
func NewNullableInt ¶
NewNullableInt returns a new sql.NullInt32 based on the given int pointer
func NewNullableString ¶
func NewNullableString(text *string) sql.NullString
NewNullableString returns a new sql.NullString based on the given string pointer
func NewNullableStringFromJSONRawMessage ¶
func NewNullableStringFromJSONRawMessage(json json.RawMessage) sql.NullString
NewNullableStringFromJSONRawMessage returns a new sql.NullString based on the given json.RawMessage
func NewValidNullableBool ¶
NewValidNullableBool returns a new sql.NullBool based on the given bool
func NewValidNullableString ¶
func NewValidNullableString(text string) sql.NullString
NewValidNullableString returns a new sql.NullString based on the given string
func StringPtrFromNullableString ¶
func StringPtrFromNullableString(sqlString sql.NullString) *string
StringPtrFromNullableString returns a string pointer based on the given sql.NullString
Types ¶
type AdvisoryLockResult ¶
type AdvisoryLockResult struct {
IsLocked bool `db:"pg_try_advisory_xact_lock"`
}
AdvisoryLockResult is structure used for result when advisory lock is acquired.
type BaseEntity ¶
type BaseEntity struct { ID string `db:"id"` Ready bool `db:"ready"` CreatedAt *time.Time `db:"created_at"` UpdatedAt *time.Time `db:"updated_at"` DeletedAt *time.Time `db:"deleted_at"` Error sql.NullString `db:"error"` }
BaseEntity represents a base implementation of Entity
func (*BaseEntity) GetCreatedAt ¶
func (e *BaseEntity) GetCreatedAt() time.Time
GetCreatedAt returns the created_at value of the entity
func (*BaseEntity) GetDeletedAt ¶
func (e *BaseEntity) GetDeletedAt() time.Time
GetDeletedAt returns the deleted_at value of the entity
func (*BaseEntity) GetError ¶
func (e *BaseEntity) GetError() sql.NullString
GetError returns the error value of the entity
func (*BaseEntity) GetReady ¶
func (e *BaseEntity) GetReady() bool
GetReady returns the ready value of the entity
func (*BaseEntity) GetUpdatedAt ¶
func (e *BaseEntity) GetUpdatedAt() time.Time
GetUpdatedAt returns the updated_at value of the entity
func (*BaseEntity) SetCreatedAt ¶
func (e *BaseEntity) SetCreatedAt(t time.Time)
SetCreatedAt sets the created_at value of the entity
func (*BaseEntity) SetDeletedAt ¶
func (e *BaseEntity) SetDeletedAt(t time.Time)
SetDeletedAt sets the deleted_at value of the entity
func (*BaseEntity) SetError ¶
func (e *BaseEntity) SetError(err sql.NullString)
SetError sets the error value of the entity
func (*BaseEntity) SetReady ¶
func (e *BaseEntity) SetReady(ready bool)
SetReady sets the ready value of the entity
func (*BaseEntity) SetUpdatedAt ¶
func (e *BaseEntity) SetUpdatedAt(t time.Time)
SetUpdatedAt sets the updated_at value of the entity
type ChildEntity ¶
ChildEntity is an interface for a child entity that can be used to obtain its parent ID.
type Collection ¶
type Collection interface {
Len() int
}
Collection is an interface for a collection of entities.
type Condition ¶
type Condition interface { // GetQueryPart returns formatted string that will be included in the SQL query for a given condition GetQueryPart() string // GetQueryArgs returns a boolean flag if the condition contain arguments and the actual arguments // // For conditions like IN and IS NOT NULL there are no arguments to be included in the query. // For conditions like = there is a placeholder which value will be returned calling this func. GetQueryArgs() ([]interface{}, bool) }
Condition represents an SQL condition
func NewEqualCondition ¶
NewEqualCondition represents equal SQL condition (field = val)
func NewExistsConditionForSubQuery ¶
NewExistsConditionForSubQuery represents SQL EXISTS subquery (EXISTS (SELECT ...))
func NewInConditionForStringValues ¶
NewInConditionForStringValues represents SQL IN condition (field IN (?, ?, ...))
func NewInConditionForSubQuery ¶
NewInConditionForSubQuery represents SQL IN subquery (field IN (SELECT ...))
func NewJSONArrAnyMatchCondition ¶
NewJSONArrAnyMatchCondition represents PostgreSQL JSONB array any element match condition
func NewJSONArrMatchAnyStringCondition ¶
NewJSONArrMatchAnyStringCondition represents PostgreSQL JSONB string array any element match condition
func NewJSONCondition ¶
NewJSONCondition represents PostgreSQL JSONB contains condition
func NewLessThanCondition ¶
NewLessThanCondition represents less than SQL condition (field < val)
func NewLikeCondition ¶
NewLikeCondition represents SQL like condition (field like val)
func NewNotEqualCondition ¶
NewNotEqualCondition represents not equal SQL condition (field != val)
func NewNotNullCondition ¶
NewNotNullCondition represents SQL not null condition (field IS NOT NULL)
func NewNotRegexConditionString ¶
NewNotRegexConditionString represents SQL regex not match condition
func NewNullCondition ¶
NewNullCondition represents SQL null condition (field IS NULL)
func NewTenantIsolationCondition ¶
func NewTenantIsolationCondition(resourceType resource.Type, tenant string, ownerCheck bool) (Condition, error)
NewTenantIsolationCondition is a tenant isolation SQL subquery for entities that have tenant accesses managed outside of the entity table (m2m table or view). Conditionally an owner check is added to the subquery. In case of resource.BundleInstanceAuth additional embedded owner check is added.
type ConditionTree ¶
type ConditionTree struct { // Operator represents an SQL operator used to join the children conditions. This is populated only for non-leaf nodes. Operator Operator // Operand is the actual condition. This is populated only for leaf nodes. Operand Condition // Children is a slice of conditions. This is populated only for non-leaf nodes. Children []*ConditionTree }
ConditionTree represents a tree of conditions. The tree is constructed bottom to top. Leafs are the actual conditions. Intermediate nodes are operators joining them.
func And ¶
func And(children ...*ConditionTree) *ConditionTree
And joins given conditions with AND operator
func ConditionTreesFromConditions ¶
func ConditionTreesFromConditions(conditions Conditions) []*ConditionTree
ConditionTreesFromConditions builds a tree of conditions from a slice of conditions. The tree is constructed bottom to top.
func Or ¶
func Or(children ...*ConditionTree) *ConditionTree
Or joins given conditions with OR operator
func (*ConditionTree) BuildSubquery ¶
func (t *ConditionTree) BuildSubquery() (string, []interface{})
BuildSubquery builds SQL subquery for a given condition tree
func (*ConditionTree) IsLeaf ¶
func (t *ConditionTree) IsLeaf() bool
IsLeaf returns true if the node is a leaf node
type ConditionTreeLister ¶
type ConditionTreeLister interface {
ListConditionTree(ctx context.Context, resourceType resource.Type, tenant string, dest Collection, conditionTree *ConditionTree) error
}
ConditionTreeLister is an interface for listing tenant scoped entities with either externally managed tenant accesses (m2m table or view) or embedded tenant in them based on provided conditionTree.
func NewConditionTreeLister ¶
func NewConditionTreeLister(tableName string, selectedColumns []string) ConditionTreeLister
NewConditionTreeLister is a constructor for ConditionTreeLister about entities with externally managed tenant accesses (m2m table or view)
func NewConditionTreeListerWithEmbeddedTenant ¶
func NewConditionTreeListerWithEmbeddedTenant(tableName string, tenantColumn string, selectedColumns []string) ConditionTreeLister
NewConditionTreeListerWithEmbeddedTenant is a constructor for ConditionTreeLister about entities with tenant embedded in them.
type ConditionTreeListerGlobal ¶
type ConditionTreeListerGlobal interface {
ListConditionTreeGlobal(ctx context.Context, resourceType resource.Type, dest Collection, conditionTree *ConditionTree) error
}
ConditionTreeListerGlobal is an interface for listing entities by conditionTree globally.
func NewConditionTreeListerGlobal ¶
func NewConditionTreeListerGlobal(tableName string, selectedColumns []string) ConditionTreeListerGlobal
NewConditionTreeListerGlobal is a constructor for ConditionTreeListerGlobal.
type Creator ¶
type Creator interface { Create(ctx context.Context, resourceType resource.Type, tenant string, dbEntity interface{}) error SetParentAccessVerifier(func(ctx context.Context, parentResourceType resource.Type, parentID string) error) }
Creator is an interface for creating entities with externally managed tenant accesses (m2m table or view)
func NewCreator ¶
NewCreator is a constructor for Creator about entities with externally managed tenant accesses (m2m table or view)
func NewCreatorWithMatchingColumns ¶
func NewCreatorWithMatchingColumns(tableName string, columns []string, matcherColumns []string) Creator
NewCreatorWithMatchingColumns is a constructor for Creator about entities with externally managed tenant accesses (m2m table or view). In addition, matcherColumns can be added in order to identify already existing top-level entities and prevent their duplicate creation.
type CreatorGlobal ¶
CreatorGlobal is an interface for creating global entities without tenant or entities with tenant embedded in them.
func NewCreatorGlobal ¶
func NewCreatorGlobal(resourceType resource.Type, tableName string, columns []string) CreatorGlobal
NewCreatorGlobal is a constructor for GlobalCreator about entities without tenant or entities with tenant embedded in them.
type Deleter ¶
type Deleter interface { DeleteOne(ctx context.Context, resourceType resource.Type, tenant string, conditions Conditions) error DeleteMany(ctx context.Context, resourceType resource.Type, tenant string, conditions Conditions) error }
Deleter is an interface for deleting tenant scoped entities with either externally managed tenant accesses (m2m table or view) or embedded tenant in them.
func NewDeleter ¶
NewDeleter is a constructor for Deleter about entities with externally managed tenant accesses (m2m table or view)
func NewDeleterWithEmbeddedTenant ¶
NewDeleterWithEmbeddedTenant is a constructor for Deleter about entities with tenant embedded in them.
type DeleterConditionTree ¶
type DeleterConditionTree interface {
DeleteConditionTree(ctx context.Context, resourceType resource.Type, tenant string, conditionTree *ConditionTree) error
}
DeleterConditionTree deletes tenant scoped entities matching the provided condition tree with tenant isolation.
func NewDeleterConditionTree ¶
func NewDeleterConditionTree(tableName string) DeleterConditionTree
NewDeleterConditionTree is a constructor for Deleter about entities with externally managed tenant accesses (m2m table or view)
func NewDeleterConditionTreeWithEmbeddedTenant ¶
func NewDeleterConditionTreeWithEmbeddedTenant(tableName string, tenantColumn string) DeleterConditionTree
NewDeleterConditionTreeWithEmbeddedTenant is a constructor for Deleter about entities with externally managed tenant accesses (m2m table or view)
type DeleterGlobal ¶
type DeleterGlobal interface { DeleteOneGlobal(ctx context.Context, conditions Conditions) error DeleteManyGlobal(ctx context.Context, conditions Conditions) error }
DeleterGlobal is an interface for deleting global entities.
func NewDeleterGlobal ¶
func NewDeleterGlobal(resourceType resource.Type, tableName string) DeleterGlobal
NewDeleterGlobal is a constructor for DeleterGlobal about global entities.
type Entity ¶
type Entity interface { Identifiable GetReady() bool SetReady(ready bool) GetCreatedAt() time.Time SetCreatedAt(t time.Time) GetUpdatedAt() time.Time SetUpdatedAt(t time.Time) GetDeletedAt() time.Time SetDeletedAt(t time.Time) GetError() sql.NullString SetError(err sql.NullString) }
Entity denotes an DB-layer entity which can be timestamped with created_at, updated_at, deleted_at and ready values
type EntityWithExternalTenant ¶
type EntityWithExternalTenant interface {
DecorateWithTenantID(tenant string) interface{}
}
EntityWithExternalTenant is an interface that can be used for object with an external tenant to add tenant_id to the struct. This is needed for update operations when we want to use named arguments in the SQL queries.
type ExistQuerier ¶
type ExistQuerier interface {
Exists(ctx context.Context, resourceType resource.Type, tenant string, conditions Conditions) (bool, error)
}
ExistQuerier is an interface for checking existence of tenant scoped entities with either externally managed tenant accesses (m2m table or view) or embedded tenant in them.
func NewExistQuerier ¶
func NewExistQuerier(tableName string) ExistQuerier
NewExistQuerier is a constructor for ExistQuerier about entities with externally managed tenant accesses (m2m table or view)
func NewExistQuerierWithEmbeddedTenant ¶
func NewExistQuerierWithEmbeddedTenant(tableName string, tenantColumn string) ExistQuerier
NewExistQuerierWithEmbeddedTenant is a constructor for ExistQuerier about entities with tenant embedded in them.
func NewExistQuerierWithOwnerCheck ¶
func NewExistQuerierWithOwnerCheck(tableName string) ExistQuerier
NewExistQuerierWithOwnerCheck is a constructor for ExistQuerier about entities with externally managed tenant accesses (m2m table or view) with additional owner check.
type ExistQuerierGlobal ¶
type ExistQuerierGlobal interface {
ExistsGlobal(ctx context.Context, conditions Conditions) (bool, error)
}
ExistQuerierGlobal is an interface for checking existence of global entities.
func NewExistQuerierGlobal ¶
func NewExistQuerierGlobal(resourceType resource.Type, tableName string) ExistQuerierGlobal
NewExistQuerierGlobal is a constructor for ExistQuerierGlobal about global entities.
type ExistQuerierGlobalWithConditionTree ¶
type ExistQuerierGlobalWithConditionTree interface {
ExistsGlobalWithConditionTree(ctx context.Context, conditionTree *ConditionTree) (bool, error)
}
ExistQuerierGlobalWithConditionTree is an interface for checking existence of global entities.
func NewExistsQuerierGlobalWithConditionTree ¶
func NewExistsQuerierGlobalWithConditionTree(resourceType resource.Type, tableName string) ExistQuerierGlobalWithConditionTree
NewExistsQuerierGlobalWithConditionTree is a constructor for ExistQuerierGlobalWithConditionTree about global entities.
type FunctionerGlobal ¶
type FunctionerGlobal interface {
AdvisoryLock(ctx context.Context, identifier int64) (bool, error)
}
FunctionerGlobal is an interface for invoking functions.
func NewFunctionerGlobal ¶
func NewFunctionerGlobal() FunctionerGlobal
NewFunctionerGlobal is a constructor for DBFunction .
type Identifiable ¶
type Identifiable interface {
GetID() string
}
Identifiable is an interface that can be used to identify an object.
type Lister ¶
type Lister interface { List(ctx context.Context, resourceType resource.Type, tenant string, dest Collection, additionalConditions ...Condition) error ListWithSelectForUpdate(ctx context.Context, resourceType resource.Type, tenant string, dest Collection, additionalConditions ...Condition) error SetSelectedColumns(selectedColumns []string) Clone() *universalLister }
Lister is an interface for listing tenant scoped entities with either externally managed tenant accesses (m2m table or view) or embedded tenant in them.
func NewLister ¶
NewLister is a constructor for Lister about entities with externally managed tenant accesses (m2m table or view)
func NewListerWithEmbeddedTenant ¶
func NewListerWithEmbeddedTenant(tableName string, tenantColumn string, selectedColumns []string) Lister
NewListerWithEmbeddedTenant is a constructor for Lister about entities with tenant embedded in them.
func NewListerWithOrderBy ¶
func NewListerWithOrderBy(tableName string, selectedColumns []string, orderByParams OrderByParams) Lister
NewListerWithOrderBy is a constructor for Lister about entities with externally managed tenant accesses (m2m table or view) with additional order by clause.
type ListerGlobal ¶
type ListerGlobal interface { ListGlobal(ctx context.Context, dest Collection, additionalConditions ...Condition) error ListGlobalWithSelectForUpdate(ctx context.Context, dest Collection, additionalConditions ...Condition) error ListGlobalWithLimit(ctx context.Context, dest Collection, limit int, additionalConditions ...Condition) error SetSelectedColumns(selectedColumns []string) Clone() *universalLister }
ListerGlobal is an interface for listing global entities.
func NewListerGlobal ¶
func NewListerGlobal(resourceType resource.Type, tableName string, selectedColumns []string) ListerGlobal
NewListerGlobal is a constructor for ListerGlobal about global entities.
func NewListerGlobalWithOrderBy ¶
func NewListerGlobalWithOrderBy(resourceType resource.Type, tableName string, selectedColumns []string, orderByParams OrderByParams) ListerGlobal
NewListerGlobalWithOrderBy is a constructor for ListerGlobal about global entities with additional order by clause.
type OrderBy ¶
type OrderBy struct { Field string Dir OrderByDir }
OrderBy type that wraps the information about the ordering column and direction
func NewAscOrderBy ¶
NewAscOrderBy returns wrapping type for ascending order for a given column (field)
func NewDescOrderBy ¶
NewDescOrderBy returns wrapping type for descending ordered for a given column (field)
type OrderByDir ¶
type OrderByDir string
OrderByDir is a type encapsulating the ORDER BY direction
const ( // AscOrderBy defines ascending order AscOrderBy OrderByDir = "ASC" // DescOrderBy defines descending order DescOrderBy OrderByDir = "DESC" )
type OrderByParams ¶
type OrderByParams []OrderBy
OrderByParams is a wrapping type for slice of OrderBy types
type PageableQuerier ¶
type PageableQuerier interface {
List(ctx context.Context, resourceType resource.Type, tenant string, pageSize int, cursor string, orderByColumn string, dest Collection, additionalConditions ...Condition) (*pagination.Page, int, error)
}
PageableQuerier is an interface for listing with paging of tenant scoped entities with either externally managed tenant accesses (m2m table or view) or embedded tenant in them.
func NewPageableQuerier ¶
func NewPageableQuerier(tableName string, selectedColumns []string) PageableQuerier
NewPageableQuerier is a constructor for PageableQuerier about entities with externally managed tenant accesses (m2m table or view)
func NewPageableQuerierWithEmbeddedTenant ¶
func NewPageableQuerierWithEmbeddedTenant(tableName string, tenantColumn string, selectedColumns []string) PageableQuerier
NewPageableQuerierWithEmbeddedTenant is a constructor for PageableQuerier about entities with tenant embedded in them.
type PageableQuerierGlobal ¶
type PageableQuerierGlobal interface { ListGlobal(ctx context.Context, pageSize int, cursor string, orderByColumn string, dest Collection) (*pagination.Page, int, error) ListGlobalWithAdditionalConditions(ctx context.Context, pageSize int, cursor string, orderByColumn string, dest Collection, conditions *ConditionTree) (*pagination.Page, int, error) ListGlobalWithSelectForUpdate(ctx context.Context, pageSize int, cursor string, orderByColumn string, dest Collection) (*pagination.Page, int, error) }
PageableQuerierGlobal is an interface for listing with paging of global entities.
func NewPageableQuerierGlobal ¶
func NewPageableQuerierGlobal(resourceType resource.Type, tableName string, selectedColumns []string) PageableQuerierGlobal
NewPageableQuerierGlobal is a constructor for PageableQuerierGlobal about global entities.
type QueryBuilder ¶
type QueryBuilder interface {
BuildQuery(resourceType resource.Type, tenantID string, isRebindingNeeded bool, conditions ...Condition) (string, []interface{}, error)
}
QueryBuilder is an interface for building queries about tenant scoped entities with either externally managed tenant accesses (m2m table or view) or embedded tenant in them.
func NewQueryBuilder ¶
func NewQueryBuilder(tableName string, selectedColumns []string) QueryBuilder
NewQueryBuilder is a constructor for QueryBuilder about entities with externally managed tenant accesses (m2m table or view)
func NewQueryBuilderWithEmbeddedTenant ¶
func NewQueryBuilderWithEmbeddedTenant(tableName string, tenantColumn string, selectedColumns []string) QueryBuilder
NewQueryBuilderWithEmbeddedTenant is a constructor for QueryBuilder about entities with tenant embedded in them.
type QueryBuilderGlobal ¶
type QueryBuilderGlobal interface { BuildQueryGlobal(isRebindingNeeded bool, conditions ...Condition) (string, []interface{}, error) BuildQueryGlobalWithLimit(isRebindingNeeded bool, limit int, conditions ...Condition) (string, []interface{}, error) }
QueryBuilderGlobal is an interface for building queries about global entities.
func NewQueryBuilderGlobal ¶
func NewQueryBuilderGlobal(resourceType resource.Type, tableName string, selectedColumns []string) QueryBuilderGlobal
NewQueryBuilderGlobal is a constructor for QueryBuilderGlobal about global entities.
type SingleGetter ¶
type SingleGetter interface { Get(ctx context.Context, resourceType resource.Type, tenant string, conditions Conditions, orderByParams OrderByParams, dest interface{}) error GetForUpdate(ctx context.Context, resourceType resource.Type, tenant string, conditions Conditions, orderByParams OrderByParams, dest interface{}) error }
SingleGetter is an interface for getting tenant scoped entities with either externally managed tenant accesses (m2m table or view) or embedded tenant in them.
func NewSingleGetter ¶
func NewSingleGetter(tableName string, selectedColumns []string) SingleGetter
NewSingleGetter is a constructor for SingleGetter about entities with externally managed tenant accesses (m2m table or view)
func NewSingleGetterWithEmbeddedTenant ¶
func NewSingleGetterWithEmbeddedTenant(tableName string, tenantColumn string, selectedColumns []string) SingleGetter
NewSingleGetterWithEmbeddedTenant is a constructor for SingleGetter about entities with tenant embedded in them.
type SingleGetterGlobal ¶
type SingleGetterGlobal interface {
GetGlobal(ctx context.Context, conditions Conditions, orderByParams OrderByParams, dest interface{}) error
}
SingleGetterGlobal is an interface for getting global entities.
func NewSingleGetterGlobal ¶
func NewSingleGetterGlobal(resourceType resource.Type, tableName string, selectedColumns []string) SingleGetterGlobal
NewSingleGetterGlobal is a constructor for SingleGetterGlobal about global entities.
type TenantAccess ¶
type TenantAccess struct { TenantID string `db:"tenant_id"` ResourceID string `db:"id"` Owner bool `db:"owner"` Source string `db:"source"` }
TenantAccess represents the tenant access table/views that are used for tenant isolation queries.
func GetSingleTenantAccess ¶
func GetSingleTenantAccess(ctx context.Context, m2mTable string, tenantID, resourceID string) (*TenantAccess, error)
GetSingleTenantAccess gets a tenant access record for tenant with ID tenantID and resource with ID resourceID
type TenantAccessCollection ¶
type TenantAccessCollection []TenantAccess
TenantAccessCollection is a wrapper type for slice of entities.
func (TenantAccessCollection) Len ¶
func (tc TenantAccessCollection) Len() int
Len returns the current number of entities in the collection.
type UnionLister ¶
type UnionLister interface { // List stores the result into dest and returns the total count of tuples for each id from ids List(ctx context.Context, resourceType resource.Type, tenant string, ids []string, idsColumn string, pageSize int, cursor string, orderBy OrderByParams, dest Collection, additionalConditions ...Condition) (map[string]int, error) }
UnionLister is an interface for listing tenant scoped entities with either externally managed tenant accesses (m2m table or view) or embedded tenant in them. It lists entities based on multiple parent queries. For each parent a separate list with a separate tenant isolation subquery is created and the end result is a union of all the results.
func NewUnionLister ¶
func NewUnionLister(tableName string, selectedColumns []string) UnionLister
NewUnionLister is a constructor for UnionLister about entities with externally managed tenant accesses (m2m table or view)
func NewUnionListerWithEmbeddedTenant ¶
func NewUnionListerWithEmbeddedTenant(tableName string, tenantColumn string, selectedColumns []string) UnionLister
NewUnionListerWithEmbeddedTenant is a constructor for UnionLister about entities with tenant embedded in them.
type UnionListerGlobal ¶
type UnionListerGlobal interface { ListGlobal(ctx context.Context, ids []string, idsColumn string, pageSize int, cursor string, orderBy OrderByParams, dest Collection, additionalConditions ...Condition) (map[string]int, error) SetSelectedColumns(selectedColumns []string) Clone() *unionLister }
UnionListerGlobal is an interface for listing global entities. It lists entities based on multiple parent queries. For each parent a separate list with a separate tenant isolation subquery is created and the end result is a union of all the results.
func NewUnionListerGlobal ¶
func NewUnionListerGlobal(resourceType resource.Type, tableName string, selectedColumns []string) UnionListerGlobal
NewUnionListerGlobal is a constructor for UnionListerGlobal about global entities.
type UnsafeCreator ¶
UnsafeCreator is used to create new entities in case they do not exist. In case they do already exist, no action is taken, hence the provided entity ID is not guaranteed to match the ID in the Compass DB.
func NewUnsafeCreator ¶
func NewUnsafeCreator(resourceType resource.Type, tableName string, insertColumns []string, conflictingColumns []string) UnsafeCreator
NewUnsafeCreator returns a new Creator which supports creation with conflicts.
type Updater ¶
type Updater interface { UpdateSingle(ctx context.Context, resourceType resource.Type, tenant string, dbEntity interface{}) error UpdateSingleWithVersion(ctx context.Context, resourceType resource.Type, tenant string, dbEntity interface{}) error }
Updater is an interface for updating entities with externally managed tenant accesses (m2m table or view)
type UpdaterGlobal ¶
type UpdaterGlobal interface { UpdateSingleGlobal(ctx context.Context, dbEntity interface{}) error UpdateSingleWithVersionGlobal(ctx context.Context, dbEntity interface{}) error UpdateFieldsGlobal(ctx context.Context, conditions Conditions, newValues map[string]interface{}) error SetIDColumns(idColumns []string) SetUpdatableColumns(updatableColumns []string) TechnicalUpdate(ctx context.Context, dbEntity interface{}) error Clone() UpdaterGlobal }
UpdaterGlobal is an interface for updating global entities without tenant or entities with tenant embedded in them.
func NewUpdaterGlobal ¶
func NewUpdaterGlobal(resourceType resource.Type, tableName string, updatableColumns []string, idColumns []string) UpdaterGlobal
NewUpdaterGlobal is a constructor for UpdaterGlobal about global entities without tenant.
func NewUpdaterWithEmbeddedTenant ¶
func NewUpdaterWithEmbeddedTenant(resourceType resource.Type, tableName string, updatableColumns []string, tenantColumn string, idColumns []string) UpdaterGlobal
NewUpdaterWithEmbeddedTenant is a constructor for UpdaterGlobal about entities with tenant embedded in them.
type Upserter ¶
type Upserter interface {
Upsert(ctx context.Context, resourceType resource.Type, tenant string, dbEntity interface{}) (string, error)
}
Upserter is an interface for upserting entities with externally managed tenant accesses (m2m table or view)
func NewTrustedUpserter ¶
func NewTrustedUpserter(tableName string, insertColumns []string, conflictingColumns []string, updateColumns []string) Upserter
NewTrustedUpserter is a constructor for Upserter about entities with externally managed tenant accesses (m2m table or view) which ignores the tenant isolation
type UpserterGlobal ¶
UpserterGlobal is an interface for upserting global entities without tenant or entities with tenant embedded in them.
func NewUpserterGlobal ¶
func NewUpserterGlobal(resourceType resource.Type, tableName string, insertColumns []string, conflictingColumns []string, updateColumns []string) UpserterGlobal
NewUpserterGlobal is a constructor for UpserterGlobal about global entities without tenant.
func NewUpserterWithEmbeddedTenant ¶
func NewUpserterWithEmbeddedTenant(resourceType resource.Type, tableName string, insertColumns []string, conflictingColumns []string, updateColumns []string, tenantColumn string) UpserterGlobal
NewUpserterWithEmbeddedTenant is a constructor for Upserter about entities with tenant embedded in them.