postgres

package
v0.0.0-...-328caaa Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var OpenDB = sql.Open

allow tests to stub sql.Open/Ping

View Source
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 MapsToJSONStrings(arr []map[string]interface{}) ([]string, error)

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 ParseUUID

func ParseUUID(v interface{}) interface{}

func ParseValue

func ParseValue(v interface{}) interface{}

func SplitQualifiedName

func SplitQualifiedName(qualifiedName string) ([]string, error)

SplitQualifiedName splits a qualified table name on dots while respecting quoted identifiers

func TryParseJSON

func TryParseJSON(b []byte) (interface{}, bool)

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

func ValidateAndQuoteColumnList(columns []string) ([]string, error)

ValidateAndQuoteColumnList validates and safely quotes a list of column names Used for SELECT, GROUP BY, and similar clauses that accept column lists

func ValidateAndQuoteOrderByList

func ValidateAndQuoteOrderByList(orderByList []string) ([]string, error)

ValidateAndQuoteOrderByList validates and safely quotes ORDER BY columns Handles formats like "column ASC", "column DESC", "column"

func ValidateColumnName

func ValidateColumnName(name string) error

ValidateColumnName ensures column name is safe for SQL

func ValidateOperator

func ValidateOperator(op string) error

ValidateOperator ensures operator is in the whitelist and safe to use

func ValidateQualifiedNameParts

func ValidateQualifiedNameParts(parts []string, qualifiedName string) error

ValidateQualifiedNameParts validates the split parts of a qualified name

func ValidateQualifiedTableName

func ValidateQualifiedTableName(qualifiedName string) error

ValidateQualifiedTableName ensures qualified table name (schema.table) is safe for SQL Supports formats like "table", "schema.table", "schema"."table", or "public"."relations"

func ValidateTableName

func ValidateTableName(name string) error

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

func (*BulkRepoImpl) Upsert

func (b *BulkRepoImpl) Upsert(tableName string, data map[string]interface{}, conflictColumns, updateColumns []string) (map[string]interface{}, error)

Upsert performs insert or update based on conflict

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

func NewPostgresConnectorWithConfig

func NewPostgresConnectorWithConfig(maxOpen, maxIdle int, maxLifetime time.Duration) Connector

NewPostgresConnectorWithConfig creates a new PostgreSQL connector with custom 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) Insert

func (d *DMLRepoImpl) Insert(collection string, data map[string]any) (any, error)

Insert inserts a record into a collection

func (*DMLRepoImpl) Update

func (d *DMLRepoImpl) Update(collection string, id any, data map[string]any) (any, error)

Update updates a record in a collection

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

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 (r *PostgresDbService) ExecuteFunction(ctx context.Context, name string, args map[string]interface{}) (any, error)

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) Insert

func (postgresDbService *PostgresDbService) Insert(collection string, data map[string]any) (any, 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) Update

func (postgresDbService *PostgresDbService) Update(collection string, id any, data map[string]any) (any, error)

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

Jump to

Keyboard shortcuts

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