pgorm

package module
v0.0.0-...-5ca6d2f Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2019 License: BSD-2-Clause Imports: 15 Imported by: 5

README

go-pg-orm

Wrapper that simplifies use of Golang ORM with focus on PostgreSQL found at https://github.com/go-pg/pg

NOTE: Work in progress!

Documentation

Overview

Package pgorm implements Golang ORM with focus on PostgreSQL features and performance. See https://github.com/go-pg/pg

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database struct {
	DB  *pg.DB
	Log *log.Logger
}

Database implements the PostgreSQL ORM

func (*Database) Close

func (d *Database) Close()

func (*Database) DeleteModel

func (d *Database) DeleteModel(model interface{}) error

DeleteModel attempts update the given model in the database.

func (*Database) Error

func (d *Database) Error(where string, message string, err error)

Error logs a error event then continues execution

func (*Database) Fatal

func (d *Database) Fatal(where string, message string, err error)

Fatal logs a fatal error event then stops execution

func (*Database) GetAllModels

func (d *Database) GetAllModels(model interface{}) error

GetAllModels attempts retrieve all models based on the given model from the database.

func (*Database) GetAllWithCondition

func (d *Database) GetAllWithCondition(model interface{}, condition interface{}, args ...interface{}) error

GetAllWithCondition attempts retrieve all models based on the given model and condition from the database.

func (*Database) GetModel

func (d *Database) GetModel(model interface{}) error

GetModel attempts retrieve the given model from the database.

func (*Database) GetRowsWithCondition

func (d *Database) GetRowsWithCondition(model interface{}, condition interface{}, args ...interface{}) error

GetRowsWithCondition attempts retrieve a model based on the given model and condition from the database.

func (*Database) GetWithCondition

func (d *Database) GetWithCondition(model interface{}, condition interface{}, args ...interface{}) error

GetWithCondition attempts retrieve a model based on the given model and condition from the database.

func (*Database) Info

func (d *Database) Info(where string, message string)

Info logs a general information event then continues execution

func (*Database) Open

func (d *Database) Open()

Open

func (*Database) OpenWithOptions

func (d *Database) OpenWithOptions(opts *pg.Options)

OpenWithOptions

func (*Database) SaveModel

func (d *Database) SaveModel(model interface{}) error

SaveModel attempts add the given model to database.

func (*Database) Success

func (d *Database) Success(where string, message string)

Success logs a successful event then continues execution

func (*Database) UpdateModel

func (d *Database) UpdateModel(model interface{}) error

UpdateModel attempts update the given model in the database.

func (*Database) Warn

func (d *Database) Warn(where string, message string)

Warn logs a warning event then continues execution

type IChange

type IChange interface {
	SaveModel(interface{}) error
	UpdateModel(interface{}) error
	DeleteModel(interface{}) error
}

IChange defines the change related methods

type IConn

type IConn interface {
	Open() error
	OpenWithConnString(conn string) error
	OpenWithEnv() error
	OpenWithOptions(opts *pg.Options) error
	Close() error
}

IConn defines the connection related methods

type IDatabase

type IDatabase interface {
	IConn
	IGet
	IChange
	ILogger
}

IDatabase defines the top level Database methods

type IGet

type IGet interface {
	GetModel(interface{}) error
	GetAllModels(interface{})
	GetWithCondition(model interface{}, condition interface{}, args ...interface{}) error
	GetAllWithCondition(model interface{}, condition interface{}, args ...interface{}) error
	GetRowsWithCondition(interface{}, interface{}, ...interface{}) error
}

IGet defines the get related methods

type ILogger

type ILogger interface {
	Success(where string, message string, err error)
	Info(where string, message string, err error)
	Warn(where string, message string, err error)
	Error(where string, message string, err error)
	Fatal(where string, message string, err error)
}

ILogger defines the logging related methods

type Model

type Model struct {
	*Database
	// contains filtered or unexported fields
}

Model facilitate database interactions, supports postgres, mysql and foundation

func NewModel

func NewModel() *Model

NewModel returns a new Model without opening database connection

func (*Model) AutoMigrateAll

func (m *Model) AutoMigrateAll(migrate bool)

AutoMigrateAll runs migrations for all the registered models

func (*Model) Count

func (m *Model) Count() int

Count returns the number of registered models

func (*Model) DropTables

func (m *Model) DropTables(drop bool, verbose bool)

DropTables Drops All Model Database Tables

func (*Model) IsOpen

func (m *Model) IsOpen() bool

IsOpen returns true if the Model has already established connection to the database

func (*Model) OpenWithConfig

func (m *Model) OpenWithConfig(cfg *config.Config) error

OpenWithConfig opens database connection with the settings found in cfg

func (*Model) OpenWithParams

func (m *Model) OpenWithParams(conn string, migrate bool, drop bool, nomodel bool) error

Settings: Database Database string `json:"database" yaml:"database" toml:"database" hcl:"database"` DatabaseConn string `json:"database_conn" yaml:"database_conn" toml:"database_conn" hcl:"database_conn"` Automigrate bool `json:"automigrate" yaml:"automigrate" toml:"automigrate" hcl:"automigrate"` DropTables bool `json:"droptables" yaml:"droptables" toml:"droptables" hcl:"droptables"` NoModel bool `json:"no_model" yaml:"no_model" toml:"no_model" hcl:"no_model"`

func (*Model) Register

func (m *Model) Register(values ...interface{}) error

Register adds the values to the models registry

Jump to

Keyboard shortcuts

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