Help us shape the future of Go! Take the 2026 Go Developer Survey

postgresql

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPostgreSQLMigrator

func NewPostgreSQLMigrator(db *sql.DB, postgresqlDB *PostgreSQLDB) types.DatabaseMigrator

NewPostgreSQLMigrator creates a new PostgreSQL migrator that implements types.DatabaseMigrator

Types

type PostgreSQLCapabilities

type PostgreSQLCapabilities struct{}

PostgreSQLCapabilities implements types.DriverCapabilities for PostgreSQL

func NewPostgreSQLCapabilities

func NewPostgreSQLCapabilities() *PostgreSQLCapabilities

NewPostgreSQLCapabilities creates new PostgreSQL capabilities

func (*PostgreSQLCapabilities) GetBooleanLiteral

func (c *PostgreSQLCapabilities) GetBooleanLiteral(value bool) string

func (*PostgreSQLCapabilities) GetDriverType

func (c *PostgreSQLCapabilities) GetDriverType() types.DriverType

func (*PostgreSQLCapabilities) GetNullsOrderingSQL

func (c *PostgreSQLCapabilities) GetNullsOrderingSQL(direction types.Order, nullsFirst bool) string

func (*PostgreSQLCapabilities) GetPlaceholder

func (c *PostgreSQLCapabilities) GetPlaceholder(index int) string

func (*PostgreSQLCapabilities) GetSupportedSchemes

func (c *PostgreSQLCapabilities) GetSupportedSchemes() []string

func (*PostgreSQLCapabilities) IsNoSQL

func (c *PostgreSQLCapabilities) IsNoSQL() bool

func (*PostgreSQLCapabilities) IsSystemIndex

func (c *PostgreSQLCapabilities) IsSystemIndex(indexName string) bool

func (*PostgreSQLCapabilities) IsSystemTable

func (c *PostgreSQLCapabilities) IsSystemTable(tableName string) bool

func (*PostgreSQLCapabilities) NeedsTypeConversion

func (c *PostgreSQLCapabilities) NeedsTypeConversion() bool

func (*PostgreSQLCapabilities) QuoteIdentifier

func (c *PostgreSQLCapabilities) QuoteIdentifier(name string) string

func (*PostgreSQLCapabilities) RequiresLimitForOffset

func (c *PostgreSQLCapabilities) RequiresLimitForOffset() bool

func (*PostgreSQLCapabilities) SupportsAggregationPipeline

func (c *PostgreSQLCapabilities) SupportsAggregationPipeline() bool

func (*PostgreSQLCapabilities) SupportsArrayFields

func (c *PostgreSQLCapabilities) SupportsArrayFields() bool

func (*PostgreSQLCapabilities) SupportsDefaultValues

func (c *PostgreSQLCapabilities) SupportsDefaultValues() bool

func (*PostgreSQLCapabilities) SupportsDistinctOn

func (c *PostgreSQLCapabilities) SupportsDistinctOn() bool

func (*PostgreSQLCapabilities) SupportsNestedDocuments

func (c *PostgreSQLCapabilities) SupportsNestedDocuments() bool

func (*PostgreSQLCapabilities) SupportsReturning

func (c *PostgreSQLCapabilities) SupportsReturning() bool

func (*PostgreSQLCapabilities) SupportsTransactions

func (c *PostgreSQLCapabilities) SupportsTransactions() bool

type PostgreSQLDB

type PostgreSQLDB struct {
	*base.Driver
	// contains filtered or unexported fields
}

PostgreSQLDB implements the Database interface for PostgreSQL

func NewPostgreSQLDB

func NewPostgreSQLDB(nativeURI string) (*PostgreSQLDB, error)

NewPostgreSQLDB creates a new PostgreSQL database instance The uri parameter should be a native PostgreSQL DSN (e.g., "host=localhost port=5432 user=user dbname=db")

func (*PostgreSQLDB) Begin

Begin starts a new transaction

func (*PostgreSQLDB) Connect

func (p *PostgreSQLDB) Connect(ctx context.Context) error

Connect establishes a connection to the PostgreSQL database

func (*PostgreSQLDB) CreateModel

