Documentation
¶
Index ¶
- Constants
- Variables
- func IsDeadlockDetected(err error) bool
- func IsForeignKeyViolation(err error) bool
- func IsSQLState(err error, code string) bool
- func IsSerializationFailure(err error) bool
- func IsUniqueViolation(err error) bool
- func Open(dsn string) (*sql.DB, error)
- func OpenConfig(config Config) (*sql.DB, error)
- type Config
- type Connector
- type Error
- type Row
- type ScriptResult
- type Session
- func (s *Session) BeginTx(ctx context.Context, options *sql.TxOptions) (*sql.Tx, error)
- func (s *Session) Close() error
- func (s *Session) Discard() error
- func (s *Session) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
- func (s *Session) ExecScriptContext(ctx context.Context, script string) (ScriptResult, error)
- func (s *Session) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
- func (s *Session) QueryRowContext(ctx context.Context, query string, args ...any) Row
- type TLSMode
Constants ¶
const Version = "1.1.1"
Version is the stable semantic version of the driver.
Variables ¶
var ErrOperationOutcomeUnknown = errors.New("postgres: connection lost after operation started; outcome is unknown")
ErrOperationOutcomeUnknown means a connection failed after an operation may have reached PostgreSQL. The driver returns this instead of driver.ErrBadConn so database/sql does not retry a potentially non-idempotent statement.
Functions ¶
func IsDeadlockDetected ¶
func IsForeignKeyViolation ¶
func IsSQLState ¶
func IsSerializationFailure ¶
func IsUniqueViolation ¶
Types ¶
type Config ¶
type Config struct {
Host string
Port uint16
User string
Password string
Database string
TLSMode TLSMode
TLSConfig *tls.Config
RootCAs *x509.CertPool
ServerName string
ConnectTimeout time.Duration
CancelTimeout time.Duration
MaxMessageSize int32
ApplicationName string
RuntimeParams map[string]string
// AllowInsecureAuthentication permits cleartext or MD5 password authentication
// on an unencrypted transport. It is false by default.
AllowInsecureAuthentication bool
}
Config contains connection settings for one PostgreSQL server.
func ParseConfig ¶
ParseConfig parses a postgres:// or postgresql:// URL.
type Connector ¶
type Connector struct {
// contains filtered or unexported fields
}
Connector implements database/sql/driver.Connector.
func NewConnector ¶
type Error ¶
type Error struct {
Severity string
SeverityNonLocal string
Code string
Message string
Detail string
Hint string
Position string
InternalPosition string
InternalQuery string
Where string
Schema string
Table string
Column string
DataType string
Constraint string
File string
Line string
Routine string
}
Error is a structured PostgreSQL ErrorResponse.
type Row ¶ added in v1.1.0
Row is the minimal scan surface shared by sql.Row and ORM-generated scanners.
type ScriptResult ¶ added in v1.1.0
type ScriptResult struct {
CommandTags []string
}
ScriptResult describes the CommandComplete tags returned by a trusted SQL script in execution order.
type Session ¶ added in v1.1.0
type Session struct {
// contains filtered or unexported fields
}
Session owns one pinned database/sql connection until Close or Discard.
Sessions are intended for PostgreSQL session-scoped operations such as advisory locks and migration execution. A Session must not be used concurrently by multiple goroutines.
func (*Session) BeginTx ¶ added in v1.1.0
BeginTx begins a database/sql transaction on the pinned connection.
func (*Session) Close ¶ added in v1.1.0
Close returns the pinned connection to the database/sql pool.
func (*Session) Discard ¶ added in v1.1.0
Discard permanently removes the pinned backend from the database/sql pool. It is intended for failed advisory-lock cleanup, protocol uncertainty, or any other situation where returning the backend to the pool is unsafe.
func (*Session) ExecContext ¶ added in v1.1.0
ExecContext executes one parameterized statement on the pinned connection.
func (*Session) ExecScriptContext ¶ added in v1.1.0
ExecScriptContext executes trusted, developer-authored SQL through the PostgreSQL simple-query protocol on the pinned session.
This API intentionally accepts no arguments. Request or user-controlled data must never be interpolated into script. Use ExecContext or QueryContext for parameterized application values.
func (*Session) QueryContext ¶ added in v1.1.0
QueryContext executes one parameterized query on the pinned connection.