Documentation
¶
Index ¶
- Variables
- func Connect(cfg *config.DatabaseConfig) (interfaces.DB, error)
- func ConvertToPostgresArray(val interface{}) interface{}
- func MapsToJSONStrings(arr []map[string]interface{}) ([]string, error)
- func NewDatabaseRepo(db *PostgresDbService) interfaces.DatabaseRepo
- func ParseNumeric(v interface{}) interface{}
- func ParseStringArrayElements(strSlice []string) []interface{}
- func ParseUUID(v interface{}) interface{}
- func ParseValue(v interface{}) interface{}
- func SplitQualifiedName(qualifiedName string) ([]string, error)
- func TryParseJSON(b []byte) (interface{}, bool)
- func TryParseJSONElement(elem string) interface{}
- func ValidateAndQuoteColumnList(columns []string) ([]string, error)
- func ValidateAndQuoteOrderByList(orderByList []string) ([]string, error)
- func ValidateColumnName(name string) error
- func ValidateOperator(op string) error
- func ValidateQualifiedNameParts(parts []string, qualifiedName string) error
- func ValidateQualifiedTableName(qualifiedName string) error
- func ValidateTableName(name string) error
- type BulkRepoImpl
- func (b *BulkRepoImpl) BulkDelete(tableName string, ids []interface{}, idColumn string) (int64, error)
- func (b *BulkRepoImpl) BulkInsert(tableName string, records []map[string]interface{}) ([]map[string]interface{}, error)
- func (b *BulkRepoImpl) BulkUpdate(tableName string, updates []map[string]interface{}, whereColumn string) (int64, error)
- func (b *BulkRepoImpl) Upsert(tableName string, data map[string]interface{}, ...) (map[string]interface{}, error)
- type Connector
- type CoreRepoImpl
- func (c *CoreRepoImpl) ExecuteFunction(ctx context.Context, name string, args map[string]interface{}) (any, error)
- func (c *CoreRepoImpl) ExecuteQuery(name string, params models.QueryParams) (any, error)
- func (c *CoreRepoImpl) ExecuteRawSQL(ctx context.Context, sql string) error
- func (c *CoreRepoImpl) ListCollections(schema string) ([]models.Table, error)
- func (c *CoreRepoImpl) Ping() (bool, error)
- type DDLRepoImpl
- func (d *DDLRepoImpl) AddField(collection string, req models.AddColumnRequest) error
- func (d *DDLRepoImpl) AlterCollection(collection string, req models.AlterTableRequest) error
- func (d *DDLRepoImpl) CheckTableExists(tableName string) (bool, error)
- func (d *DDLRepoImpl) CreateCollection(req models.CreateTableRequest) error
- type DMLRepoImpl
- func (d *DMLRepoImpl) Delete(collection string, id any) error
- func (d *DMLRepoImpl) DeleteByColumns(collection string, where models.ComplexFilter) (int64, error)
- func (d *DMLRepoImpl) Insert(collection string, data map[string]any) (any, error)
- func (d *DMLRepoImpl) Update(collection string, id any, data map[string]any) (any, error)
- func (d *DMLRepoImpl) UpdateByColumns(collection string, where models.ComplexFilter, data map[string]any) (any, error)
- type DSNBuilder
- type DatabaseRepoImpl
- func (dr *DatabaseRepoImpl) AsBulkRepo() interfaces.BulkRepo
- func (dr *DatabaseRepoImpl) AsCoreRepo() interfaces.CoreRepo
- func (dr *DatabaseRepoImpl) AsDDLRepo() interfaces.DDLRepo
- func (dr *DatabaseRepoImpl) AsDMLRepo() interfaces.DMLRepo
- func (dr *DatabaseRepoImpl) AsMigrationRepo() interfaces.MigrationRepo
- func (dr *DatabaseRepoImpl) AsPerformanceRepo() interfaces.PerformanceRepo
- func (dr *DatabaseRepoImpl) AsRelationshipRepo() interfaces.RelationshipRepo
- type MigrationRepoImpl
- type PerformanceRepoImpl
- type PostgresConnectorImpl
- type PostgresDSNBuilder
- type PostgresDbService
- func (postgresDbService *PostgresDbService) AddField(collection string, req models.AddColumnRequest) error
- func (postgresDbService *PostgresDbService) AlterCollection(collection string, req models.AlterTableRequest) error
- func (postgresDbService *PostgresDbService) AnalyzeQuery(query string) ([]string, error)
- func (postgresDbService *PostgresDbService) BuildAdvancedQuery(tableName string, params models.QueryParams) (string, []interface{})
- func (postgresDbService *PostgresDbService) BuildAggregateParts(aggregates []models.AggregateFunction) []string
- func (postgresDbService *PostgresDbService) BuildAnyCondition(filter models.QueryFilter, argCounter int) (string, []interface{}, int)
- func (postgresDbService *PostgresDbService) BuildColumnDefinitions(columns []models.ColumnDefinition) []string
- func (postgresDbService *PostgresDbService) BuildComplexFilter(filter models.ComplexFilter, argCounter int) (string, []interface{}, int)
- func (postgresDbService *PostgresDbService) BuildFilterCondition(filter models.QueryFilter, argCounter int) (string, []interface{}, int)
- func (postgresDbService *PostgresDbService) BuildForeignKeyDefinitions(foreignKeys []models.ForeignKeyDef) []string
- func (postgresDbService *PostgresDbService) BuildGroupByClause(groupBy []string) string
- func (postgresDbService *PostgresDbService) BuildHavingClause(having []models.QueryFilter, argCounter int) (string, []interface{}, int)
- func (postgresDbService *PostgresDbService) BuildInCondition(filter models.QueryFilter, useNot bool, argCounter int) (string, []interface{}, int)
- func (postgresDbService *PostgresDbService) BuildJoinClause(joins []models.JoinClause) string
- func (postgresDbService *PostgresDbService) BuildLimitOffsetClause(limit, offset *int, argCounter int) (string, []interface{})
- func (postgresDbService *PostgresDbService) BuildNullCondition(filter models.QueryFilter, useNot bool, argCounter int) (string, []interface{}, int)
- func (postgresDbService *PostgresDbService) BuildOrderByClause(orderBy []string) string
- func (postgresDbService *PostgresDbService) BuildSelectClause(params models.QueryParams) (string, []interface{}, int)
- func (postgresDbService *PostgresDbService) BuildSelectColumnParts(selectCols []string) []string
- func (postgresDbService *PostgresDbService) BuildSimpleCondition(filter models.QueryFilter, operator string, argCounter int) (string, []interface{}, int)
- func (postgresDbService *PostgresDbService) BuildWhereClause(params models.QueryParams, argCounter int) (string, []interface{}, int)
- func (postgresDbService *PostgresDbService) BulkDelete(tableName string, ids []interface{}, idColumn string) (int64, error)
- func (postgresDbService *PostgresDbService) BulkInsert(tableName string, records []map[string]interface{}) ([]map[string]interface{}, error)
- func (postgresDbService *PostgresDbService) BulkUpdate(tableName string, updates []map[string]interface{}, whereColumn string) (int64, error)
- func (postgresDbService *PostgresDbService) CheckTableExists(tableName string) (bool, error)
- func (postgresDbService *PostgresDbService) ConvertComplexArray(val interface{}) interface{}
- func (postgresDbService *PostgresDbService) ConvertPrimitiveArray(val interface{}) interface{}
- func (postgresDbService *PostgresDbService) CreateCollection(req models.CreateTableRequest) error
- func (r *PostgresDbService) CreateForeignKeyConstraint(relationship *models.RelationshipDefinition) error
- func (postgresDbService *PostgresDbService) CreateIndex(tableName, indexName, columns string) error
- func (postgresDbService *PostgresDbService) CreateIndexFromDefinition(tableName string, idx models.IndexDefinition) error
- func (r *PostgresDbService) CreateJoinTable(relationship *models.RelationshipDefinition, ...) error
- func (postgresDbService *PostgresDbService) Delete(collection string, id any) error
- func (postgresDbService *PostgresDbService) DeleteByColumns(collection string, where models.ComplexFilter) (int64, error)
- func (postgresDbService *PostgresDbService) DropColumn(tableName string, req models.DropColumnRequest) error
- func (r *PostgresDbService) DropJoinTable(tableName string) error
- func (r *PostgresDbService) DropRelationshipConstraints(relationship *models.RelationshipDefinition) error
- func (r *PostgresDbService) ExecuteFunction(ctx context.Context, name string, args map[string]interface{}) (any, error)
- func (postgresDbService *PostgresDbService) ExecuteQuery(name string, params models.QueryParams) (any, error)
- func (postgresDbService *PostgresDbService) ExecuteRawSQL(ctx context.Context, sql string) error
- func (r *PostgresDbService) ForeignKeyConstraintExists(tableName string, constraintName string) (bool, error)
- func (postgresDbService *PostgresDbService) GetMigrationHistory() ([]map[string]interface{}, error)
- func (postgresDbService *PostgresDbService) GetPerformanceMetrics() (map[string]interface{}, error)
- func (r *PostgresDbService) GetRelationshipData(ctx context.Context, relationship *models.RelationshipDefinition, ...) ([]map[string]interface{}, error)
- func (postgresDbService *PostgresDbService) Insert(collection string, data map[string]any) (any, error)
- func (postgresDbService *PostgresDbService) IsValidAggregateFunction(funcName string) bool
- func (postgresDbService *PostgresDbService) ListCollections(schema string) ([]models.Table, error)
- func (postgresDbService *PostgresDbService) ModifyColumn(tableName string, req models.ModifyColumnRequest) error
- func (s *PostgresDbService) ParseRow(columns []string, rawValues []interface{}) map[string]interface{}
- func (postgresDbService *PostgresDbService) Ping() (bool, error)
- func (postgresDbService *PostgresDbService) RecordMigration(name, sql, checksum string) error
- func (r *PostgresDbService) RemoveManyToManyRelations(relationship *models.RelationshipDefinition, sourceID interface{}, ...) (int, error)
- func (r *PostgresDbService) RemoveOneToManyRelations(relationship *models.RelationshipDefinition, sourceID interface{}, ...) (int, error)
- func (postgresDbService *PostgresDbService) RenameColumn(tableName string, req models.RenameColumnRequest) error
- func (r *PostgresDbService) SetManyToManyRelations(relationship *models.RelationshipDefinition, sourceID interface{}, ...) ([]map[string]interface{}, error)
- func (r *PostgresDbService) SetOneToManyRelation(relationship *models.RelationshipDefinition, sourceID interface{}, ...) error
- func (r *PostgresDbService) SetOneToManyRelations(relationship *models.RelationshipDefinition, sourceID interface{}, ...) error
- func (r *PostgresDbService) SetOneToOneRelation(relationship *models.RelationshipDefinition, sourceID interface{}, ...) error
- func (postgresDbService *PostgresDbService) ToInterfaceSlice(v interface{}) ([]interface{}, bool)
- func (postgresDbService *PostgresDbService) Update(collection string, id any, data map[string]any) (any, error)
- func (postgresDbService *PostgresDbService) UpdateByColumns(collection string, where models.ComplexFilter, data map[string]any) (any, error)
- func (postgresDbService *PostgresDbService) Upsert(tableName string, data map[string]interface{}, conflictColumns []string, ...) (map[string]interface{}, error)
- func (postgresDbService *PostgresDbService) ValidateCreateTableRequest(req models.CreateTableRequest) error
- type RelationshipRepoImpl
- func (r *RelationshipRepoImpl) CreateForeignKeyConstraint(relationship *models.RelationshipDefinition) error
- func (r *RelationshipRepoImpl) CreateJoinTable(relationship *models.RelationshipDefinition, ...) error
- func (r *RelationshipRepoImpl) DropJoinTable(tableName string) error
- func (r *RelationshipRepoImpl) DropRelationshipConstraints(relationship *models.RelationshipDefinition) error
- func (r *RelationshipRepoImpl) GetRelationshipData(ctx context.Context, relationship *models.RelationshipDefinition, ...) ([]map[string]interface{}, error)
- func (r *RelationshipRepoImpl) RemoveManyToManyRelations(relationship *models.RelationshipDefinition, sourceID interface{}, ...) (int, error)
- func (r *RelationshipRepoImpl) RemoveOneToManyRelations(relationship *models.RelationshipDefinition, sourceID interface{}, ...) (int, error)
- func (r *RelationshipRepoImpl) SetManyToManyRelations(relationship *models.RelationshipDefinition, sourceID interface{}, ...) ([]map[string]interface{}, error)
- func (r *RelationshipRepoImpl) SetOneToManyRelation(relationship *models.RelationshipDefinition, sourceID interface{}, ...) error
- func (r *RelationshipRepoImpl) SetOneToManyRelations(relationship *models.RelationshipDefinition, sourceID interface{}, ...) error
- func (r *RelationshipRepoImpl) SetOneToOneRelation(relationship *models.RelationshipDefinition, sourceID interface{}, ...) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var OpenDB = sql.Open
allow tests to stub sql.Open/Ping
var PingDB = func(db *sql.DB) error { return db.Ping() }
Functions ¶
func Connect ¶
func Connect(cfg *config.DatabaseConfig) (interfaces.DB, error)
ConnetPostgres creates a DSN string for Postgres using the provided config.
func ConvertToPostgresArray ¶
func ConvertToPostgresArray(val interface{}) interface{}
func MapsToJSONStrings ¶
func NewDatabaseRepo ¶
func NewDatabaseRepo(db *PostgresDbService) interfaces.DatabaseRepo
NewDatabaseRepo creates a new composite DatabaseRepo implementation
func ParseNumeric ¶
func ParseNumeric(v interface{}) interface{}
func ParseStringArrayElements ¶
func ParseStringArrayElements(strSlice []string) []interface{}
ParseStringArrayElements parses each string element as JSON if possible
func ParseValue ¶
func ParseValue(v interface{}) interface{}
func SplitQualifiedName ¶
SplitQualifiedName splits a qualified table name on dots while respecting quoted identifiers
func TryParseJSON ¶
TryParseJSON attempts to parse bytes as JSON, returns parsed value and success flag
func TryParseJSONElement ¶
func TryParseJSONElement(elem string) interface{}
TryParseJSONElement attempts to parse a string element as JSON
func ValidateAndQuoteColumnList ¶
ValidateAndQuoteColumnList validates and safely quotes a list of column names Used for SELECT, GROUP BY, and similar clauses that accept column lists
func ValidateAndQuoteOrderByList ¶
ValidateAndQuoteOrderByList validates and safely quotes ORDER BY columns Handles formats like "column ASC", "column DESC", "column"
func ValidateColumnName ¶
ValidateColumnName ensures column name is safe for SQL
func ValidateOperator ¶
ValidateOperator ensures operator is in the whitelist and safe to use
func ValidateQualifiedNameParts ¶
ValidateQualifiedNameParts validates the split parts of a qualified name
func ValidateQualifiedTableName ¶
ValidateQualifiedTableName ensures qualified table name (schema.table) is safe for SQL Supports formats like "table", "schema.table", "schema"."table", or "public"."relations"
func ValidateTableName ¶
ValidateTableName ensures table name is safe for SQL
Example ¶
ExampleValidateTableName demonstrates proper usage of validation functions
package main
import (
"fmt"
postgres "github.com/aptlogica/go-postgres-rest/pkg/database/postgres"
)
func main() {
// Example 1: Validate table name
if err := postgres.ValidateTableName("users"); err != nil {
fmt.Println("Invalid table name:", err)
} else {
fmt.Println("Table name 'users' is valid")
}
// Example 2: Validate column name
if err := postgres.ValidateColumnName("user_id"); err != nil {
fmt.Println("Invalid column name:", err)
} else {
fmt.Println("Column name 'user_id' is valid")
}
// Example 3: Reject SQL injection attempts
if err := postgres.ValidateTableName("users; DROP TABLE users; --"); err != nil {
fmt.Println("Rejected SQL injection attempt")
}
// Example 4: Validate operator
if err := postgres.ValidateOperator("like"); err != nil {
fmt.Println("Invalid operator:", err)
} else {
fmt.Println("Operator 'like' is valid")
}
}
Output: Table name 'users' is valid Column name 'user_id' is valid Rejected SQL injection attempt Operator 'like' is valid
Types ¶
type BulkRepoImpl ¶
type BulkRepoImpl struct {
// contains filtered or unexported fields
}
BulkRepoImpl implements BulkRepo interface
func NewBulkRepo ¶
func NewBulkRepo(db *PostgresDbService) *BulkRepoImpl
func (*BulkRepoImpl) BulkDelete ¶
func (b *BulkRepoImpl) BulkDelete(tableName string, ids []interface{}, idColumn string) (int64, error)
BulkDelete deletes multiple records
func (*BulkRepoImpl) BulkInsert ¶
func (b *BulkRepoImpl) BulkInsert(tableName string, records []map[string]interface{}) ([]map[string]interface{}, error)
BulkInsert inserts multiple records
func (*BulkRepoImpl) BulkUpdate ¶
func (b *BulkRepoImpl) BulkUpdate(tableName string, updates []map[string]interface{}, whereColumn string) (int64, error)
BulkUpdate updates multiple records
type Connector ¶
type Connector interface {
Connect(dsn string) (interfaces.DB, error)
}
Connector defines the interface for SQL database connections
func NewPostgresConnector ¶
func NewPostgresConnector() Connector
NewPostgresConnector creates a new PostgreSQL connector with default settings
type CoreRepoImpl ¶
type CoreRepoImpl struct {
// contains filtered or unexported fields
}
CoreRepoImpl implements CoreRepo interface
func NewCoreRepo ¶
func NewCoreRepo(db *PostgresDbService) *CoreRepoImpl
func (*CoreRepoImpl) ExecuteFunction ¶
func (c *CoreRepoImpl) ExecuteFunction(ctx context.Context, name string, args map[string]interface{}) (any, error)
ExecuteFunction executes a PostgreSQL function
func (*CoreRepoImpl) ExecuteQuery ¶
func (c *CoreRepoImpl) ExecuteQuery(name string, params models.QueryParams) (any, error)
ExecuteQuery executes a complex query with parameters
func (*CoreRepoImpl) ExecuteRawSQL ¶
func (c *CoreRepoImpl) ExecuteRawSQL(ctx context.Context, sql string) error
ExecuteRawSQL executes raw SQL statements
func (*CoreRepoImpl) ListCollections ¶
func (c *CoreRepoImpl) ListCollections(schema string) ([]models.Table, error)
ListCollections retrieves all tables from a schema
func (*CoreRepoImpl) Ping ¶
func (c *CoreRepoImpl) Ping() (bool, error)
Ping checks the database connection
type DDLRepoImpl ¶
type DDLRepoImpl struct {
// contains filtered or unexported fields
}
DDLRepoImpl implements DDLRepo interface
func NewDDLRepo ¶
func NewDDLRepo(db *PostgresDbService) *DDLRepoImpl
func (*DDLRepoImpl) AddField ¶
func (d *DDLRepoImpl) AddField(collection string, req models.AddColumnRequest) error
AddField adds a new column to a table
func (*DDLRepoImpl) AlterCollection ¶
func (d *DDLRepoImpl) AlterCollection(collection string, req models.AlterTableRequest) error
AlterCollection alters an existing table
func (*DDLRepoImpl) CheckTableExists ¶
func (d *DDLRepoImpl) CheckTableExists(tableName string) (bool, error)
CheckTableExists checks if a table exists
func (*DDLRepoImpl) CreateCollection ¶
func (d *DDLRepoImpl) CreateCollection(req models.CreateTableRequest) error
CreateCollection creates a new table
type DMLRepoImpl ¶
type DMLRepoImpl struct {
// contains filtered or unexported fields
}
DMLRepoImpl implements DMLRepo interface
func NewDMLRepo ¶
func NewDMLRepo(db *PostgresDbService) *DMLRepoImpl
func (*DMLRepoImpl) Delete ¶
func (d *DMLRepoImpl) Delete(collection string, id any) error
Delete deletes a record from a collection
func (*DMLRepoImpl) DeleteByColumns ¶
func (d *DMLRepoImpl) DeleteByColumns(collection string, where models.ComplexFilter) (int64, error)
DeleteByColumns deletes rows matching the provided column criteria.
func (*DMLRepoImpl) UpdateByColumns ¶
func (d *DMLRepoImpl) UpdateByColumns(collection string, where models.ComplexFilter, data map[string]any) (any, error)
UpdateByColumns updates specified columns for rows matching the provided column criteria.
type DSNBuilder ¶
type DSNBuilder interface {
BuildDSN(cfg *config.DatabaseConfig) (string, error)
}
DSNBuilder defines the interface for building database connection strings
func NewPostgresDSNBuilder ¶
func NewPostgresDSNBuilder() DSNBuilder
NewPostgresDSNBuilder creates a new DSN builder for PostgreSQL
type DatabaseRepoImpl ¶
type DatabaseRepoImpl struct {
*CoreRepoImpl
*DDLRepoImpl
*DMLRepoImpl
*BulkRepoImpl
*RelationshipRepoImpl
*PerformanceRepoImpl
*MigrationRepoImpl
}
DatabaseRepoImpl is the composite implementation that embeds all repository interfaces
func (*DatabaseRepoImpl) AsBulkRepo ¶
func (dr *DatabaseRepoImpl) AsBulkRepo() interfaces.BulkRepo
func (*DatabaseRepoImpl) AsCoreRepo ¶
func (dr *DatabaseRepoImpl) AsCoreRepo() interfaces.CoreRepo
Convenience methods to satisfy specific interfaces if needed
func (*DatabaseRepoImpl) AsDDLRepo ¶
func (dr *DatabaseRepoImpl) AsDDLRepo() interfaces.DDLRepo
func (*DatabaseRepoImpl) AsDMLRepo ¶
func (dr *DatabaseRepoImpl) AsDMLRepo() interfaces.DMLRepo
func (*DatabaseRepoImpl) AsMigrationRepo ¶
func (dr *DatabaseRepoImpl) AsMigrationRepo() interfaces.MigrationRepo
func (*DatabaseRepoImpl) AsPerformanceRepo ¶
func (dr *DatabaseRepoImpl) AsPerformanceRepo() interfaces.PerformanceRepo
func (*DatabaseRepoImpl) AsRelationshipRepo ¶
func (dr *DatabaseRepoImpl) AsRelationshipRepo() interfaces.RelationshipRepo
type MigrationRepoImpl ¶
type MigrationRepoImpl struct {
// contains filtered or unexported fields
}
MigrationRepoImpl implements MigrationRepo interface
func NewMigrationRepo ¶
func NewMigrationRepo(db *PostgresDbService) *MigrationRepoImpl
func (*MigrationRepoImpl) GetMigrationHistory ¶
func (m *MigrationRepoImpl) GetMigrationHistory() ([]map[string]interface{}, error)
GetMigrationHistory retrieves migration history
func (*MigrationRepoImpl) RecordMigration ¶
func (m *MigrationRepoImpl) RecordMigration(name, sql, checksum string) error
RecordMigration records a migration execution
type PerformanceRepoImpl ¶
type PerformanceRepoImpl struct {
// contains filtered or unexported fields
}
PerformanceRepoImpl implements PerformanceRepo interface
func NewPerformanceRepo ¶
func NewPerformanceRepo(db *PostgresDbService) *PerformanceRepoImpl
func (*PerformanceRepoImpl) AnalyzeQuery ¶
func (p *PerformanceRepoImpl) AnalyzeQuery(query string) ([]string, error)
AnalyzeQuery provides query optimization suggestions
func (*PerformanceRepoImpl) CreateIndex ¶
func (p *PerformanceRepoImpl) CreateIndex(tableName, indexName, columns string) error
CreateIndex creates an index on a table
func (*PerformanceRepoImpl) GetPerformanceMetrics ¶
func (p *PerformanceRepoImpl) GetPerformanceMetrics() (map[string]interface{}, error)
GetPerformanceMetrics returns performance metrics
type PostgresConnectorImpl ¶
type PostgresConnectorImpl struct {
MaxOpenConns int
MaxIdleConns int
ConnMaxLifetime time.Duration
}
PostgresConnectorImpl handles PostgreSQL connection creation
func (*PostgresConnectorImpl) Connect ¶
func (pc *PostgresConnectorImpl) Connect(dsn string) (interfaces.DB, error)
Connect establishes a PostgreSQL connection using the provided DSN
type PostgresDSNBuilder ¶
type PostgresDSNBuilder struct{}
PostgresDSNBuilder builds PostgreSQL Data Source Names with validation
func (*PostgresDSNBuilder) BuildDSN ¶
func (pb *PostgresDSNBuilder) BuildDSN(cfg *config.DatabaseConfig) (string, error)
BuildDSN constructs a PostgreSQL connection string with validation
type PostgresDbService ¶
type PostgresDbService struct {
// contains filtered or unexported fields
}
func NewPostgresDbServiceInstance ¶
func NewPostgresDbServiceInstance(db interfaces.DB) *PostgresDbService
NewPostgresDbServiceInstance creates a new PostgreSQL database service instance
func (*PostgresDbService) AddField ¶
func (postgresDbService *PostgresDbService) AddField(collection string, req models.AddColumnRequest) error
func (*PostgresDbService) AlterCollection ¶
func (postgresDbService *PostgresDbService) AlterCollection(collection string, req models.AlterTableRequest) error
func (*PostgresDbService) AnalyzeQuery ¶
func (postgresDbService *PostgresDbService) AnalyzeQuery(query string) ([]string, error)
AnalyzeQuery provides query optimization suggestions for PostgreSQL
func (*PostgresDbService) BuildAdvancedQuery ¶
func (postgresDbService *PostgresDbService) BuildAdvancedQuery(tableName string, params models.QueryParams) (string, []interface{})
func (*PostgresDbService) BuildAggregateParts ¶
func (postgresDbService *PostgresDbService) BuildAggregateParts(aggregates []models.AggregateFunction) []string
BuildAggregateParts builds the aggregate function parts of SELECT clause
func (*PostgresDbService) BuildAnyCondition ¶
func (postgresDbService *PostgresDbService) BuildAnyCondition(filter models.QueryFilter, argCounter int) (string, []interface{}, int)
BuildAnyCondition builds conditions for ANY operator
func (*PostgresDbService) BuildColumnDefinitions ¶
func (postgresDbService *PostgresDbService) BuildColumnDefinitions(columns []models.ColumnDefinition) []string
BuildColumnDefinitions builds SQL column definitions from ColumnDefinition slice
func (*PostgresDbService) BuildComplexFilter ¶
func (postgresDbService *PostgresDbService) BuildComplexFilter(filter models.ComplexFilter, argCounter int) (string, []interface{}, int)
func (*PostgresDbService) BuildFilterCondition ¶
func (postgresDbService *PostgresDbService) BuildFilterCondition(filter models.QueryFilter, argCounter int) (string, []interface{}, int)
func (*PostgresDbService) BuildForeignKeyDefinitions ¶
func (postgresDbService *PostgresDbService) BuildForeignKeyDefinitions(foreignKeys []models.ForeignKeyDef) []string
BuildForeignKeyDefinitions builds SQL foreign key constraint definitions
func (*PostgresDbService) BuildGroupByClause ¶
func (postgresDbService *PostgresDbService) BuildGroupByClause(groupBy []string) string
BuildGroupByClause builds the GROUP BY clause
func (*PostgresDbService) BuildHavingClause ¶
func (postgresDbService *PostgresDbService) BuildHavingClause(having []models.QueryFilter, argCounter int) (string, []interface{}, int)
BuildHavingClause builds the HAVING clause
func (*PostgresDbService) BuildInCondition ¶
func (postgresDbService *PostgresDbService) BuildInCondition(filter models.QueryFilter, useNot bool, argCounter int) (string, []interface{}, int)
BuildInCondition builds conditions for IN/NOT IN operators
func (*PostgresDbService) BuildJoinClause ¶
func (postgresDbService *PostgresDbService) BuildJoinClause(joins []models.JoinClause) string
BuildJoinClause builds the JOIN clauses
func (*PostgresDbService) BuildLimitOffsetClause ¶
func (postgresDbService *PostgresDbService) BuildLimitOffsetClause(limit, offset *int, argCounter int) (string, []interface{})
BuildLimitOffsetClause builds the LIMIT and OFFSET clauses
func (*PostgresDbService) BuildNullCondition ¶
func (postgresDbService *PostgresDbService) BuildNullCondition(filter models.QueryFilter, useNot bool, argCounter int) (string, []interface{}, int)
BuildNullCondition builds conditions for IS NULL/IS NOT NULL operators
func (*PostgresDbService) BuildOrderByClause ¶
func (postgresDbService *PostgresDbService) BuildOrderByClause(orderBy []string) string
BuildOrderByClause builds the ORDER BY clause
func (*PostgresDbService) BuildSelectClause ¶
func (postgresDbService *PostgresDbService) BuildSelectClause(params models.QueryParams) (string, []interface{}, int)
BuildSelectClause builds the SELECT clause with aggregations and column selection
func (*PostgresDbService) BuildSelectColumnParts ¶
func (postgresDbService *PostgresDbService) BuildSelectColumnParts(selectCols []string) []string
BuildSelectColumnParts builds the column selection parts of SELECT clause
func (*PostgresDbService) BuildSimpleCondition ¶
func (postgresDbService *PostgresDbService) BuildSimpleCondition(filter models.QueryFilter, operator string, argCounter int) (string, []interface{}, int)
BuildSimpleCondition builds conditions for simple operators (=, !=, <, >, etc.)
func (*PostgresDbService) BuildWhereClause ¶
func (postgresDbService *PostgresDbService) BuildWhereClause(params models.QueryParams, argCounter int) (string, []interface{}, int)
BuildWhereClause builds the WHERE clause with complex filters, simple filters, range queries, and full-text search
func (*PostgresDbService) BulkDelete ¶
func (postgresDbService *PostgresDbService) BulkDelete(tableName string, ids []interface{}, idColumn string) (int64, error)
BulkDelete implements interfaces.DatabaseRepo.
func (*PostgresDbService) BulkInsert ¶
func (postgresDbService *PostgresDbService) BulkInsert(tableName string, records []map[string]interface{}) ([]map[string]interface{}, error)
BulkInsert implements interfaces.DatabaseRepo.
func (*PostgresDbService) BulkUpdate ¶
func (postgresDbService *PostgresDbService) BulkUpdate(tableName string, updates []map[string]interface{}, whereColumn string) (int64, error)
BulkUpdate implements interfaces.DatabaseRepo.
func (*PostgresDbService) CheckTableExists ¶
func (postgresDbService *PostgresDbService) CheckTableExists(tableName string) (bool, error)
CheckTableExists checks if a table exists
func (*PostgresDbService) ConvertComplexArray ¶
func (postgresDbService *PostgresDbService) ConvertComplexArray(val interface{}) interface{}
ConvertComplexArray converts complex slice types to PostgreSQL arrays
func (*PostgresDbService) ConvertPrimitiveArray ¶
func (postgresDbService *PostgresDbService) ConvertPrimitiveArray(val interface{}) interface{}
ConvertPrimitiveArray converts primitive slice types to PostgreSQL arrays
func (*PostgresDbService) CreateCollection ¶
func (postgresDbService *PostgresDbService) CreateCollection(req models.CreateTableRequest) error
func (*PostgresDbService) CreateForeignKeyConstraint ¶
func (r *PostgresDbService) CreateForeignKeyConstraint(relationship *models.RelationshipDefinition) error
func (*PostgresDbService) CreateIndex ¶
func (postgresDbService *PostgresDbService) CreateIndex(tableName, indexName, columns string) error
CreateIndex creates an index on a table
func (*PostgresDbService) CreateIndexFromDefinition ¶
func (postgresDbService *PostgresDbService) CreateIndexFromDefinition(tableName string, idx models.IndexDefinition) error
func (*PostgresDbService) CreateJoinTable ¶
func (r *PostgresDbService) CreateJoinTable(relationship *models.RelationshipDefinition, joinTable models.CreateJoinTableRequest) error
func (*PostgresDbService) Delete ¶
func (postgresDbService *PostgresDbService) Delete(collection string, id any) error
func (*PostgresDbService) DeleteByColumns ¶
func (postgresDbService *PostgresDbService) DeleteByColumns(collection string, where models.ComplexFilter) (int64, error)
DeleteByColumns deletes rows matching the provided column criteria. `where` must contain at least one filter to avoid accidental full-table deletes. Returns rows affected.
func (*PostgresDbService) DropColumn ¶
func (postgresDbService *PostgresDbService) DropColumn(tableName string, req models.DropColumnRequest) error
func (*PostgresDbService) DropJoinTable ¶
func (r *PostgresDbService) DropJoinTable(tableName string) error
func (*PostgresDbService) DropRelationshipConstraints ¶
func (r *PostgresDbService) DropRelationshipConstraints(relationship *models.RelationshipDefinition) error
func (*PostgresDbService) ExecuteFunction ¶
func (*PostgresDbService) ExecuteQuery ¶
func (postgresDbService *PostgresDbService) ExecuteQuery(name string, params models.QueryParams) (any, error)
func (*PostgresDbService) ExecuteRawSQL ¶
func (postgresDbService *PostgresDbService) ExecuteRawSQL(ctx context.Context, sql string) error
ExecuteRawSQL executes raw SQL statements
func (*PostgresDbService) ForeignKeyConstraintExists ¶
func (r *PostgresDbService) ForeignKeyConstraintExists(tableName string, constraintName string) (bool, error)
func (*PostgresDbService) GetMigrationHistory ¶
func (postgresDbService *PostgresDbService) GetMigrationHistory() ([]map[string]interface{}, error)
GetMigrationHistory retrieves migration history
func (*PostgresDbService) GetPerformanceMetrics ¶
func (postgresDbService *PostgresDbService) GetPerformanceMetrics() (map[string]interface{}, error)
GetPerformanceMetrics returns PostgreSQL-specific performance metrics
func (*PostgresDbService) GetRelationshipData ¶
func (r *PostgresDbService) GetRelationshipData( ctx context.Context, relationship *models.RelationshipDefinition, sourceID string, params models.QueryParams, ) ([]map[string]interface{}, error)
func (*PostgresDbService) IsValidAggregateFunction ¶
func (postgresDbService *PostgresDbService) IsValidAggregateFunction(funcName string) bool
IsValidAggregateFunction checks if the aggregate function is allowed
func (*PostgresDbService) ListCollections ¶
func (postgresDbService *PostgresDbService) ListCollections(schema string) ([]models.Table, error)
func (*PostgresDbService) ModifyColumn ¶
func (postgresDbService *PostgresDbService) ModifyColumn(tableName string, req models.ModifyColumnRequest) error
func (*PostgresDbService) ParseRow ¶
func (s *PostgresDbService) ParseRow(columns []string, rawValues []interface{}) map[string]interface{}
func (*PostgresDbService) Ping ¶
func (postgresDbService *PostgresDbService) Ping() (bool, error)
func (*PostgresDbService) RecordMigration ¶
func (postgresDbService *PostgresDbService) RecordMigration(name, sql, checksum string) error
RecordMigration records a migration execution
func (*PostgresDbService) RemoveManyToManyRelations ¶
func (r *PostgresDbService) RemoveManyToManyRelations(relationship *models.RelationshipDefinition, sourceID interface{}, targetIDs []interface{}) (int, error)
func (*PostgresDbService) RemoveOneToManyRelations ¶
func (r *PostgresDbService) RemoveOneToManyRelations(relationship *models.RelationshipDefinition, sourceID interface{}, targetIDs []interface{}) (int, error)
func (*PostgresDbService) RenameColumn ¶
func (postgresDbService *PostgresDbService) RenameColumn(tableName string, req models.RenameColumnRequest) error
func (*PostgresDbService) SetManyToManyRelations ¶
func (r *PostgresDbService) SetManyToManyRelations(relationship *models.RelationshipDefinition, sourceID interface{}, targetIDs []interface{}, data map[string]interface{}) ([]map[string]interface{}, error)
func (*PostgresDbService) SetOneToManyRelation ¶
func (r *PostgresDbService) SetOneToManyRelation(relationship *models.RelationshipDefinition, sourceID interface{}, targetIDs []interface{}) error
func (*PostgresDbService) SetOneToManyRelations ¶
func (r *PostgresDbService) SetOneToManyRelations(relationship *models.RelationshipDefinition, sourceID interface{}, targetIDs []interface{}) error
func (*PostgresDbService) SetOneToOneRelation ¶
func (r *PostgresDbService) SetOneToOneRelation(relationship *models.RelationshipDefinition, sourceID interface{}, targetID interface{}) error
func (*PostgresDbService) ToInterfaceSlice ¶
func (postgresDbService *PostgresDbService) ToInterfaceSlice(v interface{}) ([]interface{}, bool)
func (*PostgresDbService) UpdateByColumns ¶
func (postgresDbService *PostgresDbService) UpdateByColumns(collection string, where models.ComplexFilter, data map[string]any) (any, error)
UpdateByColumns updates specified columns for rows matching the provided column criteria. `where` may contain one or more column=value pairs; at least one is required to avoid full-table updates.
func (*PostgresDbService) Upsert ¶
func (postgresDbService *PostgresDbService) Upsert(tableName string, data map[string]interface{}, conflictColumns []string, updateColumns []string) (map[string]interface{}, error)
Upsert implements interfaces.DatabaseRepo.
func (*PostgresDbService) ValidateCreateTableRequest ¶
func (postgresDbService *PostgresDbService) ValidateCreateTableRequest(req models.CreateTableRequest) error
ValidateCreateTableRequest validates all components of a CreateTableRequest
type RelationshipRepoImpl ¶
type RelationshipRepoImpl struct {
// contains filtered or unexported fields
}
RelationshipRepoImpl implements RelationshipRepo interface
func NewRelationshipRepo ¶
func NewRelationshipRepo(db *PostgresDbService) *RelationshipRepoImpl
func (*RelationshipRepoImpl) CreateForeignKeyConstraint ¶
func (r *RelationshipRepoImpl) CreateForeignKeyConstraint(relationship *models.RelationshipDefinition) error
CreateForeignKeyConstraint creates a foreign key constraint
func (*RelationshipRepoImpl) CreateJoinTable ¶
func (r *RelationshipRepoImpl) CreateJoinTable(relationship *models.RelationshipDefinition, joinTable models.CreateJoinTableRequest) error
CreateJoinTable creates a join table for many-to-many relationships
func (*RelationshipRepoImpl) DropJoinTable ¶
func (r *RelationshipRepoImpl) DropJoinTable(tableName string) error
DropJoinTable drops a join table
func (*RelationshipRepoImpl) DropRelationshipConstraints ¶
func (r *RelationshipRepoImpl) DropRelationshipConstraints(relationship *models.RelationshipDefinition) error
DropRelationshipConstraints drops relationship constraints
func (*RelationshipRepoImpl) GetRelationshipData ¶
func (r *RelationshipRepoImpl) GetRelationshipData(ctx context.Context, relationship *models.RelationshipDefinition, sourceID string, params models.QueryParams) ([]map[string]interface{}, error)
GetRelationshipData retrieves relationship data
func (*RelationshipRepoImpl) RemoveManyToManyRelations ¶
func (r *RelationshipRepoImpl) RemoveManyToManyRelations(relationship *models.RelationshipDefinition, sourceID interface{}, targetIDs []interface{}) (int, error)
RemoveManyToManyRelations removes many-to-many relationships
func (*RelationshipRepoImpl) RemoveOneToManyRelations ¶
func (r *RelationshipRepoImpl) RemoveOneToManyRelations(relationship *models.RelationshipDefinition, sourceID interface{}, targetIDs []interface{}) (int, error)
RemoveOneToManyRelations removes one-to-many relationships
func (*RelationshipRepoImpl) SetManyToManyRelations ¶
func (r *RelationshipRepoImpl) SetManyToManyRelations(relationship *models.RelationshipDefinition, sourceID interface{}, targetIDs []interface{}, data map[string]interface{}) ([]map[string]interface{}, error)
SetManyToManyRelations sets many-to-many relationships
func (*RelationshipRepoImpl) SetOneToManyRelation ¶
func (r *RelationshipRepoImpl) SetOneToManyRelation(relationship *models.RelationshipDefinition, sourceID interface{}, targetIDs []interface{}) error
SetOneToManyRelation sets a one-to-many relationship
func (*RelationshipRepoImpl) SetOneToManyRelations ¶
func (r *RelationshipRepoImpl) SetOneToManyRelations(relationship *models.RelationshipDefinition, sourceID interface{}, targetIDs []interface{}) error
SetOneToManyRelations sets multiple one-to-many relationships
func (*RelationshipRepoImpl) SetOneToOneRelation ¶
func (r *RelationshipRepoImpl) SetOneToOneRelation(relationship *models.RelationshipDefinition, sourceID interface{}, targetID interface{}) error
SetOneToOneRelation sets a one-to-one relationship