func (p *PostgreSQLDB) CreateModel(ctx context.Context, modelName string) error

CreateModel creates a table from the registered schema

func (*PostgreSQLDB) DropModel

func (p *PostgreSQLDB) DropModel(ctx context.Context, modelName string) error

DropModel drops a table

func (*PostgreSQLDB) Exec

func (p *PostgreSQLDB) Exec(query string, args ...any) (sql.Result, error)

Exec executes a raw SQL query

func (*PostgreSQLDB) GetBooleanLiteral

func (p *PostgreSQLDB) GetBooleanLiteral(value bool) string

GetBooleanLiteral returns PostgreSQL-specific boolean literal

func (*PostgreSQLDB) GetCapabilities

func (p *PostgreSQLDB) GetCapabilities() types.DriverCapabilities

GetCapabilities returns driver capabilities

func (*PostgreSQLDB) GetDriverType

func (p *PostgreSQLDB) GetDriverType() string

GetDriverType returns the database driver type

func (*PostgreSQLDB) GetMigrator

func (p *PostgreSQLDB) GetMigrator() types.DatabaseMigrator

GetMigrator returns the migrator for this database

func (*PostgreSQLDB) Model

func (p *PostgreSQLDB) Model(modelName string) types.ModelQuery

Model creates a new model query

func (*PostgreSQLDB) Query

func (p *PostgreSQLDB) Query(query string, args ...any) (*sql.Rows, error)

Query executes a raw SQL query and returns rows

func (*PostgreSQLDB) QueryRow

func (p *PostgreSQLDB) QueryRow(query string, args ...any) *sql.Row

QueryRow executes a raw SQL query and returns a single row

func (*PostgreSQLDB) Raw

func (p *PostgreSQLDB) Raw(query string, args ...any) types.RawQuery

Raw creates a raw query

func (*PostgreSQLDB) SyncSchemas

func (p *PostgreSQLDB) SyncSchemas(ctx context.Context) error

SyncSchemas synchronizes all loaded schemas with the database

func (*PostgreSQLDB) Transaction

func (p *PostgreSQLDB) Transaction(ctx context.Context, fn func(tx types.Transaction) error) error

Transaction executes a function within a transaction

type PostgreSQLMigrator

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

PostgreSQLMigrator implements types.DatabaseSpecificMigrator for PostgreSQL

func (*PostgreSQLMigrator) ApplyMigration

func (m *PostgreSQLMigrator) ApplyMigration(sql string) error

ApplyMigration applies a migration SQL statement

func (*PostgreSQLMigrator) ConvertFieldToColumnInfo

func (m *PostgreSQLMigrator) ConvertFieldToColumnInfo(field schema.Field) *types.ColumnInfo

ConvertFieldToColumnInfo converts a schema field to column info

func (*PostgreSQLMigrator) FormatDefaultValue

func (m *PostgreSQLMigrator) FormatDefaultValue(value any) string

FormatDefaultValue formats a default value for PostgreSQL

func (*PostgreSQLMigrator) GenerateAddColumnSQL

func (m *PostgreSQLMigrator) GenerateAddColumnSQL(tableName string, column any) (string, error)

GenerateAddColumnSQL generates ALTER TABLE ADD COLUMN SQL

func (*PostgreSQLMigrator) GenerateColumnDefinition

func (m *PostgreSQLMigrator) GenerateColumnDefinition(field schema.Field) string

GenerateColumnDefinition generates column definition from schema field

func (*PostgreSQLMigrator) GenerateColumnDefinitionFromColumnInfo

func (m *PostgreSQLMigrator) GenerateColumnDefinitionFromColumnInfo(column types.ColumnInfo) string

GenerateColumnDefinitionFromColumnInfo generates column definition from ColumnInfo

func (*PostgreSQLMigrator) GenerateCreateIndexSQL

func (m *PostgreSQLMigrator) GenerateCreateIndexSQL(tableName, indexName string, columns []string, unique bool) string

GenerateCreateIndexSQL generates CREATE INDEX SQL

func (*PostgreSQLMigrator) GenerateCreateTableSQL

func (m *PostgreSQLMigrator) GenerateCreateTableSQL(schema *schema.Schema) (string, error)

