Documentation
¶
Index ¶
- func OverrideConfigSettings(config *pgx.ConnConfig, jsonContent map[string]interface{})
- type DB
- func (m *DB) DestroySchema(ctx context.Context, s schema.Database) error
- func (m *DB) ExtractSchema(options map[string]any) schema2.Database
- func (m *DB) FormatArgument(n int) string
- func (m *DB) Insert(ctx context.Context, table string, fields map[string]any, autoPkKey string) error
- func (m *DB) OperationSql(op Operator, operands []Node, operandStrings []string) (sql string)
- func (m *DB) QuoteIdentifier(v string) string
- func (m *DB) SupportsForUpdate() bool
- func (m *DB) TableDefinitionSql(d *schema2.Database, table *schema2.Table) (tableSql string, extraClauses []string)
- func (m *DB) Update(ctx context.Context, table string, primaryKey map[string]any, ...) (err error)
- func (m *DB) WithConstraintsOff(ctx context.Context, f func(ctx context.Context) error) (err error)
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 ¶
DB is the goradd driver for postgresql databases.
func NewDB ¶
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 ¶
DestroySchema removes all tables and data from the tables found in the given schema s.
func (*DB) FormatArgument ¶
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 ¶
OperationSql provides Postgres specific SQL for certain operators.
func (*DB) QuoteIdentifier ¶
QuoteIdentifier surrounds the given identifier with quote characters appropriate for Postgres
func (*DB) SupportsForUpdate ¶
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 ¶
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.