Documentation ¶
Index ¶
- Constants
- Variables
- func GetSingleTenant() string
- func IsMultiSchema() bool
- type CacheDriver
- type Cluster
- func (c *Cluster) BeginTransaction(ctx context.Context, tenant *Tenant, useCache bool) (*Transaction, error)
- func (c *Cluster) CreateTenant(ctx context.Context, tenant string) error
- func (c *Cluster) DropSingleTenant(ctx context.Context) error
- func (c *Cluster) DropTenant(ctx context.Context, tenant string) error
- func (c *Cluster) InitSingleTenant(ctx context.Context) error
- func (c *Cluster) Register(model *ModelDefinition)
- type ClusterInfo
- type DBRequestError
- type DBType
- type DBUnrecognizedOperatorError
- type DatabaseDriver
- type EventInterface
- type EventStore
- type ExternalDriver
- type Field
- type FieldType
- type Filter
- type ModelDefinition
- func (t *ModelDefinition) Delete(ctx context.Context, tx *Transaction, filters []*Filter) error
- func (t *ModelDefinition) GetStoreCustomFunctions() string
- func (t *ModelDefinition) Insert(ctx context.Context, tx *Transaction, records []ModelInterface) (interface{}, error)
- func (t *ModelDefinition) NestedFields() []Field
- func (t *ModelDefinition) Select(ctx context.Context, tx *Transaction, filters []*Filter, limit *uint, ...) (interface{}, error)
- func (t *ModelDefinition) Snake() string
- func (t *ModelDefinition) SourceFields() string
- func (t *ModelDefinition) StoredFields() []Field
- func (t *ModelDefinition) Title() string
- func (t *ModelDefinition) Update(ctx context.Context, tx *Transaction, filters []*Filter, record interface{}, ...) (interface{}, error)
- type ModelInterface
- type OrderByInput
- type Tenant
- type Transaction
- func (tx *Transaction) CommitTransaction(ctx context.Context, err error) error
- func (tx *Transaction) Delete(ctx context.Context, t *ModelDefinition, filters []*Filter) error
- func (tx *Transaction) Insert(ctx context.Context, t *ModelDefinition, records []ModelInterface) (interface{}, error)
- func (tx *Transaction) InsertEvents(ctx context.Context) error
- func (tx *Transaction) PublishEvents()
- func (tx *Transaction) RegisterEvent(aggregate string, aggregateUUID string, name string, payload []byte) error
- func (tx *Transaction) Select(ctx context.Context, t *ModelDefinition, filters []*Filter, limit *uint, ...) (interface{}, error)
- func (tx *Transaction) Update(ctx context.Context, t *ModelDefinition, filters []*Filter, record interface{}, ...) (interface{}, error)
Constants ¶
const CreatedAtField = "created_at"
CreatedAtField contains the name of the created_at field.
const STRING = "string"
STRING is a contains reprensenting the widely used string type.
const UpdatedAtField = "updated_at"
UpdatedAtField contains the name of the updated_at field.
Variables ¶
var EventDriver eventDriver
EventDriver is the driver which shall be used to generate event.
var MigrationPath = "migrations/"
MigrationPath contains the path to the directory containing the migrations.
var NatsClientToRemoveInFavorOfDriver *nats.Conn
var PostInitTenant func(context.Context) error
Functions ¶
func GetSingleTenant ¶
func GetSingleTenant() string
GetSingleTenant return the database tenant if we are in single tenant mode.
Types ¶
type CacheDriver ¶
type Cluster ¶
type Cluster struct { Driver DatabaseDriver MultiTenant bool Models []*ModelDefinition WriteInfo *ClusterInfo WriteCluster interface{} ReadInfo *ClusterInfo ReadCluster interface{} CacheDriver CacheDriver TenantDropper func(ctx context.Context, tenant string) error }
Cluster contain the connection to the database cluster.
func InitDB ¶
func InitDB( multiTenant bool, writeInfo *ClusterInfo, readInfo *ClusterInfo, memoryInfo *ClusterInfo, ) (*Cluster, error)
InitDB will initialize the connection with the specified credentials and return the cluster. nolint: unparam
func (*Cluster) BeginTransaction ¶
func (c *Cluster) BeginTransaction( ctx context.Context, tenant *Tenant, useCache bool, ) (*Transaction, error)
BeginTransaction will create a new transaction for this cluster and the specified tenant. nolint: unparam
func (*Cluster) CreateTenant ¶
CreateTenant will create the new specified tenant in multi tenant mode. nolint: unparam
func (*Cluster) DropSingleTenant ¶
DropSingleTenant will drop the single tenant. nolint: unparam
func (*Cluster) DropTenant ¶
DropTenant will drop the specified tenant. nolint: unparam
func (*Cluster) InitSingleTenant ¶
InitSingleTenant will initialize the database in single tenant mode. nolint: unparam
func (*Cluster) Register ¶
func (c *Cluster) Register(model *ModelDefinition)
Register will register the specified model in the specified cluster.
type ClusterInfo ¶
type ClusterInfo struct { Driver DatabaseDriver URL string Host string Port int32 User string Password string Database string }
ClusterInfo contains the credentials to connect to the database cluster.
type DBRequestError ¶
DBRequestError is an error returned when the database return an error.
func (*DBRequestError) Error ¶
func (e *DBRequestError) Error() string
Error return the error message.
type DBUnrecognizedOperatorError ¶
type DBUnrecognizedOperatorError struct {
O string
}
DBUnrecognizedOperatorError is an error returned when you use a non existing operator in filter.
func (*DBUnrecognizedOperatorError) Error ¶
func (e *DBUnrecognizedOperatorError) Error() string
Error return the error message.
type DatabaseDriver ¶
type DatabaseDriver interface { InitDB(writeInfo *ClusterInfo, readInfo *ClusterInfo) (*Cluster, error) CreateTenant(cluster *Cluster, tenant *Tenant) error BeginTransaction(c *Cluster, tenant *Tenant, useCache bool) (*Transaction, error) RollbackTransaction(*Transaction) error CommitTransaction(*Transaction) error GetTenant(*Transaction, *Tenant) (*Tenant, error) GenerateScanFunc(*ModelDefinition) string Select(context.Context, *Transaction, *ModelDefinition, []*Filter, *uint, []*OrderByInput) (interface{}, error) Insert(context.Context, *Transaction, *ModelDefinition, []ModelInterface) (interface{}, error) Update( context.Context, *Transaction, *ModelDefinition, []*Filter, interface{}, *fieldmask.FieldMask, ) (interface{}, error) Delete(context.Context, *Transaction, *ModelDefinition, []*Filter) error }
Driver is an interface for the drivers providing crud operations.
type EventInterface ¶
type EventInterface interface { ModelInterface GetName() string GetAggregate() string GetPayload() []byte }
type EventStore ¶
type EventStore interface {
NewEvent(string, string, string, []byte) EventInterface
}
EventStore ensure the EventModel contain the needed function.
type ExternalDriver ¶
type ExternalDriver interface { Get(context.Context, string, string) (interface{}, error) Select(context.Context, string, []*Filter) ([]interface{}, error) GetImportName() string GetImport() string }
Driver is an interface for the drivers providing crud operations.
type Field ¶
type Field interface { GetName() string NameWithoutUUID() string Title() string TitleWithoutUUID() string Snake() string Type() FieldType GoType() string ProtoType() string DBType() *DBType GraphqlType() string GraphqlSchemaType() string GetReferenceName() string GetReference() *ModelDefinition // GetReferenceDefinition() *ModelDefinition SetReference(*ModelDefinition) GetInverseField() string GetRequired() bool GetPrimaryKey() bool // GetFieldData() *FieldData IsStored() bool IsNested() bool }
Field is an interface to get the data from the field.
type ModelDefinition ¶
type ModelDefinition struct { Cluster *Cluster Store interface{} Name string Fields []Field Datetime bool SafeDelete bool CanAssignID bool NoID bool UseOneOf bool Gorm interface{} StoreCustomFunctions string DisableDatabaseStore bool ExternalDriver ExternalDriver }
ModelDefinition is the struct used to declare a new model definition. nolint: maligned
var EventModel *ModelDefinition
EventModel contain the definition of the event model.
var TenantModel *ModelDefinition
TenantModel contain the definition of the tenant model, used in multi tenant mode.
func (*ModelDefinition) Delete ¶
func (t *ModelDefinition) Delete(ctx context.Context, tx *Transaction, filters []*Filter) error
Delete can be called from the ModelDefinition and will delete the records in the cluster, filtered by the arguments. nolint: unparam
func (*ModelDefinition) GetStoreCustomFunctions ¶
func (t *ModelDefinition) GetStoreCustomFunctions() string
GetStoreCustomFunctions return the custom functions defined in this model.
func (*ModelDefinition) Insert ¶
func (t *ModelDefinition) Insert( ctx context.Context, tx *Transaction, records []ModelInterface) (interface{}, error)
Insert can be called from the ModelDefinition and will insert the records from the cluster, and return it. nolint: unparam
func (*ModelDefinition) NestedFields ¶
func (t *ModelDefinition) NestedFields() []Field
func (*ModelDefinition) Select ¶
func (t *ModelDefinition) Select( ctx context.Context, tx *Transaction, filters []*Filter, limit *uint, orderBy []*OrderByInput, ) (interface{}, error)
Select can be called from the ModelDefinition and will return the records from the cluster, filtered by the arguments. nolint: unparam
func (*ModelDefinition) Snake ¶
func (t *ModelDefinition) Snake() string
func (*ModelDefinition) SourceFields ¶
func (t *ModelDefinition) SourceFields() string
func (*ModelDefinition) StoredFields ¶
func (t *ModelDefinition) StoredFields() []Field
func (*ModelDefinition) Title ¶
func (t *ModelDefinition) Title() string
func (*ModelDefinition) Update ¶
func (t *ModelDefinition) Update( ctx context.Context, tx *Transaction, filters []*Filter, record interface{}, updateMask *fieldmask.FieldMask) (interface{}, error)
Update can be called from the ModelDefinition and will update the records in the cluster, filtered by the arguments. nolint: unparam
type ModelInterface ¶
type ModelInterface interface { GetUUID() string Marshal() ([]byte, error) Unmarshal([]byte) error }
ModelInterface is an interface containing the function on our model.
type OrderByInput ¶
OrderByInput is the struct used to declare the order by of our request.
type Tenant ¶
type Tenant struct { ID string `db:"id"` Name string `db:"name"` CreatedAt time.Time `json:"createdAt" db:"created_at"` UpdatedAt time.Time `json:"updatedAt" db:"updated_at"` }
Tenant is a struct containing the tenant information.
type Transaction ¶
type Transaction struct { Type string WriteTx interface{} ReadTx interface{} MemoryTx interface{} Cluster *Cluster Tenant *Tenant UseCache bool // contains filtered or unexported fields }
Transaction contains the information on the transaction.
func (*Transaction) CommitTransaction ¶
func (tx *Transaction) CommitTransaction(ctx context.Context, err error) error
CommitTransaction will commit the transaction. nolint: unparam
func (*Transaction) Delete ¶
func (tx *Transaction) Delete( ctx context.Context, t *ModelDefinition, filters []*Filter) error
Delete will delete the records, filtered by arguments.
func (*Transaction) Insert ¶
func (tx *Transaction) Insert( ctx context.Context, t *ModelDefinition, records []ModelInterface) (interface{}, error)
Insert will insert the records in the cluster.
func (*Transaction) InsertEvents ¶
func (tx *Transaction) InsertEvents(ctx context.Context) error
InsertEvents will insert the events in the database at the end of the transaction.
func (*Transaction) PublishEvents ¶
func (tx *Transaction) PublishEvents()
func (*Transaction) RegisterEvent ¶
func (tx *Transaction) RegisterEvent( aggregate string, aggregateUUID string, name string, payload []byte, ) error
RegisterEvent will register the event in the transaction event queue.
func (*Transaction) Select ¶
func (tx *Transaction) Select( ctx context.Context, t *ModelDefinition, filters []*Filter, limit *uint, orderBy []*OrderByInput, ) (interface{}, error)
Select will query the cluster to return the records, filtered by arguments.
func (*Transaction) Update ¶
func (tx *Transaction) Update( ctx context.Context, t *ModelDefinition, filters []*Filter, record interface{}, updateMask *fieldmask.FieldMask) (interface{}, error)
Update will update the records, filtered by arguments, with the specified data.