db

package
v1.8.32 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2019 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

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

type BigInteger struct {
	Table   string
	Name    string
	Null    bool
	Default *uint
}

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

func (*BigInteger) ToForward

func (op *BigInteger) ToForward(db *PSQL) error

ToForward operation

func (*BigInteger) ToReverse

func (op *BigInteger) ToReverse(db *PSQL) error

ToReverse operation

type Boolean

type Boolean struct {
	Table   string
	Name    string
	Null    bool
	Default *bool
}

Boolean is add column boolean in table

func (*Boolean) Copy

func (op *Boolean) Copy(table, name string) Operation

Copy column with new params

func (*Boolean) Meta

func (op *Boolean) Meta() (table, name string)

Meta column info for migration

func (*Boolean) ToForward

func (op *Boolean) ToForward(db *PSQL) error

ToForward operation

func (*Boolean) ToReverse

func (op *Boolean) ToReverse(db *PSQL) error

ToReverse operation

type Column

type Column interface {
	Meta() (table, name string)
	Copy(table, name string) Operation
}

Column is database column description

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

type CustomOperation struct {
	Forward func(*PSQL) error
	Reverse func(*PSQL) error
}

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 DateTime

type DateTime struct {
	Table   string
	Name    string
	Null    bool
	Default *time.Time
}

DateTime is add column datetime in table

func (*DateTime) Copy

func (op *DateTime) Copy(table, name string) Operation

Copy column with new params

func (*DateTime) Meta

func (op *DateTime) Meta() (table, name string)

Meta column info for migration

func (*DateTime) ToForward

func (op *DateTime) ToForward(db *PSQL) error

ToForward operation

func (*DateTime) ToReverse

func (op *DateTime) ToReverse(db *PSQL) error

ToReverse operation

type Decimal

type Decimal struct {
	Table   string
	Name    string
	Null    bool
	Default *float64
}

Decimal is add column decimal in table

func (*Decimal) Copy

func (op *Decimal) Copy(table, name string) Operation

Copy column with new params

func (*Decimal) Meta

func (op *Decimal) Meta() (table, name string)

Meta column info for migration

func (*Decimal) ToForward

func (op *Decimal) ToForward(db *PSQL) error

ToForward operation

func (*Decimal) ToReverse

func (op *Decimal) ToReverse(db *PSQL) error

ToReverse operation

type DeleteColumn

type DeleteColumn struct {
	Table string
	Name  string
}

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

type DeleteIndex struct {
	Name       string
	Background bool
}

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

type Double struct {
	Table   string
	Name    string
	Null    bool
	Default *float64
}

Double is add column double in table

func (*Double) Copy

func (op *Double) Copy(table, name string) Operation

Copy column with new params

func (*Double) Meta

func (op *Double) Meta() (table, name string)

Meta column info for migration

func (*Double) ToForward

func (op *Double) ToForward(db *PSQL) error

ToForward operation

func (*Double) ToReverse

func (op *Double) ToReverse(db *PSQL) error

ToReverse operation

type ForeignKey

type ForeignKey struct {
	Table    string
	Name     string
	Ref      string
	RefKey   string
	OnDelete int
}

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

func (*ForeignKey) ToForward

func (op *ForeignKey) ToForward(db *PSQL) error

ToForward operation

func (*ForeignKey) ToReverse

func (op *ForeignKey) ToReverse(db *PSQL) error

ToReverse operation

type Integer

type Integer struct {
	Table   string
	Name    string
	Null    bool
	Default *int
}

Integer is add column integer in table

func (*Integer) Copy

func (op *Integer) Copy(table, name string) Operation

Copy column with new params

func (*Integer) Meta

func (op *Integer) Meta() (table, name string)

Meta column info for migration

func (*Integer) ToForward

func (op *Integer) ToForward(db *PSQL) error

ToForward operation

func (*Integer) ToReverse

func (op *Integer) ToReverse(db *PSQL) error

ToReverse operation

type JSON

type JSON struct {
	Table string
	Name  string
	Null  bool
}

JSON is add column jsonb in table

func (*JSON) Copy

func (op *JSON) Copy(table, name string) Operation

Copy column with new params

func (*JSON) Meta

func (op *JSON) Meta() (table, name string)

Meta column info for migration

func (*JSON) ToForward

func (op *JSON) ToForward(db *PSQL) error

ToForward operation

func (*JSON) ToReverse

func (op *JSON) ToReverse(db *PSQL) error

ToReverse operation

type Migration

type Migration struct {
	Index      int
	Name       string
	Operations []Operation
}

Migration is db migration operations

type Migrations

type Migrations map[int]*Migration

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 Operation

