orm

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsRecordNotFoundError

func IsRecordNotFoundError(err error) bool

IsRecordNotFoundError returns whether the given error is due to a requested record not present in the DB.

func NewRecordNotFoundError

func NewRecordNotFoundError() error

NewRecordNotFoundError returns a ErrRecordNotFoundError.

Types

type Config

type Config struct {
	EnableLogging      bool          `configkey:"database.log"` // Whether to enable logging of the database
	InMemory           bool          `configkey:"database.inmemory" default:"false"`
	Host               string        `configkey:"database.host" validate:"required"`
	Port               string        `configkey:"database.port" validate:"required"`
	DbName             string        `configkey:"database.dbname" default:"postgres"`
	DbUser             string        `configkey:"database.dbuser" default:"postgres"`
	DbPassword         string        `configkey:"database.dbpassword" validate:"required"`
	ConnectionParams   string        `configkey:"database.connectionParams"` // Postgres sql connection parameters separate by space
	ConnectionLifetime time.Duration `configkey:"database.connectionLifeTime,duration" default:"1h"`
}

Config contains the configuration parameter to set up the orm.

type Migrator

type Migrator struct {
	// contains filtered or unexported fields
}

Migrator is a structure used to perform DB migrations.

func NewMigrator

func NewMigrator(orm *ORM, models ...interface{}) *Migrator

NewMigrator creates a new Migrator class. ex.) NewMigrator(orm, &model.Hoge{}, &model.Fuga{})

func (*Migrator) Initialize

func (m *Migrator) Initialize() error

Initialize performs the migrations for the models handled by the Migrator.

func (*Migrator) IsInitialized

func (m *Migrator) IsInitialized() bool

IsInitialized returns whether the Migrator is initialized.

type ORM

type ORM struct {
	// contains filtered or unexported fields
}

ORM represent an Object Relational Mapper instance.

func NewORM

func NewORM(config *Config, l *log.Log) *ORM

NewORM creates a new ORM structure with the given parameters.

func (*ORM) Finalize

func (o *ORM) Finalize() error

Finalize releases the resources held by the orm.

func (*ORM) GetDB

func (o *ORM) GetDB() *gorm.DB

GetDB returns the DB instance associated with the orm object. Panics if the object is not initialized.

func (*ORM) GetTableName

func (o *ORM) GetTableName(model interface{}) string

GetTableName returns the name of the table for the given model. Assumes that the globalDB is initialized, returns empty string if not

func (*ORM) Initialize

func (o *ORM) Initialize() error

Initialize initializes the ORM structure.

func (*ORM) IsInitialized

func (o *ORM) IsInitialized() bool

IsInitialized returns whether the orm is initialized.

Jump to

Keyboard shortcuts

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