Documentation ¶
Index ¶
- Constants
- type BigInteger
- type Boolean
- type Column
- type CreateIndex
- type CreateTable
- type CustomOperation
- type DB
- type DateTime
- type Decimal
- type DeleteColumn
- type DeleteIndex
- type DeleteTable
- type Double
- type ForeignKey
- type Integer
- type JSON
- type Migration
- type Migrations
- type Operation
- type Operations
- type PSQL
- func (pq *PSQL) C() *pgxpool.Pool
- func (pq *PSQL) CheckMigrations() bool
- func (pq *PSQL) CheckMigrationsOrExit() bool
- func (pq *PSQL) Exec(query string, args ...interface{}) (affected uint)
- func (pq *PSQL) ExecContext(ctx context.Context, query string, args ...interface{}) (affected uint)
- func (pq *PSQL) ExecProcedure(declare, body string, args ...interface{}) (affected uint)
- func (pq *PSQL) GenerateHTML(filename string) bool
- func (pq *PSQL) GetScheme(maxIndex int) (TableSchemes, Operations, error)
- func (pq *PSQL) Migrate(fake bool) bool
- func (pq *PSQL) MigrateTarget(targetIdx int, fake bool) bool
- func (pq *PSQL) Query(query string, args ...interface{}) *Rows
- func (pq *PSQL) QueryContext(ctx context.Context, query string, args ...interface{}) *Rows
- func (pq *PSQL) QueryRow(query string, args ...interface{}) *Row
- func (pq *PSQL) QueryRowContext(ctx context.Context, query string, args ...interface{}) *Row
- func (pq *PSQL) Start(args []string) bool
- func (pq *PSQL) Tx() pgx.Tx
- func (pq *PSQL) WithTransaction(f func(*PSQL))
- func (pq *PSQL) WithTransactionContext(ctx context.Context, f func(*PSQL))
- type PrimaryKey
- type RenameColumn
- type RenameIndex
- type RenameTable
- type Row
- type Rows
- type SetForeignKey
- type SetNotNull
- type TableScheme
- type TableSchemes
- type Text
- type UnsetForeignKey
- type UnsetNotNull
Constants ¶
const ( SetNull = iota Cascade Protect // named RESTRICT in SQL )
On cascade delete
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BigInteger ¶
BigInteger is add column niginteger in table
func (*BigInteger) Copy ¶
func (op *BigInteger) Copy(table, name string) Operation
Copy column with new params
func (*BigInteger) Meta ¶
func (op *BigInteger) Meta() (table, name string)
Meta column info for migration
type Boolean ¶
Boolean is add column boolean in table
type CreateIndex ¶
type CreateIndex struct { Name string // recommended 'name_idx' Table string Column string Using string // using METHOD [GIN, GiST, B-Tree, Hash, BRIN, SP-GiST] With string // on store params Background bool }
CreateIndex is create index in db
func (*CreateIndex) Copy ¶
func (op *CreateIndex) Copy(name string) Operation
Copy column with new params
func (*CreateIndex) ToForward ¶
func (op *CreateIndex) ToForward(db *PSQL) (err error)
ToForward operation
func (*CreateIndex) ToReverse ¶
func (op *CreateIndex) ToReverse(db *PSQL) (err error)
ToReverse operation
type CreateTable ¶
type CreateTable struct {
Name string
}
CreateTable is create table in db
func (*CreateTable) ToForward ¶
func (op *CreateTable) ToForward(db *PSQL) error
ToForward operation
func (*CreateTable) ToReverse ¶
func (op *CreateTable) ToReverse(db *PSQL) error
ToReverse operation
type CustomOperation ¶
CustomOperation is helper for create custom operation
func (*CustomOperation) ToForward ¶
func (op *CustomOperation) ToForward(db *PSQL) error
ToForward migration
func (*CustomOperation) ToReverse ¶
func (op *CustomOperation) ToReverse(db *PSQL) error
ToReverse migration
type DB ¶ added in v1.3.2
type DB interface { C() *pgxpool.Pool Tx() pgx.Tx ExecContext(ctx context.Context, query string, args ...interface{}) (affected uint) Exec(query string, args ...interface{}) (affected uint) ExecProcedure(declare, body string, args ...interface{}) (affected uint) QueryContext(ctx context.Context, query string, args ...interface{}) *Rows Query(query string, args ...interface{}) *Rows QueryRowContext(ctx context.Context, query string, args ...interface{}) *Row QueryRow(query string, args ...interface{}) *Row }
DB util interface
type DateTime ¶
DateTime is add column datetime in table
type Decimal ¶
Decimal is add column decimal in table
type DeleteColumn ¶
DeleteColumn is delete column in table
func (*DeleteColumn) ToForward ¶
func (op *DeleteColumn) ToForward(db *PSQL) error
ToForward operation
func (*DeleteColumn) ToReverse ¶
func (op *DeleteColumn) ToReverse(db *PSQL) error
ToReverse operation
type DeleteIndex ¶
DeleteIndex is delete index in db
func (*DeleteIndex) ToForward ¶
func (op *DeleteIndex) ToForward(db *PSQL) (err error)
ToForward operation
func (*DeleteIndex) ToReverse ¶
func (op *DeleteIndex) ToReverse(db *PSQL) error
ToReverse operation
type DeleteTable ¶
type DeleteTable struct {
Name string
}
DeleteTable is delete table from db
func (*DeleteTable) ToForward ¶
func (op *DeleteTable) ToForward(db *PSQL) error
ToForward operation
func (*DeleteTable) ToReverse ¶
func (op *DeleteTable) ToReverse(db *PSQL) error
ToReverse operation
type Double ¶
Double is add column double in table
type ForeignKey ¶
ForeignKey is create INT column with reference to other table primary key
func (*ForeignKey) Copy ¶
func (op *ForeignKey) Copy(table, name string) Operation
Copy column with new params
func (*ForeignKey) Meta ¶
func (op *ForeignKey) Meta() (table, name string)
Meta column info for migration
type Integer ¶
Integer is add column integer in table
type Migrations ¶
Migrations is map[int]Migration
func (Migrations) Add ¶
func (migrations Migrations) Add(migration *Migration)
Add migration to list with check unique index
func (Migrations) AddFromFile ¶
func (migrations Migrations) AddFromFile(operations []Operation)
AddFromFile migration to list with check unique index using utils.MigrationFileIndexName
type PSQL ¶
type PSQL struct { Migrations Migrations Host string Name string Username string Password string MaxConns int32 MaxConnLifetime time.Duration LogLevel pgx.LogLevel Logger pgx.Logger // contains filtered or unexported fields }
PSQL - PostgreSQL database wrapper
func (*PSQL) CheckMigrations ¶
CheckMigrations check have migrations
func (*PSQL) CheckMigrationsOrExit ¶
CheckMigrationsOrExit is CheckMigrations and exit if have not applied
func (*PSQL) ExecContext ¶
ExecContext is wrapper ExecContext using transaction (if active)
func (*PSQL) ExecProcedure ¶
ExecProcedure is Exec PL/pgSQL procedure
func (*PSQL) GenerateHTML ¶
GenerateHTML db scheme
func (*PSQL) GetScheme ¶
func (pq *PSQL) GetScheme(maxIndex int) (TableSchemes, Operations, error)
GetScheme db
func (*PSQL) MigrateTarget ¶
MigrateTarget call apply target migrations
func (*PSQL) QueryContext ¶
QueryContext is wrapper QueryContext using transaction (if active)
func (*PSQL) QueryRowContext ¶
QueryRowContext is wrapper QueryRowContext using transaction (if active)
func (*PSQL) WithTransaction ¶
WithTransaction is helper wrapper for transaction (rollback when panic)
type PrimaryKey ¶
PrimaryKey is create column autocrement column and set primary key
func (*PrimaryKey) Copy ¶
func (op *PrimaryKey) Copy(table, name string) Operation
Copy column with new params
func (*PrimaryKey) Meta ¶
func (op *PrimaryKey) Meta() (table, name string)
Meta column info for migration
type RenameColumn ¶
RenameColumn is rename column in table
func (*RenameColumn) ToForward ¶
func (op *RenameColumn) ToForward(db *PSQL) error
ToForward operation
func (*RenameColumn) ToReverse ¶
func (op *RenameColumn) ToReverse(db *PSQL) error
ToReverse operation
type RenameIndex ¶
RenameIndex is rename index in db
func (*RenameIndex) ToForward ¶
func (op *RenameIndex) ToForward(db *PSQL) error
ToForward operation
func (*RenameIndex) ToReverse ¶
func (op *RenameIndex) ToReverse(db *PSQL) error
ToReverse operation
type RenameTable ¶
RenameTable is rename table in db
func (*RenameTable) ToForward ¶
func (op *RenameTable) ToForward(db *PSQL) error
ToForward operation
func (*RenameTable) ToReverse ¶
func (op *RenameTable) ToReverse(db *PSQL) error
ToReverse operation
type SetForeignKey ¶
SetForeignKey is set foreign key constraint to exists column
func (*SetForeignKey) Copy ¶
func (op *SetForeignKey) Copy(table, name string) Operation
Copy column with new params
func (*SetForeignKey) Meta ¶
func (op *SetForeignKey) Meta() (table, name string)
Meta column info for migration
func (*SetForeignKey) ToForward ¶
func (op *SetForeignKey) ToForward(db *PSQL) error
ToForward operation
func (*SetForeignKey) ToReverse ¶
func (op *SetForeignKey) ToReverse(db *PSQL) error
ToReverse operation
type SetNotNull ¶
SetNotNull is set not null for column in db
type UnsetForeignKey ¶
UnsetForeignKey is unset foreign key constraint to exists column
func (*UnsetForeignKey) ToForward ¶
func (op *UnsetForeignKey) ToForward(db *PSQL) error
ToForward operation
func (*UnsetForeignKey) ToReverse ¶
func (op *UnsetForeignKey) ToReverse(db *PSQL) error
ToReverse operation
type UnsetNotNull ¶
UnsetNotNull is unset not null for column in db
func (*UnsetNotNull) ToForward ¶
func (op *UnsetNotNull) ToForward(db *PSQL) error
ToForward operation
func (*UnsetNotNull) ToReverse ¶
func (op *UnsetNotNull) ToReverse(db *PSQL) error
ToReverse operation