package
0.0.0-20241204125103-4a9f9b64ecde
Repository: https://github.com/albertwidi/pkg.git
Documentation: pkg.go.dev

# README

Postgres

The postgres package provides a compatibility layer between lib/pq and jackq/pgx.

The motivation of bridging lib/pq and jackq/pgx is because we are using lib/pq at the begining of our project. While migrating to pgx we found many things are not compatible with database/sql. To make things consistent on our end we build the compatibility layer.

This package provide some helper functions taken and modified from https://github.com/golang/pkgsite/tree/master/internal/database.

Disclaimer

This package doesn't guarantee full backwards compatibility between stdlib and jackq/pgx because pgx use a lot of custom error inside the package itself. For example, sql.ErrNoRows is pgx.ErrNoRows in pgx. We tried to convert this back in some cases, but not all.

Tracing

This package offers a comprehensive tracing via opentelemetry(by default).

Configurations for tracing can be configured via TraceConfig.

# Functions

No description provided by the author
CollectStructs scans the rows from the query into structs and returns a slice of them.
Connect returns connected Postgres object.
IsPQError returns whether the error is a PostgreSQL internal error or not.
NewConfigFromDSN creates a new connect configuration from postgresql data source name.
NullIsEmpty returns a sql.Scanner that writes the empty string to s if the sql.Value is NULL.
NullPtr is for scanning nullable database columns into pointer variables or fields.
ParseDSN parses a postgres-type dsn into a map.
StructScanner returns a function that, when called on a struct pointer of its argument type, returns a slice of arguments suitable for Row.Scan or Rows.Scan.

# Constants

No description provided by the author

# Variables

PostgreSQL error codes and definition taken from https://www.postgresql.org/docs/current/errcodes-appendix.html.
PostgreSQL error codes and definition taken from https://www.postgresql.org/docs/current/errcodes-appendix.html.
Class 22 - Data Exception.
PostgreSQL error codes and definition taken from https://www.postgresql.org/docs/current/errcodes-appendix.html.
PostgreSQL error codes and definition taken from https://www.postgresql.org/docs/current/errcodes-appendix.html.
PostgreSQL error codes and definition taken from https://www.postgresql.org/docs/current/errcodes-appendix.html.
PostgreSQL error codes and definition taken from https://www.postgresql.org/docs/current/errcodes-appendix.html.
Class 23 - Integrity Constraint Violation.
PostgreSQL error codes and definition taken from https://www.postgresql.org/docs/current/errcodes-appendix.html.
PostgreSQL error codes and definition taken from https://www.postgresql.org/docs/current/errcodes-appendix.html.
PostgreSQL error codes and definition taken from https://www.postgresql.org/docs/current/errcodes-appendix.html.
PostgreSQL error codes and definition taken from https://www.postgresql.org/docs/current/errcodes-appendix.html.

# Structs

ConnectConfig stores the configuration to create a new connection to PostgreSQL database.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
RowsCompat implements Rows to maintain the compatibility with sql.Rows.
No description provided by the author
No description provided by the author
TransactCompat handle backwards compatibility guarantee of different postgreSQL libraries.

# Interfaces

Transaction interface ensure the pgx and sql/db tx object is compatible so we can use them both inside the Postgres object.