Documentation ¶
Index ¶
- Variables
- func NewContext(ctx *context.Context, q Queryer) *context.Context
- func TestConnectDB(t *testing.T, connectionInfo string) *sqlx.DB
- func TestMigrateUp(t *testing.T, DBConnectionString string, sourceDriver RiceBoxSource, ...)
- func TestTruncateAll(t *testing.T, connectionInfo string, databaseName string)
- func TransformObject(source interface{}, result interface{}) error
- type ActivityLog
- type GenericStorage
- type ImmutableGenericStorage
- type LogStorage
- type Manager
- type PostgresConfig
- type PostgresStorage
- func (r *PostgresStorage) CountAll(ctx *context.Context, count interface{}) error
- func (r *PostgresStorage) Delete(ctx *context.Context, id interface{}) error
- func (r *PostgresStorage) DeleteMany(ctx *context.Context, ids interface{}) error
- func (r *PostgresStorage) ExecQuery(ctx *context.Context, query string, args map[string]interface{}) error
- func (r *PostgresStorage) FindAll(ctx *context.Context, elems interface{}, page int, limit int, isAsc bool) error
- func (r *PostgresStorage) FindByID(ctx *context.Context, elem interface{}, id interface{}) error
- func (r *PostgresStorage) HardDelete(ctx *context.Context, id interface{}) error
- func (r *PostgresStorage) Insert(ctx *context.Context, elem interface{}) error
- func (r *PostgresStorage) InsertMany(ctx *context.Context, elem interface{}) error
- func (r *PostgresStorage) InsertManyWithResult(ctx *context.Context, elem interface{}, result interface{}) error
- func (r *PostgresStorage) InsertManyWithTime(ctx *context.Context, elem interface{}, createdAt time.Time) error
- func (r *PostgresStorage) SelectFirstWithQuery(ctx *context.Context, elems interface{}, query string, ...) error
- func (r *PostgresStorage) SelectWithQuery(ctx *context.Context, elems interface{}, query string, ...) error
- func (r *PostgresStorage) Single(ctx *context.Context, elem interface{}, where string, ...) error
- func (r *PostgresStorage) SinglePOSTEMP(ctx *context.Context, elem interface{}, where string, ...) error
- func (r *PostgresStorage) Update(ctx *context.Context, elem interface{}) error
- func (r *PostgresStorage) UpdateMany(ctx *context.Context, elems interface{}) error
- func (r *PostgresStorage) UpdateManyWithResult(ctx *context.Context, elems interface{}, result interface{}) error
- func (r *PostgresStorage) Where(ctx *context.Context, elems interface{}, where string, ...) error
- func (r *PostgresStorage) WherePOSTEMP(ctx *context.Context, elems interface{}, where string, ...) error
- type Queryer
- type RiceBoxSource
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = fmt.Errorf("data is not found") ErrAlreadyExist = fmt.Errorf("data already exists") )
ErrNotEnough declare specific error for Not Enough ErrExisted declare specific error for data already exist
Functions ¶
func NewContext ¶
NewContext creates a new data context
func TestConnectDB ¶
TestConnectDB tests connect to the db and returns the sqlx.DB object if succeeded
func TestMigrateUp ¶
func TestTruncateAll ¶
TestTruncateAll truncates all table
func TransformObject ¶
func TransformObject(source interface{}, result interface{}) error
TransformObject used to transform source object to result object based on json tag
Types ¶
type ActivityLog ¶
type ActivityLog struct { ID int `db:"id"` UserID int `db:"userId"` UserType string `db:"userType"` TableName string `db:"tableName"` ReferenceID int `db:"referenceId"` Metadata map[string]interface{} `db:"metadata"` ValueBefore map[string]interface{} `db:"valueBefore"` ValueAfter map[string]interface{} `db:"valueAfter"` TransactionTime *time.Time `db:"transactionTime"` TransactionType string `db:"transactionType"` CreatedAt *time.Time `db:"createdAt"` }
ActivityLog log for transactions (insert, update, delete)
type GenericStorage ¶
type GenericStorage interface { Single(ctx *context.Context, elem interface{}, where string, arg map[string]interface{}) error Where(ctx *context.Context, elems interface{}, where string, arg map[string]interface{}) error SinglePOSTEMP(ctx *context.Context, elem interface{}, where string, arg map[string]interface{}) error WherePOSTEMP(ctx *context.Context, elems interface{}, where string, arg map[string]interface{}) error SelectWithQuery(ctx *context.Context, elem interface{}, query string, args map[string]interface{}) error FindByID(ctx *context.Context, elem interface{}, id interface{}) error FindAll(ctx *context.Context, elems interface{}, page int, limit int, isAsc bool) error Insert(ctx *context.Context, elem interface{}) error InsertMany(ctx *context.Context, elem interface{}) error InsertManyWithResult(ctx *context.Context, elem interface{}, bulk interface{}) error InsertManyWithTime(ctx *context.Context, elem interface{}, createdAt time.Time) error Update(ctx *context.Context, elem interface{}) error UpdateMany(ctx *context.Context, elems interface{}) error UpdateManyWithResult(ctx *context.Context, elem interface{}, bulk interface{}) error Delete(ctx *context.Context, id interface{}) error DeleteMany(ctx *context.Context, ids interface{}) error CountAll(ctx *context.Context, count interface{}) error HardDelete(ctx *context.Context, id interface{}) error ExecQuery(ctx *context.Context, query string, args map[string]interface{}) error SelectFirstWithQuery(ctx *context.Context, elem interface{}, query string, args map[string]interface{}) error }
GenericStorage represents the generic Storage for the domain models that matches with its database models
type ImmutableGenericStorage ¶
type ImmutableGenericStorage interface { Single(ctx *context.Context, elem interface{}, where string, arg map[string]interface{}) error Where(ctx *context.Context, elems interface{}, where string, arg map[string]interface{}) error FindByID(ctx *context.Context, elem interface{}, id interface{}) error FindAll(ctx *context.Context, elems interface{}, page int, limit int, isAsc bool) error Insert(ctx *context.Context, elem interface{}) error DeleteMany(ctx *context.Context, ids interface{}) error }
ImmutableGenericStorage represents the immutable generic Storage for the domain models that matches with its database models. The immutable generic Storage provides only the find & insert methods.
type LogStorage ¶
type LogStorage struct {
// contains filtered or unexported fields
}
LogStorage storage for logs
func NewLogStorage ¶
func NewLogStorage(db *sqlx.DB, logName string) *LogStorage
NewLogStorage creates a logStorage
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager represents the manager to manage the data consistency
func NewManager ¶
func NewManager( db *sqlx.DB, acknowledgeService client.AcknowledgeRequestServiceInterface, eventHandler event.EventMirroringServiceInterface, ) *Manager
NewManager creates a new manager
type PostgresConfig ¶
type PostgresConfig struct {
IsImmutable bool
}
PostgresConfig represents the configuration for the postgres Storage.
type PostgresStorage ¶
type PostgresStorage struct {
// contains filtered or unexported fields
}
PostgresStorage is the postgres implementation of generic Storage
func NewPostgresStorage ¶
func NewPostgresStorage(db *sqlx.DB, tableName string, elem interface{}, cfg PostgresConfig, logStorage LogStorage) *PostgresStorage
NewPostgresStorage creates a new generic postgres Storage
func (*PostgresStorage) CountAll ¶
func (r *PostgresStorage) CountAll(ctx *context.Context, count interface{}) error
CountAll is function to count all row datas in specific table in database
func (*PostgresStorage) Delete ¶
func (r *PostgresStorage) Delete(ctx *context.Context, id interface{}) error
Delete deletes the elem from database. Delete not really deletes the elem from the db, but it will set the "deletedAt" column to current time.
func (*PostgresStorage) DeleteMany ¶
func (r *PostgresStorage) DeleteMany(ctx *context.Context, ids interface{}) error
DeleteMany delete elems from database. DeleteMany not really delete elems from the db, but it will set the "deletedAt" column to current time.
func (*PostgresStorage) ExecQuery ¶
func (r *PostgresStorage) ExecQuery(ctx *context.Context, query string, args map[string]interface{}) error
ExecQuery is function to only execute raw query into database
func (*PostgresStorage) FindAll ¶
func (r *PostgresStorage) FindAll(ctx *context.Context, elems interface{}, page int, limit int, isAsc bool) error
FindAll finds all elements from the database.
func (*PostgresStorage) FindByID ¶
func (r *PostgresStorage) FindByID(ctx *context.Context, elem interface{}, id interface{}) error
FindByID finds an element by its id it's defined in this project context that the element id column in the db should be "id"
func (*PostgresStorage) HardDelete ¶
func (r *PostgresStorage) HardDelete(ctx *context.Context, id interface{}) error
HardDelete is function to hard deleting data into specific table in database
func (*PostgresStorage) Insert ¶
func (r *PostgresStorage) Insert(ctx *context.Context, elem interface{}) error
Insert inserts a new element into the database. It assumes the primary key of the table is "id" with serial type. It will set the "owner" field of the element with the current account in the context if exists. It will set the "createdAt" and "updatedAt" fields with current time. If immutable set true, it won't insert the updatedAt
func (*PostgresStorage) InsertMany ¶
func (r *PostgresStorage) InsertMany(ctx *context.Context, elem interface{}) error
InsertMany is function for creating many datas into specific table in database.
func (*PostgresStorage) InsertManyWithResult ¶
func (r *PostgresStorage) InsertManyWithResult(ctx *context.Context, elem interface{}, result interface{}) error
InsertManyWithResult is function for creating many datas into specific table in database.
func (*PostgresStorage) InsertManyWithTime ¶
func (r *PostgresStorage) InsertManyWithTime(ctx *context.Context, elem interface{}, createdAt time.Time) error
InsertManyWithTime is function for creating many datas into specific table in database with specific createdAt.
func (*PostgresStorage) SelectFirstWithQuery ¶
func (r *PostgresStorage) SelectFirstWithQuery(ctx *context.Context, elems interface{}, query string, arg map[string]interface{}) error
SelectFirstWithQuery Customizable Query for Select only take the first row
func (*PostgresStorage) SelectWithQuery ¶
func (r *PostgresStorage) SelectWithQuery(ctx *context.Context, elems interface{}, query string, arg map[string]interface{}) error
SelectWithQuery Customizable Query for Select
func (*PostgresStorage) Single ¶
func (r *PostgresStorage) Single(ctx *context.Context, elem interface{}, where string, arg map[string]interface{}) error
Single queries an element according to the query & argument provided
func (*PostgresStorage) SinglePOSTEMP ¶
func (r *PostgresStorage) SinglePOSTEMP(ctx *context.Context, elem interface{}, where string, arg map[string]interface{}) error
SinglePOSTEMP queries an element according to the query & argument provided
func (*PostgresStorage) Update ¶
func (r *PostgresStorage) Update(ctx *context.Context, elem interface{}) error
Update updates the element in the database. It will update the "updatedAt" field.
func (*PostgresStorage) UpdateMany ¶
func (r *PostgresStorage) UpdateMany(ctx *context.Context, elems interface{}) error
UpdateMany updates the element in the database. It will update the "updatedAt" field.
func (*PostgresStorage) UpdateManyWithResult ¶
func (r *PostgresStorage) UpdateManyWithResult(ctx *context.Context, elems interface{}, result interface{}) error
UpdateManyWithResult updates the element in the database. It will update the "updatedAt" field.
func (*PostgresStorage) Where ¶
func (r *PostgresStorage) Where(ctx *context.Context, elems interface{}, where string, arg map[string]interface{}) error
Where queries the elements according to the query & argument provided
func (*PostgresStorage) WherePOSTEMP ¶
func (r *PostgresStorage) WherePOSTEMP(ctx *context.Context, elems interface{}, where string, arg map[string]interface{}) error
WherePOSTEMP queries the elements according to the query & argument provided
type Queryer ¶
type Queryer interface { PrepareNamed(query string) (*sqlx.NamedStmt, error) Rebind(query string) string MustExec(query string, args ...interface{}) sql.Result Select(dest interface{}, query string, args ...interface{}) error Get(dest interface{}, query string, args ...interface{}) error }
Queryer represents the database commands interface
type RiceBoxSource ¶
type RiceBoxSource interface { PopulateMigrations(box *rice.Box) error Open(url string) (source.Driver, error) Close() error First() (version uint, err error) Prev(version uint) (prevVersion uint, err error) Next(version uint) (nextVersion uint, err error) ReadUp(version uint) (r io.ReadCloser, identifier string, err error) ReadDown(version uint) (r io.ReadCloser, identifier string, err error) }