GenerateCreateTableSQL generates CREATE TABLE SQL

func (*PostgreSQLMigrator) GenerateDropColumnSQL

func (m *PostgreSQLMigrator) GenerateDropColumnSQL(tableName, columnName string) ([]string, error)

GenerateDropColumnSQL generates ALTER TABLE DROP COLUMN SQL

func (*PostgreSQLMigrator) GenerateDropIndexSQL

func (m *PostgreSQLMigrator) GenerateDropIndexSQL(indexName string) string

GenerateDropIndexSQL generates DROP INDEX SQL

func (*PostgreSQLMigrator) GenerateDropTableSQL

func (m *PostgreSQLMigrator) GenerateDropTableSQL(tableName string) string

GenerateDropTableSQL generates DROP TABLE SQL

func (*PostgreSQLMigrator) GenerateModifyColumnSQL

func (m *PostgreSQLMigrator) GenerateModifyColumnSQL(change types.ColumnChange) ([]string, error)

GenerateModifyColumnSQL generates ALTER TABLE ALTER COLUMN SQL for PostgreSQL

func (*PostgreSQLMigrator) GetDatabaseType

func (m *PostgreSQLMigrator) GetDatabaseType() string

GetDatabaseType returns the database type

func (*PostgreSQLMigrator) GetTableInfo

func (m *PostgreSQLMigrator) GetTableInfo(tableName string) (*types.TableInfo, error)

GetTableInfo returns information about a specific table

func (*PostgreSQLMigrator) GetTables

func (m *PostgreSQLMigrator) GetTables() ([]string, error)

GetTables returns all table names in the database

func (*PostgreSQLMigrator) IsSystemIndex

func (m *PostgreSQLMigrator) IsSystemIndex(indexName string) bool

IsSystemIndex checks if an index is a system-generated index in PostgreSQL

func (*PostgreSQLMigrator) IsSystemTable

func (m *PostgreSQLMigrator) IsSystemTable(tableName string) bool

IsSystemTable checks if a table is a system table in PostgreSQL

func (*PostgreSQLMigrator) MapFieldType

func (m *PostgreSQLMigrator) MapFieldType(field schema.Field) string

MapFieldType maps a schema field to PostgreSQL column type

type PostgreSQLMigratorWrapper

type PostgreSQLMigratorWrapper struct {
	*base.BaseMigrator
	// contains filtered or unexported fields
}

PostgreSQLMigratorWrapper wraps PostgreSQLMigrator with BaseMigrator to implement types.DatabaseMigrator

func (*PostgreSQLMigratorWrapper) CompareSchema

func (w *PostgreSQLMigratorWrapper) CompareSchema(existingTable *types.TableInfo, desiredSchema any) (*types.MigrationPlan, error)

CompareSchema wraps the BaseMigrator's CompareSchema to match the DatabaseMigrator interface

func (*PostgreSQLMigratorWrapper) GenerateAddColumnSQL

func (w *PostgreSQLMigratorWrapper) GenerateAddColumnSQL(tableName string, field any) (string, error)

GenerateAddColumnSQL wraps to match the DatabaseMigrator interface

func (*PostgreSQLMigratorWrapper) GenerateCreateTableSQL

func (w *PostgreSQLMigratorWrapper) GenerateCreateTableSQL(schemaInterface any) (string, error)

GenerateCreateTableSQL wraps to match the DatabaseMigrator interface

func (*PostgreSQLMigratorWrapper) IsSystemTable

func (w *PostgreSQLMigratorWrapper) IsSystemTable(tableName string) bool

IsSystemTable delegates to the specific implementation

type PostgreSQLRawQuery

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

PostgreSQLRawQuery implements the RawQuery interface for PostgreSQL

func (*PostgreSQLRawQuery) Exec

Exec executes the query and returns the result

func (*PostgreSQLRawQuery) Find

func (q *PostgreSQLRawQuery) Find(ctx context.Context, dest any) error

Find executes the query and scans multiple rows into dest

func (*PostgreSQLRawQuery) FindOne

func (q *PostgreSQLRawQuery) FindOne(ctx context.Context, dest any) error

FindOne executes the query and scans a single row into dest

type PostgreSQLTransaction

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

