db

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2025 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ColumnInfo

type ColumnInfo struct {
	ColumnName string `db:"column_name"`
	DataType   string `db:"data_type"`
}

type ColumnInfoEx

type ColumnInfoEx struct {
	ColumnName    string         `db:"column_name"`
	DataType      string         `db:"data_type"`
	ColumnDefault sql.NullString `db:"column_default"`
}

type DBConfig

type DBConfig struct {
	Title     string
	URL       string
	ViewsPath string
}

type Postgres

type Postgres struct {
	DB *sqlx.DB
	// contains filtered or unexported fields
}
var (
	Storage   *Postgres
	ErrNoRows = errors.New("sql: no rows in result set")
)

func New

func New(dataBaseURL string) (*Postgres, error)

func (*Postgres) BeginTransaction

func (pg *Postgres) BeginTransaction() (*Transaction, error)

func (*Postgres) Close

func (pg *Postgres) Close()

func (*Postgres) CreateGoStructDefinition

func (pg *Postgres) CreateGoStructDefinition(tableName string) (string, error)

func (*Postgres) CreateInsertStatement

func (pg *Postgres) CreateInsertStatement(tableName string) (string, error)

func (*Postgres) CreateUpdateStatement added in v0.0.8

func (pg *Postgres) CreateUpdateStatement(tableName string, headers []string, row []string) (string, error)

func (*Postgres) Exec

func (pg *Postgres) Exec(query string, args ...any) error

func (*Postgres) Get

func (pg *Postgres) Get(ret any, sqlStatement string, args ...any) error

func (*Postgres) GetPrimaryKeyColumns

func (pg *Postgres) GetPrimaryKeyColumns(tableName string) ([]string, error)

func (*Postgres) ListColumns

func (pg *Postgres) ListColumns(tableName string) ([]ColumnInfo, error)

func (*Postgres) ListRecords

func (pg *Postgres) ListRecords(
	tableName string,
	pkField string,
	offset int,
	limit int,
	where string,
	orderBy string,
) (
	[]map[string]any,
	[]ColumnInfo,
	int,
	error,
)

func (*Postgres) ListTablesAndViews

func (pg *Postgres) ListTablesAndViews() ([]TableInfo, error)

func (*Postgres) Query

func (pg *Postgres) Query(query string, args ...any) (*sql.Rows, error)

func (*Postgres) QueryRow

func (pg *Postgres) QueryRow(query string, args ...any) *sql.Row

func (*Postgres) QueryRowContext

func (pg *Postgres) QueryRowContext(
	ctx context.Context,
	query string,
	args ...any,
) *sql.Row

func (*Postgres) QuerySQL added in v0.0.8

func (pg *Postgres) QuerySQL(query string) ([]map[string]any, []ColumnInfo, error)

QuerySQL executes the given SQL query and returns records with column definitions.

func (*Postgres) RenameColumn added in v0.1.0

func (pg *Postgres) RenameColumn(tableName string, oldColName string, newColName string) error

func (*Postgres) RenameTable added in v0.1.0

func (pg *Postgres) RenameTable(oldName, newName string) error

func (*Postgres) Stats

func (pg *Postgres) Stats() sql.DBStats

func (*Postgres) UpdateDataCell

func (pg *Postgres) UpdateDataCell(
	tableName,
	fieldName string,
	newValue any,
	pkField []string,
	pkValue []any,
) error

type TableInfo

type TableInfo struct {
	Name       string         `db:"table_name"`
	Type       string         `db:"table_type"`
	Size       string         `db:"table_size"`
	PrimaryKey sql.NullString `db:"primary_key"`
}

type Transaction

type Transaction struct {
	// contains filtered or unexported fields
}

func (*Transaction) Commit

func (pg *Transaction) Commit() error

func (*Transaction) Exec

func (pg *Transaction) Exec(query string, args ...any) error

func (*Transaction) Get

func (pg *Transaction) Get(dest any, query string, args ...any) error

func (*Transaction) Query

func (pg *Transaction) Query(query string, args ...any) (*sql.Rows, error)

func (*Transaction) QueryRow

func (pg *Transaction) QueryRow(query string, args ...any) *sql.Row

func (*Transaction) Rollback

func (pg *Transaction) Rollback() error

func (*Transaction) Select

func (pg *Transaction) Select(dest any, query string, args ...any) error

Jump to

Keyboard shortcuts

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