type Operation interface {
	ToForward(*PSQL) error
	ToReverse(*PSQL) error
}

Operation is part migration

type Operations

type Operations []Operation

Operations is []Operation

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

func (pq *PSQL) C() *pgxpool.Pool

C - is db connection with first init

func (*PSQL) Exec

func (pq *PSQL) Exec(query string, args ...interface{}) (affected uint)

Exec is wrapper Exec using transaction (if active)

func (*PSQL) ExecContext

func (pq *PSQL) ExecContext(ctx context.Context, query string, args ...interface{}) (affected uint)

ExecContext is wrapper ExecContext using transaction (if active)

func (*PSQL) ExecProcedure added in v1.0.2

func (pq *PSQL) ExecProcedure(declare, body string, args ...interface{}) (affected uint)

ExecProcedure is Exec PL/pgSQL procedure

func (*PSQL) Migrate

func (pq *PSQL) Migrate(args []string) bool

Migrate call apply all migrations

func (*PSQL) MigrateCheck

func (pq *PSQL) MigrateCheck() bool

MigrateCheck call check migrations

func (*PSQL) MigrateCheckOrExit added in v1.7.5

func (pq *PSQL) MigrateCheckOrExit()

MigrateCheckOrExit call check migrations and exit on fail

func (*PSQL) Query

func (pq *PSQL) Query(query string, args ...interface{}) *Rows

Query is wrapper Query using transaction (if active)

func (*PSQL) QueryContext

func (pq *PSQL) QueryContext(ctx context.Context, query string, args ...interface{}) *Rows

QueryContext is wrapper QueryContext using transaction (if active)

func (*PSQL) QueryRow

func (pq *PSQL) QueryRow(query string, args ...interface{}) *Row

QueryRow is wrapper QueryRow using transaction (if active)

func (*PSQL) QueryRowContext

func (pq *PSQL) QueryRowContext(ctx context.Context, query string, args ...interface{}) *Row

QueryRowContext is wrapper QueryRowContext using transaction (if active)

func (*PSQL) Tx

func (pq *PSQL) Tx() pgx.Tx

Tx - is db connection with transaction

func (*PSQL) WithTransaction

func (pq *PSQL) WithTransaction(f func(*PSQL) error) error

WithTransaction is helper wrapper for transaction (rollback when panic)

func (*PSQL) WithTransactionContext

func (pq *PSQL) WithTransactionContext(ctx context.Context, f func(*PSQL) error) (err error)

WithTransactionContext is helper wrapper for transaction (rollback when panic)

type PrimaryKey

type PrimaryKey struct {
	Table string
	Name  string
}

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

func (*PrimaryKey) ToForward

func (op *PrimaryKey) ToForward(db *PSQL) error

ToForward operation

func (*PrimaryKey) ToReverse

func (op *PrimaryKey) ToReverse(db *PSQL) error

ToReverse operation

type RenameColumn

type RenameColumn struct {
	Table string
	Old   string
	New   string
}

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

type RenameIndex struct {
	Old string
	New string
}

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

type RenameTable struct {
	Old string
	New string
}

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 Row

type Row struct {
	pgx.Row
}

Row wrapper

func (*Row) Scan

func (row *Row) Scan(dest ...interface{}) bool

Scan throws panic on error

type Rows

type Rows struct {
	pgx.Rows
}

Rows wrapper

func (*Rows) Scan

func (rows *Rows) Scan(dest ...interface{})

Scan throws panic on error

type SetForeignKey

type SetForeignKey struct {
	Table    string
	Column   string
	Ref      string
	RefKey   string
	OnDelete int
}

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

type SetNotNull struct {
	Table string
	Name  string
}

SetNotNull is set not null for column in db

func (*SetNotNull) ToForward

func (op *SetNotNull) ToForward(db *PSQL) error

ToForward operation

func (*SetNotNull) ToReverse

func (op *SetNotNull) ToReverse(db *PSQL) error

ToReverse operation

type Text

type Text struct {
	Table   string
	Name    string
	Null    bool
	Default *string
}

Text is add column text in table

func (*Text) Copy

func (op *Text) Copy(table, name string) Operation

Copy column with new params

func (*Text) Meta

func (op *Text) Meta() (table, name string)

Meta column info for migration

func (*Text) ToForward

func (op *Text) ToForward(db *PSQL) error

ToForward operation

func (*Text) ToReverse

func (op *Text) ToReverse(db *PSQL) error

ToReverse operation

type UnsetForeignKey

type UnsetForeignKey struct {
	Table  string
	Column string
}

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

type UnsetNotNull struct {
	Table string
	Name  string
}

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

Jump to

Keyboard shortcuts

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