pgxs

package
v1.14.4 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotExist     = fmt.Errorf("schema or table does not exist")
	ErrAlreadyExist = fmt.Errorf("schema or table already exist")
)
View Source
var ErrEmptyConfig = fmt.Errorf("pxgs: PSQL Config is required")
View Source
var MigrationsTable = "public.schema_version"

MigrationsTable is for saving actual schema version

Functions

func QuoteString

func QuoteString(str string) string

according to https://github.com/jackc/pgx/blob/master/conn.go#L84 have to watch changes, to prevent internal issues

Types

type Config added in v0.6.0

type Config struct {
	DbUri          string      `json:"db_uri" yaml:"db_uri"`
	MigrationsPath string      `json:"migration_schemas" yaml:"migration_schemas"`
	DataDir        string      `json:"data_dir" yaml:"data_dir"`
	Host           string      `json:"host" yaml:"host"`
	Port           string      `json:"port" yaml:"port"`
	Name           string      `json:"name" yaml:"name"`
	User           string      `json:"user" yaml:"user"`
	Password       string      `json:"password" yaml:"password"`
	SslMode        string      `json:"ssl_mode" yaml:"ssl_mode"`
	TLS            SSL         `json:"tls" yaml:"tls"`
	TLSConfig      *tls.Config `json:"-" yaml:"-"`
}

func (*Config) GetConnString added in v1.4.0

func (c *Config) GetConnString() string

type DBStats added in v1.14.0

type DBStats struct {
	Name         string
	CountTables  int32
	CountRows    int32
	SizeTotal    int64
	SizeIndexes  int64
	SizeSchema   int64
	CountIndexes int32
}

DBStats describes some statistics for a database.

type ErrorLineExtract added in v1.4.0

type ErrorLineExtract struct {
	LineNum   int    // Line number starting with 1
	ColumnNum int    // Column number starting with 1
	Text      string // Text of the line without a new line character.
}

referred to original: https://github.com/jackc/tern/blob/master/error_line_extract.go

func ExtractErrorLine added in v1.4.0

func ExtractErrorLine(source string, position int) (ErrorLineExtract, error)

ExtractErrorLine takes source and character position extracts the line number, column number, and the line of text.

The first character is position 1.

type Repo

type Repo struct {
	Logger *zap.SugaredLogger `json:"-" yaml:"-"`
	Pool   *pgxpool.Pool      `json:"-" yaml:"-"`
	Config *Config            `json:"-" yaml:"-"`
}

func NewPool

func NewPool(ctx context.Context, lg *zap.SugaredLogger, conf *Config) (*Repo, error)

func (*Repo) ConnectDB

func (db *Repo) ConnectDB(ctx context.Context, tlsConfig *tls.Config) (*pgconn.PgConn, error)

func (*Repo) ConnectDBPool added in v1.4.0

func (db *Repo) ConnectDBPool(ctx context.Context, tlsConfig *tls.Config) (*pgxpool.Pool, error)

ConnectDBPool initializes Pool connection

func (*Repo) CreateSchema added in v1.14.0

func (db *Repo) CreateSchema(ctx context.Context, schemaName string) error

CreateSchema creates a new PostgreSQL schema.

It returns ErrAlreadyExist if schema already exist.

func (*Repo) CreateTable added in v1.14.0

func (db *Repo) CreateTable(ctx context.Context, schemaName, tableName string) error

CreateTable creates PostgreSQL jsonb table.

It returns ErrAlreadyExist if table already exist.

func (*Repo) DBStats added in v1.14.0

func (db *Repo) DBStats(ctx context.Context, schemaName string) (*DBStats, error)

DBStats returns a set of statistics for a specified schema.

func (*Repo) DebugLogSqlErr added in v0.2.1

func (db *Repo) DebugLogSqlErr(q string, err error) error

DebugLogSqlErr used to avoid not exists and already exists debug queries

func (*Repo) DropSchema added in v1.14.0

func (db *Repo) DropSchema(ctx context.Context, schemaName string) error

DropSchema drops PostgreSQL schema.

It returns ErrNotExist if schema does not exist.

func (*Repo) DropTable added in v1.14.0

func (db *Repo) DropTable(ctx context.Context, schemaName, tableName string, useCascade bool) error

DropTable drops PostgreSQL table.

It returns ErrNotExist is table does not exist.

func (*Repo) GetConnConfig added in v1.4.0

func (db *Repo) GetConnConfig() (*pgconn.Config, error)

func (*Repo) GetPoolConfig added in v1.4.0

func (db *Repo) GetPoolConfig() (*pgxpool.Config, error)

func (*Repo) GracefulShutdown

func (db *Repo) GracefulShutdown()

func (*Repo) Migrate added in v1.4.0

func (db *Repo) Migrate(ctx context.Context) error

func (*Repo) PoolFromString

func (db *Repo) PoolFromString(ctx context.Context, connString string) (*pgxpool.Pool, error)

func (*Repo) SanitizeString

func (db *Repo) SanitizeString(str string) string

func (*Repo) Schemas added in v1.14.0

func (db *Repo) Schemas(ctx context.Context) ([]string, error)

Schemas returns a sorted list of PostgreSQL schema names.

func (*Repo) TableStats added in v1.14.0

func (db *Repo) TableStats(ctx context.Context, schemaName, tableName string) (*TableStats, error)

TableStats returns a set of statistics for specified schema table.

func (*Repo) Tables added in v1.14.0

func (db *Repo) Tables(ctx context.Context, schemaName string) ([]string, error)

Tables returns a sorted list of specified schema PostgreSQL table names.

type SSL

type SSL struct {
	Enabled  bool   `json:"enabled" yaml:"enabled"`
	Verify   bool   `json:"verify" yaml:"verify"`
	CaPath   string `json:"ca" yaml:"ca"`
	KeyPath  string `json:"key" yaml:"key"`
	CertPath string `json:"cert" yaml:"cert"`
}

type TableStats added in v1.14.0

type TableStats struct {
	Table       string
	TableType   string
	SizeTotal   int32
	SizeIndexes int32
	SizeTable   int32
	Rows        int32
}

TableStats describes some statistics for a table.

Jump to

Keyboard shortcuts

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