decimal

package module
v0.0.0-...-0b508b9 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: MIT Imports: 7 Imported by: 0

README

Usage:

You have to use the type alias Decimal declared in this package instead of postgres.Decimal from ericlagergren/decimal in your structs. Both will work, but the latter will be much slower because it uses the default database/sql interface.

import (
	"context"
	"fmt"
    "log"

	"github.com/jackc/pgx/v5"
	"github.com/jackc/pgx/v5/pgxpool"
    pgxdecimal "github.com/SoMuchForSubtlety/pgx-ericlagergren-decimal"
)

func main() {
	pgCfg, err := pgxpool.ParseConfig("postgres://user:pass@localhost:5432")
	if err != nil {
		log.Fatal(err)
	}
	pgCfg.AfterConnect = func(ctx context.Context, c *pgx.Conn) error {
		pgxdecimal.Register(c.TypeMap())
		return nil
	}
    pool, err := pgxpool.NewWithConfig(ctx, pgCfg)
	if err != nil {
		log.Fatal(err)
	}
}

This package borrows heavily from the implementation of https://github.com/jackc/pgx-shopspring-decimal

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(m *pgtype.Map)

Register registers the ericlagergren/decimal integration with a pgtype.ConnInfo.

func TryWrapNumericEncodePlan

func TryWrapNumericEncodePlan(value interface{}) (plan pgtype.WrappedEncodePlanNextSetter, nextValue interface{}, ok bool)

func TryWrapNumericScanPlan

func TryWrapNumericScanPlan(target interface{}) (plan pgtype.WrappedScanPlanNextSetter, nextDst interface{}, ok bool)

Types

type Decimal

type Decimal postgres.Decimal

Decimal has to be used to prevent pgx from using the database/sql scanner function

func (Decimal) Float64Value

func (d Decimal) Float64Value() (pgtype.Float8, error)

func (Decimal) Int64Value

func (d Decimal) Int64Value() (pgtype.Int8, error)

func (Decimal) NumericValue

func (d Decimal) NumericValue() (pgtype.Numeric, error)

func (*Decimal) ScanFloat64

func (d *Decimal) ScanFloat64(v pgtype.Float8) error

func (*Decimal) ScanInt64

func (d *Decimal) ScanInt64(v pgtype.Int8) error

func (*Decimal) ScanNumeric

func (d *Decimal) ScanNumeric(v pgtype.Numeric) error

type NumericCodec

type NumericCodec struct {
	pgtype.NumericCodec
}

func (NumericCodec) DecodeValue

func (NumericCodec) DecodeValue(tm *pgtype.Map, oid uint32, format int16, src []byte) (interface{}, error)

Jump to

Keyboard shortcuts

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