Help us shape the future of Go! Take the 2026 Go Developer Survey

postgresbe

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DQL keywords
	SELECT  = "select"
	WITH    = "with"
	SHOW    = "show"
	EXPLAIN = "explain"
	VALUES  = "values"
	TABLE   = "table"

	// max rows fetched when browsing a table from the tree view
	FetchLimit = 200
)

Variables

This section is empty.

Functions

func BuildDsn

func BuildDsn(userName, password, host, port, dbName, sslMode string) string

BuildDsn builds a postgres connection string of the form postgres://user:pass@host:port/dbname?sslmode=<sslMode>

func GetDbName

func GetDbName() string

Types

type Backend

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

Backend adapts the postgres data-access layer to the db.Backend contract.

func Connect

func Connect(cfg Config) (*Backend, error)

Connect opens a postgres connection and pings it before returning.

func (*Backend) Close

func (b *Backend) Close() error

func (*Backend) ColumnIndexTypes

func (b *Backend) ColumnIndexTypes(namespace, table string) (map[string]string, error)

ColumnIndexTypes returns index type labels for indexed columns of namespace.table.

func (*Backend) ColumnsMeta

func (b *Backend) ColumnsMeta(namespace, table string) ([]db.ColumnMeta, error)

ColumnsMeta returns column metadata for namespace.table.

func (*Backend) CurrentNamespace

func (b *Backend) CurrentNamespace() string

CurrentNamespace reports the schema new objects resolve to on this connection (usually "public"), so browsers can scope their listing to it (optional interface, not part of db.Backend).

func (*Backend) FetchTable

func (b *Backend) FetchTable(namespace, table string, limit int) (*data.Frame, error)

FetchTable loads up to limit rows of namespace.table.

func (*Backend) Kind

func (b *Backend) Kind() string

func (*Backend) Namespaces

func (b *Backend) Namespaces() ([]string, error)

Namespaces lists the user schemas of the database.

func (*Backend) PrimaryKeys

func (b *Backend) PrimaryKeys(namespace, table string) ([]string, error)

PrimaryKeys lists the primary-key column names of namespace.table.

func (*Backend) Run

func (b *Backend) Run(stmt string) (db.Result, error)

Run executes a statement with the same DQL / RETURNING routing as the underlying data-access layer, but scans query results into typed frame cells instead of pre-rendered strings.

func (*Backend) Tables

func (b *Backend) Tables(namespace string) ([]string, error)

Tables lists the tables of one schema.

func (*Backend) Title

func (b *Backend) Title() string

type Config

type Config struct {
	UserName string
	Password string
	Host     string
	Port     string
	DbName   string
	SslMode  string
}

Config holds the connection parameters for a PostgreSQL server.

func (Config) Dsn

func (c Config) Dsn() string

Dsn renders the config as a driver connection string: postgres://user:pass@host:port/dbname?sslmode=<sslmode>

type DB

type DB struct {
	*sql.DB
	// contains filtered or unexported fields
}
var (
	DbClient *DB
)

func GetDB

func GetDB() *DB

func NewDB

func NewDB(dsn string, dbName string) (*DB, error)

func (*DB) ColumnIndexTypes

func (db *DB) ColumnIndexTypes(schema, table string) (map[string]string, error)

ColumnIndexTypes returns a column→index-type map for schema.table. Priority: PK > UNIQUE > INDEX.

func (*DB) ColumnsMeta

func (db *DB) ColumnsMeta(schema, table string) ([]dbapi.ColumnMeta, error)

ColumnsMeta returns column metadata for schema.table, in ordinal order. Column comments are resolved via col_description.

func (*DB) FetchTableRecords

func (db *DB) FetchTableRecords(schema, table string) (fields []string, records [][]string, err error)

func (*DB) ListPrimaryKeys

func (db *DB) ListPrimaryKeys(schema, table string) ([]string, error)

ListPrimaryKeys lists the primary-key column names of schema.table, in index-ordinal order. Empty when the table has no primary key.

func (*DB) ListSchemas

func (db *DB) ListSchemas() ([]string, error)

func (*DB) ListTables

func (db *DB) ListTables(schema string) ([]string, error)

func (*DB) RawExec

func (db *DB) RawExec(query string) (sql.Result, error)

func (*DB) RawQuery

func (db *DB) RawQuery(query string) (fields []string, records [][]string, err error)

func (*DB) RawSqlCommand

func (db *DB) RawSqlCommand(query string) (rawCmdResult RawCommandResult, err error)

type RawCommandResult

type RawCommandResult struct {
	Fields  []string
	Records [][]string
	Result  sql.Result
	IsDQL   bool
}

Jump to

Keyboard shortcuts

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