Documentation
¶
Index ¶
- func New() connector.Connector
- type PostgresConnector
- func (c *PostgresConnector) AlterTable(ctx context.Context, tableName string, changes []connector.SchemaChange) error
- func (c *PostgresConnector) BeginTx(ctx context.Context, opts *sql.TxOptions) (*sqlx.Tx, error)
- func (c *PostgresConnector) BuildCount(_ context.Context, req connector.CountRequest) (string, []interface{}, error)
- func (c *PostgresConnector) BuildDelete(_ context.Context, req connector.DeleteRequest) (string, []interface{}, error)
- func (c *PostgresConnector) BuildInsert(_ context.Context, req connector.InsertRequest) (string, []interface{}, error)
- func (c *PostgresConnector) BuildSelect(_ context.Context, req connector.SelectRequest) (string, []interface{}, error)
- func (c *PostgresConnector) BuildUpdate(_ context.Context, req connector.UpdateRequest) (string, []interface{}, error)
- func (c *PostgresConnector) CallProcedure(ctx context.Context, name string, params map[string]interface{}) ([]map[string]interface{}, error)
- func (c *PostgresConnector) Connect(cfg connector.ConnectionConfig) error
- func (c *PostgresConnector) CreateTable(ctx context.Context, def model.TableSchema) error
- func (c *PostgresConnector) DB() *sqlx.DB
- func (c *PostgresConnector) Disconnect() error
- func (c *PostgresConnector) DriverName() string
- func (c *PostgresConnector) DropTable(ctx context.Context, tableName string) error
- func (c *PostgresConnector) GetStoredProcedures(ctx context.Context) ([]model.StoredProcedure, error)
- func (c *PostgresConnector) GetTableNames(ctx context.Context) ([]string, error)
- func (c *PostgresConnector) IntrospectSchema(ctx context.Context) (*model.Schema, error)
- func (c *PostgresConnector) IntrospectTable(ctx context.Context, tableName string) (*model.TableSchema, error)
- func (c *PostgresConnector) ParameterPlaceholder(index int) string
- func (c *PostgresConnector) Ping(ctx context.Context) error
- func (c *PostgresConnector) QuoteIdentifier(name string) string
- func (c *PostgresConnector) SupportsReturning() bool
- func (c *PostgresConnector) SupportsUpsert() bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type PostgresConnector ¶
type PostgresConnector struct {
// contains filtered or unexported fields
}
PostgresConnector implements connector.Connector for PostgreSQL databases.
func (*PostgresConnector) AlterTable ¶
func (c *PostgresConnector) AlterTable(ctx context.Context, tableName string, changes []connector.SchemaChange) error
AlterTable applies a list of schema changes to an existing table.
func (*PostgresConnector) BeginTx ¶ added in v0.1.5
BeginTx starts a new database transaction with the given options.
func (*PostgresConnector) BuildCount ¶
func (c *PostgresConnector) BuildCount(_ context.Context, req connector.CountRequest) (string, []interface{}, error)
BuildCount constructs a SELECT COUNT(*) query with optional filtering.
func (*PostgresConnector) BuildDelete ¶
func (c *PostgresConnector) BuildDelete(_ context.Context, req connector.DeleteRequest) (string, []interface{}, error)
BuildDelete constructs a DELETE query with parameterized WHERE conditions. It supports both filter-based and ID-based deletes.
func (*PostgresConnector) BuildInsert ¶
func (c *PostgresConnector) BuildInsert(_ context.Context, req connector.InsertRequest) (string, []interface{}, error)
BuildInsert constructs an INSERT query with RETURNING * for PostgreSQL. It supports batch inserts with multiple value rows. All column names are derived from the first record, and subsequent records must have the same columns.
func (*PostgresConnector) BuildSelect ¶
func (c *PostgresConnector) BuildSelect(_ context.Context, req connector.SelectRequest) (string, []interface{}, error)
BuildSelect constructs a SELECT query from the given request. It quotes all identifiers, applies field selection, filtering, ordering, and pagination using PostgreSQL $N parameter placeholders.
func (*PostgresConnector) BuildUpdate ¶
func (c *PostgresConnector) BuildUpdate(_ context.Context, req connector.UpdateRequest) (string, []interface{}, error)
BuildUpdate constructs an UPDATE query with parameterized SET values. It supports both filter-based and ID-based updates. When IDs are provided without a filter, the first primary key column would need to be specified; for now, IDs are applied as an IN clause on the "id" column by convention.
func (*PostgresConnector) CallProcedure ¶
func (c *PostgresConnector) CallProcedure(ctx context.Context, name string, params map[string]interface{}) ([]map[string]interface{}, error)
CallProcedure executes a stored procedure or function using SELECT * FROM notation, which works for PostgreSQL functions that return result sets.
func (*PostgresConnector) Connect ¶
func (c *PostgresConnector) Connect(cfg connector.ConnectionConfig) error
Connect establishes a connection to the PostgreSQL database using the provided configuration. It configures connection pool settings and stores the schema name for introspection queries.
func (*PostgresConnector) CreateTable ¶
func (c *PostgresConnector) CreateTable(ctx context.Context, def model.TableSchema) error
CreateTable creates a new table from a TableSchema definition, translating Go/model types back to PostgreSQL column types.
func (*PostgresConnector) DB ¶
func (c *PostgresConnector) DB() *sqlx.DB
DB returns the underlying sqlx.DB connection pool.
func (*PostgresConnector) Disconnect ¶
func (c *PostgresConnector) Disconnect() error
Disconnect closes the database connection pool.
func (*PostgresConnector) DriverName ¶
func (c *PostgresConnector) DriverName() string
DriverName returns the driver identifier for PostgreSQL.
func (*PostgresConnector) DropTable ¶
func (c *PostgresConnector) DropTable(ctx context.Context, tableName string) error
DropTable drops a table from the database.
func (*PostgresConnector) GetStoredProcedures ¶
func (c *PostgresConnector) GetStoredProcedures(ctx context.Context) ([]model.StoredProcedure, error)
GetStoredProcedures returns all stored procedures and functions in the configured schema.
func (*PostgresConnector) GetTableNames ¶
func (c *PostgresConnector) GetTableNames(ctx context.Context) ([]string, error)
GetTableNames returns a list of all table names in the configured schema.
func (*PostgresConnector) IntrospectSchema ¶
IntrospectSchema returns the full schema for the configured PostgreSQL schema, including all tables, views, procedures, and functions.
func (*PostgresConnector) IntrospectTable ¶
func (c *PostgresConnector) IntrospectTable(ctx context.Context, tableName string) (*model.TableSchema, error)
IntrospectTable returns the schema for a single table or view.
func (*PostgresConnector) ParameterPlaceholder ¶
func (c *PostgresConnector) ParameterPlaceholder(index int) string
ParameterPlaceholder returns a PostgreSQL-style numbered parameter placeholder (e.g., $1, $2, $3).
func (*PostgresConnector) Ping ¶
func (c *PostgresConnector) Ping(ctx context.Context) error
Ping verifies the database connection is alive.
func (*PostgresConnector) QuoteIdentifier ¶
func (c *PostgresConnector) QuoteIdentifier(name string) string
QuoteIdentifier wraps a SQL identifier in double quotes, escaping any embedded double quotes to prevent SQL injection.
func (*PostgresConnector) SupportsReturning ¶
func (c *PostgresConnector) SupportsReturning() bool
SupportsReturning indicates that PostgreSQL supports RETURNING clauses.
func (*PostgresConnector) SupportsUpsert ¶
func (c *PostgresConnector) SupportsUpsert() bool
SupportsUpsert indicates that PostgreSQL supports ON CONFLICT (upsert).