PostgreSQLTransaction implements the Transaction interface for PostgreSQL

func (*PostgreSQLTransaction) Commit

func (t *PostgreSQLTransaction) Commit(ctx context.Context) error

Commit commits the transaction

func (*PostgreSQLTransaction) CreateMany

func (t *PostgreSQLTransaction) CreateMany(ctx context.Context, modelName string, data []any) (types.Result, error)

CreateMany creates multiple records within the transaction

func (*PostgreSQLTransaction) DeleteMany

func (t *PostgreSQLTransaction) DeleteMany(ctx context.Context, modelName string, condition types.Condition) (types.Result, error)

DeleteMany deletes multiple records within the transaction

func (*PostgreSQLTransaction) Model

func (t *PostgreSQLTransaction) Model(modelName string) types.ModelQuery

Model creates a model query within the transaction

func (*PostgreSQLTransaction) Raw

func (t *PostgreSQLTransaction) Raw(query string, args ...any) types.RawQuery

Raw creates a raw query within the transaction

func (*PostgreSQLTransaction) ReleaseSavepoint

func (t *PostgreSQLTransaction) ReleaseSavepoint(ctx context.Context, name string) error

ReleaseSavepoint releases the savepoint with the given name

func (*PostgreSQLTransaction) Rollback

func (t *PostgreSQLTransaction) Rollback(ctx context.Context) error

Rollback rolls back the transaction

func (*PostgreSQLTransaction) RollbackTo

func (t *PostgreSQLTransaction) RollbackTo(ctx context.Context, name string) error

RollbackTo rolls back to the savepoint with the given name

func (*PostgreSQLTransaction) Savepoint

func (t *PostgreSQLTransaction) Savepoint(ctx context.Context, name string) error

Savepoint creates a savepoint with the given name

func (*PostgreSQLTransaction) UpdateMany

func (t *PostgreSQLTransaction) UpdateMany(ctx context.Context, modelName string, condition types.Condition, data any) (types.Result, error)

UpdateMany updates multiple records within the transaction

type PostgreSQLTransactionDB

type PostgreSQLTransactionDB struct {
	*PostgreSQLDB
	// contains filtered or unexported fields
}

PostgreSQLTransactionDB wraps PostgreSQLDB for transaction context

func (*PostgreSQLTransactionDB) Begin

Begin within a transaction is not supported

func (*PostgreSQLTransactionDB) Close

func (t *PostgreSQLTransactionDB) Close() error

Close is not supported within a transaction

func (*PostgreSQLTransactionDB) Connect

func (t *PostgreSQLTransactionDB) Connect(ctx context.Context) error

Connect is not supported within a transaction

func (*PostgreSQLTransactionDB) CreateModel

func (t *PostgreSQLTransactionDB) CreateModel(ctx context.Context, modelName string) error

CreateModel is not supported within a transaction

func (*PostgreSQLTransactionDB) DropModel

func (t *PostgreSQLTransactionDB) DropModel(ctx context.Context, modelName string) error

DropModel is not supported within a transaction

func (*PostgreSQLTransactionDB) Exec

func (t *PostgreSQLTransactionDB) Exec(query string, args ...any) (sql.Result, error)

Exec executes a raw SQL statement within the transaction

func (*PostgreSQLTransactionDB) GetCapabilities

func (t *PostgreSQLTransactionDB) GetCapabilities() types.DriverCapabilities

GetCapabilities returns driver capabilities

func (*PostgreSQLTransactionDB) GetDriverType

func (t *PostgreSQLTransactionDB) GetDriverType() string

GetDriverType returns the database driver type

func (*PostgreSQLTransactionDB) GetMigrator

GetMigrator is not supported within a transaction

func (*PostgreSQLTransactionDB) GetModelSchema

func (t *PostgreSQLTransactionDB) GetModelSchema(modelName string) (*schema.Schema, error)

GetModelSchema returns the schema interface for a model

func (*PostgreSQLTransactionDB) GetModels

func (t *PostgreSQLTransactionDB) GetModels() []string

GetModels returns all registered model names

func (*PostgreSQLTransactionDB) GetSchema

