gopg

package module
Version: v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2020 License: BSD-2-Clause Imports: 15 Imported by: 0

README

gopg

postgress implementation

Documentation

Index

Constants

View Source
const (
	ConditionOperatorAnd = "AND"
	ConditionOperatorOr  = "OR"
	ConditionOperatorXor = "XOR"
)

Variables

View Source
var DefaultSystemColumns = SystemColumns{Created: "created_at", Updated: "updated_at"}
View Source
var DefaultSystemColumnsSoft = SystemColumns{Created: "created_at", Updated: "updated_at", Deleted: "deleted_at"}

Functions

func CreateModelFile

func CreateModelFile(schema string, table string, path string) (*os.File, string, error)

func MakeModel

func MakeModel(db Queryer, path string, schema string, table string, templatePath string, systemColumns SystemColumns) error

func ModelColumn

func ModelColumn(model IModel, field interface{}) string

Model column in db

func ModelUpdateQuery

func ModelUpdateQuery(model IModel, condition *Condition, fields ...interface{}) (sql string, params []interface{}, e goerr.IError)

Types

type Column

type Column struct {
	Name              string  // DB column name
	ModelName         string  // Model name
	Default           *string // DB default value
	IsNullable        bool    // DB is nullable
	DataType          string  // DB column type
	ModelType         string  // Model type
	Schema            string  // DB Schema
	Table             string  // DB table
	Sequence          *string // DB sequence
	ForeignSchema     *string // DB foreign schema name
	ForeignTable      *string // DB foreign table name
	ForeignColumnName *string // DB foreign column name
	ForeignIsSoft     bool    // DB foreign table is soft
	Description       *string // DB column description
	IsPrimaryKey      bool    // DB is primary key
	Tags              string  // Model Tags name
	Import            string  // Model Import custom lib
	IsArray           bool    // Array column
	IsCreated         bool    // Is created at column
	IsUpdated         bool    // Is updated at column
	IsDeleted         bool    // Is deleted at column
	HasUniqueIndex    bool    // If column is a part of unique index
	UniqueIndexName   *string // Unique index name
}

Column information

type Columns

type Columns []Column

func GetTableColumns

func GetTableColumns(dbo Queryer, schema string, table string, sysCols SystemColumns) (*Columns, error)

Get table columns from db

func (Columns) GetImports

func (c Columns) GetImports() []string

type Condition

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

Condition type

func NewSqlCondition

func NewSqlCondition(operator string) *Condition

Init Condition

func (*Condition) AddArgument

func (c *Condition) AddArgument(values ...interface{}) *Condition

Add argument

func (*Condition) AddExpression

func (c *Condition) AddExpression(expression string, values ...interface{}) *Condition

Add expression

func (*Condition) GetArguments

func (c *Condition) GetArguments() []interface{}

Get arguments

func (*Condition) IsEmpty

func (c *Condition) IsEmpty() bool

Check if condition is empty

func (*Condition) Merge

func (c *Condition) Merge(operator string, conditions ...*Condition) *Condition

Merge with conditions

func (*Condition) String

func (c *Condition) String() string

Get string of conditions

type Connection

type Connection interface {
	String() string
	GetDbType() string
	GetMaxConnection() int
	GetConnMaxLifetime() int
	GetMaxIdleConns() int
}

Database Object Connection Interface

type ConnectionConfig

type ConnectionConfig struct {
	Host                   string
	Port                   int
	Name                   string
	User                   string
	Password               string
	MaxConnections         int `yaml:"maxConnections"`
	MaxIdleConnections     int `yaml:"maxIdleConnections"`
	ConnectionIdleLifetime int `yaml:"connectionIdleLifetime"`
}

Client connection config

func (*ConnectionConfig) GetConnMaxLifetime

func (cc *ConnectionConfig) GetConnMaxLifetime() int

Connection idle lifetime

func (*ConnectionConfig) GetMaxConnection

func (cc *ConnectionConfig) GetMaxConnection() int

Get Max Connection

func (*ConnectionConfig) GetMaxIdleConns

func (cc *ConnectionConfig) GetMaxIdleConns() int

Connection max idle connections

type DBO

type DBO struct {
	*sql.DB
	Options
	Connection Connection
}

Main Database Object

func (*DBO) Begin

func (dbo *DBO) Begin() (*SqlTx, error)

Begin transaction

func (*DBO) Exec

func (dbo *DBO) Exec(query string, args ...interface{}) (sql.Result, error)

SQL Exec

func (DBO) Init

func (dbo DBO) Init() (*DBO, error)

Init Database Object

func (*DBO) Prepare

func (dbo *DBO) Prepare(query string) (*SqlStmt, error)

Prepare statement

func (*DBO) Query

func (dbo *DBO) Query(query string, args ...interface{}) (*sql.Rows, error)

SQL Query

func (*DBO) QueryRow

func (dbo *DBO) QueryRow(query string, args ...interface{}) *sql.Row

SQL Query Row

type IMigrationFile

type IMigrationFile interface {
	Up(tx *SqlTx) error
	Down(tx *SqlTx) error
	GetVersion() string
}

Migration file interface

type IModel

type IModel interface {
	Table() string
	Columns() []string
	Values() []interface{}
	Load(q Queryer) goerr.IError
	Save(q Queryer) goerr.IError
	Delete(q Queryer) goerr.IError
}

DB model interface

type ISoftModel

