db

package
v0.0.0-alpha Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2025 License: MIT Imports: 8 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 {
	Name         string
	DataType     string
	IsNullable   bool
	Default      string
	IsPrimaryKey bool
	Description  string
}

ColumnInfo represents information about a table column

type Connection

type Connection interface {
	// Schema operations
	ListTables(ctx context.Context) ([]TableInfo, error)
	DescribeTable(ctx context.Context, schema, tableName string) (*TableInfo, error)
	GetForeignKeys(ctx context.Context, schema, tableName string) ([]ForeignKeyInfo, error)
	SearchColumns(ctx context.Context, pattern string) ([]ColumnInfo, error)

	// Query operations
	Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)
	EnsureConnection(ctx context.Context)
}

Connection interface defines all database operations available to other packages This allows for dependency injection and easier testing with mocks

type ConnectionImpl

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

ConnectionImpl wraps a PostgreSQL connection pool and implements the Connection interface

func Connect

func Connect(ctx context.Context, cfg *config.DBConfig) (*ConnectionImpl, error)

Connect establishes a connection pool to PostgreSQL using the provided config

func (*ConnectionImpl) Close

func (c *ConnectionImpl) Close()

Close closes the database connection pool

func (*ConnectionImpl) DescribeTable

func (c *ConnectionImpl) DescribeTable(ctx context.Context, schema, tableName string) (*TableInfo, error)

DescribeTable returns detailed information about a specific table

func (*ConnectionImpl) EnsureConnection

func (c *ConnectionImpl) EnsureConnection(ctx context.Context)

EnsureConnection ensures we have a healthy database connection pool

func (*ConnectionImpl) Exec

func (c *ConnectionImpl) Exec(ctx context.Context, sql string, args ...interface{}) error

Exec executes a query without returning any rows

func (*ConnectionImpl) GetDatabaseInfo

func (c *ConnectionImpl) GetDatabaseInfo(ctx context.Context) (*DatabaseInfo, error)

GetDatabaseInfo returns basic information about the connected database

func (*ConnectionImpl) GetForeignKeys

func (c *ConnectionImpl) GetForeignKeys(ctx context.Context, schema, tableName string) ([]ForeignKeyInfo, error)

GetForeignKeys returns foreign key relationships for a table

func (*ConnectionImpl) ListTables

func (c *ConnectionImpl) ListTables(ctx context.Context) ([]TableInfo, error)

ListTables returns all tables and views in the database

func (*ConnectionImpl) Query

func (c *ConnectionImpl) Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)

Query executes a query and returns the rows

func (*ConnectionImpl) QueryRow

func (c *ConnectionImpl) QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row

QueryRow executes a query that returns at most one row

func (*ConnectionImpl) SearchColumns

func (c *ConnectionImpl) SearchColumns(ctx context.Context, pattern string) ([]ColumnInfo, error)

SearchColumns searches for columns matching a pattern across all tables

type DatabaseInfo

type DatabaseInfo struct {
	Host     string
	Port     int
	Database string
	User     string
	Version  string
}

DatabaseInfo holds information about the connected database

type ForeignKeyInfo

type ForeignKeyInfo struct {
	TableSchema        string
	TableName          string
	ColumnName         string
	ForeignTableSchema string
	ForeignTableName   string
	ForeignColumnName  string
	ConstraintName     string
}

ForeignKeyInfo represents foreign key relationships

type IndexInfo

type IndexInfo struct {
	Name       string
	TableName  string
	Columns    []string
	IsUnique   bool
	IsPrimary  bool
	Definition string
}

IndexInfo represents database index information

type TableInfo

type TableInfo struct {
	Schema        string
	Name          string
	Type          string // table, view, materialized view
	Description   string
	EstimatedRows int64 // Estimated row count from pg_class.reltuples
	Columns       []ColumnInfo
}

TableInfo represents information about a database table

Jump to

Keyboard shortcuts

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