common

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2019 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MigrationRepo = "_migration"
)

Variables

This section is empty.

Functions

func Migrate

func Migrate(dataDir string, db dbx.IDatabase, failOnOrderMismatch bool, repoIdSuffix ...string) error

Migrate begins a DB migration process by migrating the scripts located in the provided data dir and storing the migration track in a migration repository ('_migration' by default)

{dataDir}              - The location where the migration scripts are contained
{db}                   - The database client already initialized
{failOnOrderMismatch}  - Indicates whether the migration should fail if the order of previously migrated scripts
                         have failed (removing or adding scripts between previously migrated scripts)
{repoIdSuffix}         - (optional) A suffix to use for the repository name where the migration data is stored.
                         This is useful when sharing the same database instance with multiple services that own
                         their unique repositories (tables in SQL, collections in MongoDB)

func PageHandler

func PageHandler(q dbx.IQuery, page ...*pages.Page) dbx.IQuery

func WrapPageHandler

func WrapPageHandler(q dbx.IQuery, result interface{}, page ...*pages.Page) (*pages.Paginated, error)

Types

type AbstractQuery

type AbstractQuery struct {
	Q          dbx.IQuery
	LimitVal   *int
	SkipVal    *int
	SortFields []string
	Selects    []*ConditionData
	Queries    [][]*ConditionData
}

AbstractQuery is a base query helper used for final implementations.

func (*AbstractQuery) Limit

func (a *AbstractQuery) Limit(n int) dbx.IQuery

func (*AbstractQuery) Not

func (a *AbstractQuery) Not(query interface{}, args ...interface{}) dbx.IQuery

func (*AbstractQuery) Or

func (a *AbstractQuery) Or() dbx.IQuery

func (*AbstractQuery) Page

func (q *AbstractQuery) Page(page ...*pages.Page) dbx.IQuery

Page adds to the query the information required to fetch the requested page of objects.

func (*AbstractQuery) Select

func (a *AbstractQuery) Select(query interface{}, args ...interface{}) dbx.IQuery

func (*AbstractQuery) Skip

func (a *AbstractQuery) Skip(n int) dbx.IQuery

func (*AbstractQuery) Sort

func (a *AbstractQuery) Sort(fields ...string) dbx.IQuery

func (*AbstractQuery) Where

func (a *AbstractQuery) Where(query interface{}, args ...interface{}) dbx.IQuery

func (*AbstractQuery) WrapPage

func (q *AbstractQuery) WrapPage(result interface{}, page ...*pages.Page) (*pages.Paginated, error)

WrapPage attempts to obtain the items in the requested page and wraps the result in *pages.Paginated

type AbstractQueryx

type AbstractQueryx struct {
	Q        dbx.IQuery
	Commands []*Command
}

AbstractQueryx is a base query helper used for final implementations.

func (*AbstractQueryx) Limit

func (a *AbstractQueryx) Limit(n int) dbx.IQuery

func (*AbstractQueryx) Not

func (a *AbstractQueryx) Not(query interface{}, args ...interface{}) dbx.IQuery

func (*AbstractQueryx) Or

func (a *AbstractQueryx) Or() dbx.IQuery

func (*AbstractQueryx) Select

func (a *AbstractQueryx) Select(query interface{}, args ...interface{}) dbx.IQuery

func (*AbstractQueryx) Skip

func (a *AbstractQueryx) Skip(n int) dbx.IQuery

func (*AbstractQueryx) Sort

func (a *AbstractQueryx) Sort(fields ...string) dbx.IQuery

func (*AbstractQueryx) Where

func (a *AbstractQueryx) Where(query interface{}, args ...interface{}) dbx.IQuery

type Command

type Command struct {
	Name string
	Args []interface{}
}

type ConditionData

type ConditionData struct {
	Negation bool
	Query    interface{}
	Args     []interface{}
}

type MigrationInfo

type MigrationInfo struct {
	//IdInt     uint      `gorm:"primary_key"`
	//IdString  string    `bson:"_id"`
	ScriptId  string    `bson:"script_id"`
	Hash      string    `bson:"hash"`
	Timestamp time.Time `bson:"timestamp"`
}

type Migrator added in v1.0.2

type Migrator struct {
	// Db is the database client already initialized
	Db dbx.IDatabase

	// DataDir is the location where the migration scripts are contained
	DataDir string

	// FailOnOrderMismatch indicates whether the migration should fail if the order of previously migrated scripts
	FailOnOrderMismatch bool

	// RepoIdSuffix is an optional suffix to use for the repository name where the migration data is stored. This is
	// useful when sharing the same database instance with multiple services that own their unique repositories (tables
	// in SQL, collections in MongoDB)
	RepoIdSuffix string

	// ScriptExecutor is a custom script executor to run the scripts for a migration. If not provided uses `Db.Run`
	//
	// This custom executor is added for scenarios where Db.Run would not work as expected, for example using a MongoDB
	// client with AWS DocumentDB where `eval` is not supported, a custom executor using the `mongo` shell CLI could be
	// implemented instead.
	ScriptExecutor dbx.ScriptExecutor
}

func (*Migrator) Migrate added in v1.0.2

func (m *Migrator) Migrate() error

Migrate begins a DB migration process by migrating the scripts with the configuration contained my the *Migrator instance.

Jump to

Keyboard shortcuts

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