type ISoftModel interface {
	IModel
	SoftLoad(q Queryer) goerr.IError
	SoftDelete(q Queryer) goerr.IError
	SoftRecover(q Queryer) goerr.IError
}

DB model interface

type Iterator

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

Iterator

func NewIterator

func NewIterator(len int) *Iterator

New Iterator

func (*Iterator) Count

func (c *Iterator) Count() int

Get count

func (*Iterator) Cursor

func (c *Iterator) Cursor() int

Get cursor

func (*Iterator) Next

func (c *Iterator) Next() bool

Iterator next

func (*Iterator) Reset

func (c *Iterator) Reset() *Iterator

Reset cursor

func (*Iterator) SetCount

func (c *Iterator) SetCount(count int) *Iterator

Set count

type Logger

type Logger interface {
	Print(v ...interface{})
	Println(v ...interface{})
	Printf(format string, v ...interface{})
}

Logger

type Migration

type Migration struct {
	MigrationPath string
	DBO           *DBO
	Config        ConnectionConfig
	Registry      MigrationRegistry
	RegistryPath  string
	RegistryXPath string
}

Migration struct

func (*Migration) CreateMigrationFile

func (m *Migration) CreateMigrationFile(class string, name string) error

func (*Migration) Downgrade

func (m *Migration) Downgrade(class string, version string) error

func (*Migration) GetTemplate

func (m *Migration) GetTemplate() *template.Template

func (*Migration) InitMigration

func (m *Migration) InitMigration(class string) error

func (*Migration) Upgrade

func (m *Migration) Upgrade(class string) error

Upgrade

type MigrationRegistry

type MigrationRegistry map[string][]IMigrationFile

Migration registry

type Options

type Options struct {
	Debug  bool
	Logger Logger
}

Database Object Options

type PostgresConnectionConfig

type PostgresConnectionConfig struct {
	ConnectionConfig `yaml:",inline"`
	SSLMode          string `yaml:"sslMode"`
	BinaryParameters bool   `yaml:"binaryParameters"`
}

Postgres connection config

func (*PostgresConnectionConfig) GetDbType

func (pcc *PostgresConnectionConfig) GetDbType() string

Get database type

func (*PostgresConnectionConfig) String

func (pcc *PostgresConnectionConfig) String() string

To string

type Query

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

func NewQuery

func NewQuery() *Query

func (*Query) AddOrder

func (f *Query) AddOrder(expression ...string) *Query

func (*Query) Columns

func (f *Query) Columns(column ...string) *Query

func (*Query) From

func (f *Query) From(table ...string) *Query

func (*Query) GetArguments

func (f *Query) GetArguments() []interface{}

func (*Query) GetWith

func (f *Query) GetWith(name string) *Query

func (*Query) GroupBy

func (f *Query) GroupBy(fields ...string) *Query

func (*Query) Having

func (f *Query) Having() *Condition

func (*Query) ModelColumns

func (f *Query) ModelColumns(model ...IModel) *Query

func (*Query) ModelFrom

func (f *Query) ModelFrom(model ...IModel) *Query

func (*Query) Relate

func (f *Query) Relate(relation ...string) *Query

func (*Query) ResetColumns

func (f *Query) ResetColumns() *Query

func (*Query) ResetFrom

func (f *Query) ResetFrom() *Query

func (*Query) ResetGroupBy

func (f *Query) ResetGroupBy() *Query

func (*Query) ResetOrder

func (f *Query) ResetOrder() *Query

func (*Query) ResetRelations

func (f *Query) ResetRelations() *Query

func (*Query) ResetWith

func (f *Query) ResetWith() *Query

func (*Query) SetPagination

func (f *Query) SetPagination(limit int, offset int) *Query

func (Query) String

func (f Query) String() string

func (*Query) Where

func (f *Query) Where() *Condition

func (*Query) With

func (f *Query) With(name string, qb *Query) *Query

type Queryer

type Queryer interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
	Prepare(query string) (*SqlStmt, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
}

Queryer interface

type SqlStmt

type SqlStmt struct {
	*sql.Stmt
	Options
	// contains filtered or unexported fields
}

Stmt

func (*SqlStmt) Exec

func (st *SqlStmt) Exec(args ...interface{}) (sql.Result, error)

Stmt Exec

func (*SqlStmt) Query

func (st *SqlStmt) Query(args ...interface{}) (*sql.Rows, error)

Stmt Query

func (*SqlStmt) QueryRow

func (st *SqlStmt) QueryRow(args ...interface{}) *sql.Row

Stmt Query Row

type SqlTx

type SqlTx struct {
	*sql.Tx
	Options
}

Transaction

func (*SqlTx) Exec

func (tx *SqlTx) Exec(query string, args ...interface{}) (sql.Result, error)

Exec Transaction

func (*SqlTx) Prepare

func (tx *SqlTx) Prepare(query string) (*SqlStmt, error)

Prepare Stmt

func (*SqlTx) Query

func (tx *SqlTx) Query(query string, args ...interface{}) (*sql.Rows, error)

Query Transaction

func (*SqlTx) QueryRow

func (tx *SqlTx) QueryRow(query string, args ...interface{}) *sql.Row

Query Row Transaction

func (*SqlTx) Stmt

func (tx *SqlTx) Stmt(stmt *SqlStmt) *SqlStmt

Get Stmt

type SystemColumns

type SystemColumns struct {
	Created string
	Updated string
	Deleted string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL