shifter

package module
v0.0.0-...-6c1a939 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2022 License: MIT Imports: 19 Imported by: 4

README

pg-shifter

Getting started

To make it easy for you to get started with GitLab, here's a list of recommended next steps.

Already a pro? Just edit this README.md and make it your own. Want to make it easy? Use the template at the bottom!

Add your files

cd existing_repo
git remote add origin https://gitlab.com/g-harshit/pg-shifter.git
git branch -M main
git push -uf origin main

Integrate with your tools

Collaborate with your team

Test and Deploy

Use the built-in continuous integration in GitLab.


Editing this README

When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to makeareadme.com for this template.

Suggestions for a good README

Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.

Name

Choose a self-explaining name for your project.

Description

Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.

Badges

On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.

Visuals

Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.

Installation

Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.

Usage

Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.

Support

Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.

Roadmap

If you have ideas for releases in the future, it is a good idea to list them in the README.

Contributing

State if you are open to contributions and what your requirements are for accepting them.

For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.

You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.

Authors and acknowledgment

Show your appreciation to those who have contributed to the project.

License

For open source projects, say how it is licensed.

Project status

If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.

Documentation

Index

Constants

View Source
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

View Source
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

func (s *Shifter) AlterAllTable(conn *pg.DB, skipPromt ...bool) (err error)

AlterAllTable will alter all tables before calling it you need to set the table model in shifter using SetTableModels()

func (*Shifter) AlterTable

func (s *Shifter) AlterTable(conn *pg.DB, model interface{}, skipPrompt ...bool) (err error)

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

func (s *Shifter) CreateAllEnum(conn *pg.DB, model interface{}) (err error)

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

func (s *Shifter) CreateAllIndex(conn *pg.DB, model interface{}, skipPrompt ...bool) (err error)

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

func (s *Shifter) CreateAllTable(conn *pg.DB) (err error)

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

func (s *Shifter) CreateEnum(conn *pg.DB, model interface{}, enumName string) (err error)

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

func (s *Shifter) CreateStruct(conn *pg.DB, tableName string,
	filePath string) (err error)

CreateStruct will create golang structure from postgresql table

func (*Shifter) CreateStructFromStruct

func (s *Shifter) CreateStructFromStruct(conn *pg.DB, filePath string) (
	err error)

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

func (s *Shifter) CreateTable(conn *pg.DB, model interface{}) (err error)

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

func (s *Shifter) CreateTrigger(conn *pg.DB, tableName string) (err error)

CreateTrigger will create triggers mentioned on struct before calling it you need to set the table model in shifter using SetTableModel()

func (*Shifter) DropAllEnum

func (s *Shifter) DropAllEnum(conn *pg.DB, model interface{}, skipPrompt bool) (err error)

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

func (s *Shifter) DropAllTable(conn *pg.DB, cascade bool) (err error)

DropAllTable will drop all tables before calling it you need to set the table model in shifter using SetTableModels()

func (*Shifter) DropTable

func (s *Shifter) DropTable(conn *pg.DB, model interface{}, cascade bool) (err error)

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

func (s *Shifter) GetStructSchema(tableName string) (sSchema map[string]model.ColSchema)

GetStructSchema will return struct schema

func (*Shifter) GetTrigger

func (s *Shifter) GetTrigger(tableName string) (trigger string)

GetTrigger : Get triggers by table name

func (*Shifter) SetEnum

func (s *Shifter) SetEnum(enum map[string][]string) (err error)

SetEnum will set global enum list

func (*Shifter) SetLogPath

func (s *Shifter) SetLogPath(logPath string) *Shifter

SetLogPath will set logpath where alter struct log will be created.

deafult path is pwd/log/

func (*Shifter) SetTableModel

func (s *Shifter) SetTableModel(table interface{}) (err error)

SetTableModel will set table struct pointer to shifter

func (*Shifter) SetTableModels

func (s *Shifter) SetTableModels(tables []interface{}) (err error)

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

func (s *Shifter) UpsertAllEnum(conn *pg.DB, model interface{}) (err error)

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

func (s *Shifter) UpsertEnum(conn *pg.DB, model interface{}, enumName string) (err error)

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()

func (*Shifter) Verbose

func (s *Shifter) Verbose(enable bool) *Shifter

Verbose will enable executed sql printing in console

Directories

Path Synopsis
cli
cmd
example

Jump to

Keyboard shortcuts

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