Documentation ¶
Index ¶
- Constants
- type Shifter
- func (s *Shifter) AlterAllTable(conn *pg.DB, skipPromt ...bool) (err error)
- func (s *Shifter) AlterTable(conn *pg.DB, model interface{}, skipPrompt ...bool) (err error)
- func (s *Shifter) CreateAllEnum(conn *pg.DB, model interface{}) (err error)
- func (s *Shifter) CreateAllIndex(conn *pg.DB, model interface{}, skipPrompt ...bool) (err error)
- func (s *Shifter) CreateAllTable(conn *pg.DB) (err error)
- func (s *Shifter) CreateAllUniqueKey(conn *pg.DB, model interface{}, skipPrompt ...bool) (err error)
- func (s *Shifter) CreateEnum(conn *pg.DB, model interface{}, enumName string) (err error)
- func (s *Shifter) CreateStruct(conn *pg.DB, tableName string, filePath string) (err error)
- func (s *Shifter) CreateStructFromStruct(conn *pg.DB, filePath string) (err error)
- func (s *Shifter) CreateTable(conn *pg.DB, model interface{}) (err error)
- func (s *Shifter) CreateTrigger(conn *pg.DB, tableName string) (err error)
- func (s *Shifter) Debug(conn *pg.DB)
- func (s *Shifter) DropAllEnum(conn *pg.DB, model interface{}, skipPrompt bool) (err error)
- func (s *Shifter) DropAllTable(conn *pg.DB, cascade bool) (err error)
- func (s *Shifter) DropTable(conn *pg.DB, model interface{}, cascade bool) (err error)
- func (s *Shifter) GetStructSchema(tableName string) (sSchema map[string]model.ColSchema)
- func (s *Shifter) GetTrigger(tableName string) (trigger string)
- func (s *Shifter) SetEnum(enum map[string][]string) (err error)
- func (s *Shifter) SetLogPath(logPath string) *Shifter
- func (s *Shifter) SetTableModel(table interface{}) (err error)
- func (s *Shifter) SetTableModels(tables []interface{}) (err error)
- func (s *Shifter) UpsertAllEnum(conn *pg.DB, model interface{}) (err error)
- func (s *Shifter) UpsertAllUniqueKey(conn *pg.DB, model interface{}, skipPrompt ...bool) (err error)
- func (s *Shifter) UpsertEnum(conn *pg.DB, model interface{}, enumName string) (err error)
- func (s *Shifter) Verbose(enable bool) *Shifter
Constants ¶
const ( TriggerTag = "trigger" //use to create triggers on table. HistoryTag = "history" //use to create history table. Default table_history if after trigger given )
constants used
const ( BtreeIndex = "btree" //btree index type GinIndex = "gin" //gin index type GistIndex = "gist" //gist index type HashIndex = "hash" //hash index type BrinIndex = "brin" //brin index type SPGistIndex = "sp-gist" //sp-gist index type )
index type const
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Shifter ¶
type Shifter struct {
// contains filtered or unexported fields
}
Shifter model contains all the methods to migrate go struct to postgresql
func NewShifter ¶
func NewShifter(tables ...interface{}) *Shifter
NewShifter will return shifter model
func (*Shifter) AlterAllTable ¶
AlterAllTable will alter all tables before calling it you need to set the table model in shifter using SetTableModels()
func (*Shifter) AlterTable ¶
AlterTable will alter table.
Parameters
conn: postgresql connection model: struct pointer or string (table name) skipPrompt: bool (default false | if false then before execution sql it will prompt for confirmation)
func (*Shifter) CreateAllEnum ¶
CreateAllEnum will create all enums of the given table.
Parameters
conn: postgresql connection model: struct pointer or string (table name)
if model is table name then need to set shifter SetTableModel() before calling CreateAllEnum()
func (*Shifter) CreateAllIndex ¶
CreateAllIndex will create all index of the given table.
Parameters
conn: postgresql connection model: struct pointer or string (table name) skipPrompt: bool (default false | if false then before execution sql it will prompt for confirmation)
if model is table name then need to set shifter SetTableModel() before calling CreateAllIndex()
func (*Shifter) CreateAllTable ¶
CreateAllTable will create all tables before calling it you need to set the table model in shifter using SetTableModels()
func (*Shifter) CreateAllUniqueKey ¶
func (s *Shifter) CreateAllUniqueKey(conn *pg.DB, model interface{}, skipPrompt ...bool) (err error)
CreateAllUniqueKey will create table all composite unique key.
Parameters
conn: postgresql connection model: struct pointer or string (table name) skipPrompt: bool (default false | if false then before execution sql it will prompt for confirmation)
if model is table name then need to set shifter SetTableModel() before calling CreateAllUniqueKey()
func (*Shifter) CreateEnum ¶
CreateEnum will create enum by enum name.
Parameters
conn: postgresql connection model: struct pointer or string (table name) enumName: enum which you want to create
if model is table name then need to set shifter SetTableModel() before calling CreateEnum()
func (*Shifter) CreateStruct ¶
CreateStruct will create golang structure from postgresql table
func (*Shifter) CreateStructFromStruct ¶
CreateStructFromStruct will create structure from shifter structures which are set in shifter map before calling it you need to set all the table models in shifter using SetTableModels()
func (*Shifter) CreateTable ¶
CreateTable will create table if not exists.
Parameters
conn: postgresql connection model: struct pointer or string (table name)
if model is table name then need to set shifter SetTableModel() before calling CreateTable()
func (*Shifter) CreateTrigger ¶
CreateTrigger will create triggers mentioned on struct before calling it you need to set the table model in shifter using SetTableModel()
func (*Shifter) DropAllEnum ¶
DropAllEnum will drop all enums of the given table.
Parameters
conn: postgresql connection model: struct pointer or string (table name) skipPrompt: bool (default false | if false then before execution sql it will prompt for confirmation)
if model is table name then need to set shifter SetTableModel() before calling DropAllEnum()
func (*Shifter) DropAllTable ¶
DropAllTable will drop all tables before calling it you need to set the table model in shifter using SetTableModels()
func (*Shifter) DropTable ¶
DropTable will drop table if exists in database Parameters
conn: postgresql connection model: struct pointer or string (table name) cascade: if enable then it will drop with cascade
func (*Shifter) GetStructSchema ¶
GetStructSchema will return struct schema
func (*Shifter) GetTrigger ¶
GetTrigger : Get triggers by table name
func (*Shifter) SetLogPath ¶
SetLogPath will set logpath where alter struct log will be created.
deafult path is pwd/log/
func (*Shifter) SetTableModel ¶
SetTableModel will set table struct pointer to shifter
func (*Shifter) SetTableModels ¶
SetTableModels will set multiple table struct pointer to shifter. You can set all the table struct pointers and then perform operation by table name only
func (*Shifter) UpsertAllEnum ¶
UpsertAllEnum will create/update all enums of the given table.
Parameters
conn: postgresql connection model: struct pointer or string (table name)
if model is table name then need to set shifter SetTableModel() before calling UpsertAllEnum()
func (*Shifter) UpsertAllUniqueKey ¶
func (s *Shifter) UpsertAllUniqueKey(conn *pg.DB, model interface{}, skipPrompt ...bool) (err error)
UpsertAllUniqueKey will create/alter/drop composite unique keys of table.
Parameters
conn: postgresql connection model: struct pointer or string (table name) skipPrompt: bool (default false | if false then before execution sql it will prompt for confirmation)
If model is table name then need to set shifter SetTableModel() before calling CreateAllUniqueKey(). If composite unique key is modified then also it will update. If composite unique key exists in table but doesn't exists in struct UniqueKey method then that will be dropped.
func (*Shifter) UpsertEnum ¶
UpsertEnum will create/update enum by enum name.
Parameters
conn: postgresql connection model: struct pointer or string (table name) enumName: enum which you want to upsert
if model is table name then need to set shifter SetTableModel() before calling UpsertEnum()