pgsql

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OverrideConfigSettings

func OverrideConfigSettings(config *pgx.ConnConfig, jsonContent map[string]interface{})

OverrideConfigSettings will use a map read in from a json file to modify the given config settings

Types

type DB

type DB struct {
	sql2.Base
	// contains filtered or unexported fields
}

DB is the goradd driver for postgresql databases.

func NewDB

func NewDB(dbKey string,
	connectionString string,
	config *pgx.ConnConfig) (*DB, error)

NewDB returns a new Postgresql DB database object based on the pgx driver that you can add to the datastore. If connectionString is set, it will be used to create the configuration. Otherwise, use a config setting. Using a configSetting can potentially give you access to the underlying pgx database for advanced operations.

The postgres driver specifies that you must use ParseConfig to create the initial configuration, although that can be sent a blank string to gather initial values from environment variables. You can then change items in the configuration structure. For example:

config,_ := pgx.ParseConfig(connectionString)
config.Password = "mysecret"
db := pgsql.NewDB(key, "", config)

func (*DB) DestroySchema

func (m *DB) DestroySchema(ctx context.Context, s schema.Database) error

DestroySchema removes all tables and data from the tables found in the given schema s.

func (*DB) ExtractSchema

func (m *DB) ExtractSchema(options map[string]any) schema2.Database

func (*DB) FormatArgument

func (m *DB) FormatArgument(n int) string

FormatArgument formats the given argument number for embedding in a SQL statement.

func (*DB) Insert

func (m *DB) Insert(ctx context.Context, table string, fields map[string]any, autoPkKey string) error

Insert inserts the given data as a new record in the database. If fields contains a value for an auto-generated primary key, Insert will synchronize postgres to make sure it will not auto generate another key that matches the manually set primary key. Table can include a schema name separated with a period.

func (*DB) OperationSql

func (m *DB) OperationSql(op Operator, operands []Node, operandStrings []string) (sql string)

OperationSql provides Postgres specific SQL for certain operators.

func (*DB) QuoteIdentifier

func (m *DB) QuoteIdentifier(v string) string

QuoteIdentifier surrounds the given identifier with quote characters appropriate for Postgres

func (*DB) SupportsForUpdate

func (m *DB) SupportsForUpdate() bool

func (*DB) TableDefinitionSql

func (m *DB) TableDefinitionSql(d *schema2.Database, table *schema2.Table) (tableSql string, extraClauses []string)

TableDefinitionSql will return the sql needed to create the table. This can include clauses separated by semicolons that add additional capabilities to the table.

func (*DB) Update

func (m *DB) Update(ctx context.Context,
	table string,
	primaryKey map[string]any,
	changes map[string]any,
	optLockFieldName string,
	optLockFieldValue int64,
) (err error)

Update sets specific fields of a single record that exists in the database. optLockFieldName is the name of a version field that will implement an optimistic locking check while doing the update. If optLockFieldName is provided:

  • That field will be used to limit the update,
  • That field will be updated with a new version
  • If the record was deleted, or if the record was previously updated, an OptimisticLockError will be returned. You will need to query further to determine if the record still exists.

Otherwise, if optLockFieldName is blank, and the record we are attempting to change does not exist, the database will not be altered, and no error will be returned.

func (*DB) WithConstraintsOff

func (m *DB) WithConstraintsOff(ctx context.Context, f func(ctx context.Context) error) (err error)

WithConstraintsOff makes sure operations in f occur with foreign key constraints turned off. Postgres (and many other drivers), require that this happens within a transaction.

Jump to

Keyboard shortcuts

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