postgres

package
v0.0.0-...-2853686 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// POSTGRES_SCHEMA_QUERY is the SQL query used to describe a table schema in PostgreSQL.
	POSTGRES_SCHEMA_QUERY = "SELECT column_name, data_type, character_maximum_length FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = %s;"

	// POSTGRES_TABLE_LIST_QUERY is the SQL query used to list all tables in a schema in PostgreSQL.
	POSTGRES_TABLE_LIST_QUERY = "SELECT table_name FROM information_schema.tables WHERE table_schema= %s AND table_type='BASE TABLE';"
)

Variables

View Source
var DB_PASSWORD = "DB_PASSWORD"

DB_PASSWORD is the environment variable that holds the database password.

Functions

func NewPostgres

func NewPostgres(dbClient *sql.DB) (types.ISQL, error)

NewPostgres creates a new PostgreSQL client with the given sql.DB.

func NewPostgresWithConfig

func NewPostgresWithConfig(dbConfig *config.Config) (types.ISQL, error)

NewPostgresWithConfig creates a new PostgreSQL client with the given configuration. It returns an error if the DB_PASSWORD environment variable is not set.

Types

type Postgres

type Postgres struct {
	Client *sql.DB
}

Postgres is a PostgreSQL implementation of the ISQL interface.

func (*Postgres) Execute

func (p *Postgres) Execute(query string) ([]byte, error)

Execute executes a SQL query and returns the result as a JSON byte slice. It returns an error if the SQL query fails.

func (*Postgres) Schema

func (p *Postgres) Schema(table string) (types.Table, error)

Schema returns the schema of a table in the database. It returns an error if the SQL query fails.

func (*Postgres) Tables

func (p *Postgres) Tables(databaseName string) ([]string, error)

Tables returns a list of all tables in the given database. It returns an error if the SQL query fails.

Jump to

Keyboard shortcuts

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