Documentation ¶
Index ¶
- Variables
- func QuoteString(str string) string
- type Config
- type DBStats
- type ErrorLineExtract
- type Repo
- func (db *Repo) ConnectDB(ctx context.Context, tlsConfig *tls.Config) (*pgconn.PgConn, error)
- func (db *Repo) ConnectDBPool(ctx context.Context, tlsConfig *tls.Config) (*pgxpool.Pool, error)
- func (db *Repo) CreateSchema(ctx context.Context, schemaName string) error
- func (db *Repo) CreateTable(ctx context.Context, schemaName, tableName string) error
- func (db *Repo) DBStats(ctx context.Context, schemaName string) (*DBStats, error)
- func (db *Repo) DebugLogSqlErr(q string, err error) error
- func (db *Repo) DropSchema(ctx context.Context, schemaName string) error
- func (db *Repo) DropTable(ctx context.Context, schemaName, tableName string, useCascade bool) error
- func (db *Repo) GetConnConfig() (*pgconn.Config, error)
- func (db *Repo) GetPoolConfig() (*pgxpool.Config, error)
- func (db *Repo) GracefulShutdown()
- func (db *Repo) Migrate(ctx context.Context) error
- func (db *Repo) PoolFromString(ctx context.Context, connString string) (*pgxpool.Pool, error)
- func (db *Repo) SanitizeString(str string) string
- func (db *Repo) Schemas(ctx context.Context) ([]string, error)
- func (db *Repo) TableStats(ctx context.Context, schemaName, tableName string) (*TableStats, error)
- func (db *Repo) Tables(ctx context.Context, schemaName string) ([]string, error)
- type SSL
- type TableStats
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotExist = fmt.Errorf("schema or table does not exist") ErrAlreadyExist = fmt.Errorf("schema or table already exist") )
var ErrEmptyConfig = fmt.Errorf("pxgs: PSQL Config is required")
var MigrationsTable = "public.schema_version"
MigrationsTable is for saving actual schema version
Functions ¶
func QuoteString ¶
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
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 (*Repo) ConnectDBPool ¶ added in v1.4.0
ConnectDBPool initializes Pool connection
func (*Repo) CreateSchema ¶ added in v1.14.0
CreateSchema creates a new PostgreSQL schema.
It returns ErrAlreadyExist if schema already exist.
func (*Repo) CreateTable ¶ added in v1.14.0
CreateTable creates PostgreSQL jsonb table.
It returns ErrAlreadyExist if table already exist.
func (*Repo) DebugLogSqlErr ¶ added in v0.2.1
DebugLogSqlErr used to avoid not exists and already exists debug queries
func (*Repo) DropSchema ¶ added in v1.14.0
DropSchema drops PostgreSQL schema.
It returns ErrNotExist if schema does not exist.
func (*Repo) DropTable ¶ added in v1.14.0
DropTable drops PostgreSQL table.
It returns ErrNotExist is table does not exist.
func (*Repo) GetConnConfig ¶ added in v1.4.0
func (*Repo) GetPoolConfig ¶ added in v1.4.0
func (*Repo) GracefulShutdown ¶
func (db *Repo) GracefulShutdown()
func (*Repo) PoolFromString ¶
func (*Repo) SanitizeString ¶
func (*Repo) TableStats ¶ added in v1.14.0
TableStats returns a set of statistics for specified schema table.