unwrap

package module
v0.0.0-...-86bc64e Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

README

pgx-unwrap

Unwrap database/sql connections for pgx interop

In rare circumstances, a project may need to use both the standard library driver (github.com/jackc/pgx/v5/stdlib) and a native pgx / pgxpool client. In these rare cases, it may be necessary to convert connections of one type to the other. This library provides helpers for "unwrapping" connections for this purpose.

Documentation

Overview

Package unwrap provides tools for "unwrapping" (converting) standard library database connections for the `pgx` driver into native `pgx` connections.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyReflectData

func CopyReflectData(v reflect.Value) (reflect.Value, bool)

CopyReflectData unsafely copies a pointer so it can be modified. This copies the underlying data (by address) and just changes the flags on the `reflect.Value` wrapping that data.

By default, `reflect` sets the read-only flag on values that are internal, e.g. those produced by `FieldByName()` on unexported fields. This function makes a new `reflect.Value` without the read-only flag set.

If the value is not addressable, the value cannot and will not be copied and this function will return a `copied=false` value.

H/T: https://stackoverflow.com/a/43918797/1068170

func CopyReflectValue

func CopyReflectValue(v reflect.Value) reflect.Value

CopyReflectValue copies a value so it can be modified.

H/T: https://stackoverflow.com/a/43918797/1068170

func ExtractTx

func ExtractTx(tx *sql.Tx) (pgx.Tx, error)

ExtractTx unwraps a `pgx.Tx` from a standard library transaction created from the `github.com/jackc/pgx/v5/stdlib` driver.

Types

This section is empty.

Jump to

Keyboard shortcuts

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