libdata

package
v0.0.0-...-fda232b Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const CreatedAtField = "created_at"

CreatedAtField contains the name of the created_at field.

View Source
const STRING = "string"

STRING is a contains reprensenting the widely used string type.

View Source
const UpdatedAtField = "updated_at"

UpdatedAtField contains the name of the updated_at field.

Variables

View Source
var EventDriver eventDriver

EventDriver is the driver which shall be used to generate event.

View Source
var MigrationPath = "migrations/"

MigrationPath contains the path to the directory containing the migrations.

View Source
var NatsClientToRemoveInFavorOfDriver *nats.Conn
View Source
var PostInitTenant func(context.Context) error

Functions

func GetSingleTenant

func GetSingleTenant() string

GetSingleTenant return the database tenant if we are in single tenant mode.

func IsMultiSchema

func IsMultiSchema() bool

IsMultiSchema return if we are in multi schema mode.

Types

type CacheDriver

type CacheDriver interface {
	SetCache(string, []byte) error
	GetCache(string) ([]byte, error)
	InvalidateCache(string) bool
	SetRecordCache(string, string, string, []byte) error
	GetRecordCache(string, string, string) ([]byte, error)
	InvalidateRecordCache(string, string, string) bool
}

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

func (c *Cluster) CreateTenant(ctx context.Context, tenant string) error

CreateTenant will create the new specified tenant in multi tenant mode. nolint: unparam

func (*Cluster) DropSingleTenant

func (c *Cluster) DropSingleTenant(ctx context.Context) error

DropSingleTenant will drop the single tenant. nolint: unparam

func (*Cluster) DropTenant

func (c *Cluster) DropTenant(ctx context.Context, tenant string) error

DropTenant will drop the specified tenant. nolint: unparam

func (*Cluster) InitSingleTenant

func (c *Cluster) InitSingleTenant(ctx context.Context) error

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

type DBRequestError struct {
	Q string
	N string
	R string
}

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 DBType

type DBType struct {
	Type  string
	Value string
}

DBType contains the type and the value.

type DBUnrecognizedOperatorError

type DBUnrecognizedOperatorError struct {
	O string
}

DBUnrecognizedOperatorError is an error returned when you use a non existing operator in filter.

func (*DBUnrecognizedOperatorError) Error

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 FieldType

type FieldType string

FieldType is the generic type for a data field.

type Filter

type Filter struct {
	Field    string
	Operator string
	Operande interface{}
}

Filter is the struct used to declare a filter.

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

type OrderByInput struct {
	Field string
	Desc  bool
}

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.

Directories

Path Synopsis
drivers

Jump to

Keyboard shortcuts

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