Skip to content

pg-uint/pgx-pg-uint128

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pgx-pg-uint128

pgx-pg-uint128 adds support for the pg-uint128 PostgreSQL extension in the Go pgx driver.

Requirements

  • PostgreSQL 12+ with the pg-uint128 extension installed
  • pgx driver version 5.6.0+
  • Go version 1.21+

Features

  • New Datatypes for pgx:

    • uint1 (maps to Go's uint8)
    • uint2 (maps to Go's uint16)
    • uint4 (maps to Go's uint32)
    • uint8 (maps to Go's uint64)
    • uint16 (maps to uint128 via this package to emulate 128-bit unsigned integers in Go)
    • int1 (maps to Go's int8)
    • int16 (maps to int128 via this package to emulate 128-bit signed integers in Go)
  • Derivative Type Support:

    • Arrays
    • Ranges
    • Multi-ranges
  • Efficient Encoding/Decoding:

    • Full support for both binary and text protocols
  • Flexible Scanning:

    • zeronull types support
    • Automatically scans new types into Go's standard integer types.
    • Includes safeguards for overflow and underflow, returning errors when necessary

Installation

To add pgx-pg-uint128 to your Go project, run:

go get github.com/pg-uint/pgx-pg-uint128

Usage

package main

import (
	"context"
	"log"
	"os"

	"github.com/jackc/pgx/v5"

	"github.com/pg-uint/pgx-pg-uint128/types"
	"github.com/pg-uint/pgx-pg-uint128/types/zeronull"
)

func main() {
	conn, err := pgx.Connect(context.Background(), os.Getenv("DATABASE_URL"))
	if err != nil {
		log.Fatalf("Unable to connect to database: %v", err)
	}

	defer conn.Close(context.Background())

	if _, err := types.RegisterAll(context.Background(), conn); err != nil {
		log.Fatalf("Unable to register types: %v", err)
	}

	// Optionally register zeronull types
	zeronull.Register(conn.TypeMap())

	// Do regular work with connection
}

About

pg-uint128 extension support for GoLang PGX driver

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors