Documentation
¶
Overview ¶
Package pgsql implements gdb.Driver, which supports operations for database PostgreSQL.
Note: 1. It does not support Replace features. 2. It does not support Insert Ignore features.
Index ¶
- func New() gdb.Driver
- type Driver
- func (d *Driver) CheckLocalTypeForField(ctx context.Context, fieldType string, fieldValue any) (gdb.LocalType, error)
- func (d *Driver) ConvertValueForField(ctx context.Context, fieldType string, fieldValue any) (any, error)
- func (d *Driver) ConvertValueForLocal(ctx context.Context, fieldType string, fieldValue any) (any, error)
- func (d *Driver) DoExec(ctx context.Context, link gdb.Link, sql string, args ...any) (result sql.Result, err error)
- func (d *Driver) DoFilter(ctx context.Context, link gdb.Link, sql string, args []any) (newSql string, newArgs []any, err error)
- func (d *Driver) DoInsert(ctx context.Context, link gdb.Link, table string, list gdb.List, ...) (result sql.Result, err error)
- func (d *Driver) FormatUpsert(columns []string, list gdb.List, option gdb.DoInsertOption) (string, error)
- func (d *Driver) GetChars() (charLeft string, charRight string)
- func (d *Driver) New(core *gdb.Core, node *gdb.ConfigNode) (gdb.DB, error)
- func (d *Driver) Open(config *gdb.ConfigNode) (db *sql.DB, err error)
- func (d *Driver) OrderRandomFunction() string
- func (d *Driver) TableFields(ctx context.Context, table string, schema ...string) (fields map[string]*gdb.TableField, err error)
- func (d *Driver) Tables(ctx context.Context, schema ...string) (tables []string, err error)
- type Result
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Driver ¶
Driver is the driver for postgresql database.
func (*Driver) CheckLocalTypeForField ¶ added in v2.2.1
func (d *Driver) CheckLocalTypeForField(ctx context.Context, fieldType string, fieldValue any) (gdb.LocalType, error)
CheckLocalTypeForField checks and returns corresponding local golang type for given db type.
func (*Driver) ConvertValueForField ¶ added in v2.7.2
func (d *Driver) ConvertValueForField(ctx context.Context, fieldType string, fieldValue any) (any, error)
ConvertValueForField converts value to database acceptable value.
func (*Driver) ConvertValueForLocal ¶ added in v2.1.2
func (d *Driver) ConvertValueForLocal(ctx context.Context, fieldType string, fieldValue any) (any, error)
ConvertValueForLocal converts value to local Golang type of value according field type name from database. The parameter `fieldType` is in lower case, like: `float(5,2)`, `unsigned double(5,2)`, `decimal(10,2)`, `char(45)`, `varchar(100)`, etc.
func (*Driver) DoExec ¶ added in v2.1.3
func (d *Driver) DoExec(ctx context.Context, link gdb.Link, sql string, args ...any) (result sql.Result, err error)
DoExec commits the sql string and its arguments to underlying driver through given link object and returns the execution result.
func (*Driver) DoFilter ¶
func (d *Driver) DoFilter( ctx context.Context, link gdb.Link, sql string, args []any, ) (newSql string, newArgs []any, err error)
DoFilter deals with the sql string before commits it to underlying sql driver.
func (*Driver) DoInsert ¶
func (d *Driver) DoInsert(ctx context.Context, link gdb.Link, table string, list gdb.List, option gdb.DoInsertOption) (result sql.Result, err error)
DoInsert inserts or updates data for given table.
func (*Driver) FormatUpsert ¶ added in v2.6.4
func (d *Driver) FormatUpsert(columns []string, list gdb.List, option gdb.DoInsertOption) (string, error)
FormatUpsert returns SQL clause of type upsert for PgSQL. For example: ON CONFLICT (id) DO UPDATE SET ...
func (*Driver) New ¶
New creates and returns a database object for postgresql. It implements the interface of gdb.Driver for extra database driver installation.
func (*Driver) Open ¶
Open creates and returns an underlying sql.DB object for pgsql. https://pkg.go.dev/github.com/lib/pq
func (*Driver) OrderRandomFunction ¶ added in v2.7.4
OrderRandomFunction returns the SQL function for random ordering.