pgsql

package
v0.27.2 Latest Latest
Warning

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

Go to latest
Published: May 1, 2023 License: MIT Imports: 17 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.DbHelper
	// 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

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

func (m *DB) Analyze(options Options)

func (*DB) Associate

func (m *DB) Associate(ctx context.Context,
	table string,
	column string,
	pk interface{},
	_ string,
	relatedColumn string,
	relatedPks interface{})

Associate sets up the many-many association pointing from the given table and column to another table and column. table is the name of the association table. column is the name of the column in the association table that contains the pk for the record we are associating. pk is the value of the primary key. relatedTable is the table the association is pointing to. relatedColumn is the column in the association table that points to the relatedTable's pk. relatedPks are the new primary keys in the relatedTable we are associating.

func (*DB) Delete

func (m *DB) Delete(ctx context.Context, table string, pkName string, pkValue interface{})

Delete deletes the indicated record from the 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]interface{}) string

Insert inserts the given data as a new record in the database. It returns the record id of the new record.

func (*DB) Model

func (m *DB) Model() *db.Model

Model returns the database description object

func (*DB) NewBuilder

func (m *DB) NewBuilder(ctx context.Context) QueryBuilderI

NewBuilder returns a new query builder to build a query that will be processed by the database.

func (*DB) OperationSql

func (m *DB) OperationSql(op Operator, 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) Update

func (m *DB) Update(ctx context.Context,
	table string,
	fields map[string]any,
	pkName string,
	pkValue any)

Update sets specific fields of a record that already exists in the database to the given data.

type Options

type Options struct {
	// EnumTableSuffix is the suffix in the name of a table that tells GoRADD to treat
	// the table as a enum table. Defaults to "_enum" if not set.
	EnumTableSuffix string
	// AssociationTableSuffix is the suffix in the name of a table that tells GoRADD to
	// treat the table as an association table. Defaults to "_assn".
	AssociationTableSuffix string
	// ForeignKeySuffix is the suffix to strip off the ends of names of foreign keys when converting
	// them to internal names. For example, if the suffix is "_id", and a column named
	// manager_id a "project" table is a foreign key to a "person" table, then GoRADD will
	// create "Person" objects with the name "Manager" inside the "Project" object.
	// A suffix is required since it will also create a "ManagerID" member variable, and
	// without the suffix the two values will have the same name.
	// The default is "_id".
	ForeignKeySuffix string
	// UseQualifiedNames will force goradd to prepend schema names in front of table names.
	// This is required to clear up ambiguity when different schemas have the same table name.
	// Postgres documentation discourages the use of repeated table names in different schemas.
	// If you know you do not have repeats, you can leave this option false.
	UseQualifiedNames bool
	// Schemas lets you specify which specific schemas you want to select.
	// If no schemas are specified, then all available schemas will be used.
	Schemas []string
}

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns default database analysis options for MySQL databases.

Jump to

Keyboard shortcuts

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