func (t *PostgreSQLTransactionDB) GetSchema(modelName string) (*schema.Schema, error)

GetSchema returns the schema for a model

func (*PostgreSQLTransactionDB) LoadSchema

func (t *PostgreSQLTransactionDB) LoadSchema(ctx context.Context, schemaContent string) error

LoadSchema is not supported within a transaction

func (*PostgreSQLTransactionDB) LoadSchemaFrom

func (t *PostgreSQLTransactionDB) LoadSchemaFrom(ctx context.Context, filename string) error

LoadSchemaFrom is not supported within a transaction

func (*PostgreSQLTransactionDB) Model

func (t *PostgreSQLTransactionDB) Model(modelName string) types.ModelQuery

Model creates a model query within the transaction

func (*PostgreSQLTransactionDB) Ping

Ping is not supported within a transaction

func (*PostgreSQLTransactionDB) Query

func (t *PostgreSQLTransactionDB) Query(query string, args ...any) (*sql.Rows, error)

Query executes a raw SQL query that returns rows within the transaction

func (*PostgreSQLTransactionDB) QueryRow

func (t *PostgreSQLTransactionDB) QueryRow(query string, args ...any) *sql.Row

QueryRow executes a raw SQL query that returns a single row within the transaction

func (*PostgreSQLTransactionDB) Raw

func (t *PostgreSQLTransactionDB) Raw(query string, args ...any) types.RawQuery

Raw creates a raw query within the transaction

func (*PostgreSQLTransactionDB) RegisterSchema

func (t *PostgreSQLTransactionDB) RegisterSchema(modelName string, s *schema.Schema) error

RegisterSchema registers a schema with the database

func (*PostgreSQLTransactionDB) ResolveFieldName

func (t *PostgreSQLTransactionDB) ResolveFieldName(modelName, fieldName string) (string, error)

ResolveFieldName resolves schema field name to column name

func (*PostgreSQLTransactionDB) ResolveFieldNames

func (t *PostgreSQLTransactionDB) ResolveFieldNames(modelName string, fieldNames []string) ([]string, error)

ResolveFieldNames resolves multiple schema field names to column names

func (*PostgreSQLTransactionDB) ResolveTableName

func (t *PostgreSQLTransactionDB) ResolveTableName(modelName string) (string, error)

ResolveTableName resolves model name to table name

func (*PostgreSQLTransactionDB) SyncSchemas

func (t *PostgreSQLTransactionDB) SyncSchemas(ctx context.Context) error

SyncSchemas is not supported within a transaction

func (*PostgreSQLTransactionDB) Transaction

func (t *PostgreSQLTransactionDB) Transaction(ctx context.Context, fn func(tx types.Transaction) error) error

Transaction within a transaction is not supported

type PostgreSQLTransactionRawQuery

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

PostgreSQLTransactionRawQuery implements RawQuery for transactions

func (*PostgreSQLTransactionRawQuery) Exec

Exec executes the query within the transaction

func (*PostgreSQLTransactionRawQuery) Find

Find executes the query and scans multiple rows into dest

func (*PostgreSQLTransactionRawQuery) FindOne

func (q *PostgreSQLTransactionRawQuery) FindOne(ctx context.Context, dest any) error

FindOne executes the query and scans a single row into dest

type PostgreSQLURIParser

type PostgreSQLURIParser struct{}

PostgreSQLURIParser implements URIParser for PostgreSQL

func NewPostgreSQLURIParser

func NewPostgreSQLURIParser() *PostgreSQLURIParser

NewPostgreSQLURIParser creates a new PostgreSQL URI parser

func (*PostgreSQLURIParser) GetDriverType

func (p *PostgreSQLURIParser) GetDriverType() string

GetDriverType returns the driver type this parser is for

func (*PostgreSQLURIParser) GetSupportedSchemes

func (p *PostgreSQLURIParser) GetSupportedSchemes() []string

GetSupportedSchemes returns the URI schemes supported by this parser

func (*PostgreSQLURIParser) ParseURI

func (p *PostgreSQLURIParser) ParseURI(uri string) (string, error)

ParseURI parses a PostgreSQL connection URI and returns a PostgreSQL DSN

Jump to

Keyboard shortcuts

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