bigint

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2021 License: GPL-3.0 Imports: 4 Imported by: 2

README

bigint

bigint is a wrapper around math/big package to let us use big.int type in postgresql

In order to use big.Int structure into postgres database, one may thinks this is not straightforward and even painful. In this package, we are going to solve it.

math/big

This package uses math/big in its heart and extends its usefulnell even into postgres.

Example use with go-pg

go-pg is an amazing orm for gophers to utilize postgres. This package is used to help go-pg users implement math/big functionalities.

import (
	"net"

	"github.com/pgcontrib/bigint"
	"github.com/go-pg/pg/v10"
	"github.com/go-pg/pg/v10/orm"
)

func main() {

	type TableWithBigint struct {
		Id        uint64
		tableName struct{} `pg:"table_with_bigint"`
		Name      string
		Deposit   *bigint.Bigint
	}

	db := pg.Connect(&pg.Options{
		User:     "user",
		Password: "password",
		Database: "testdb",
		Addr: net.JoinHostPort(
			"postgres-url",
			"postgres-port",
		),
	})
	err := db.Model((*TableWithBigint)(nil)).CreateTable(&orm.CreateTableOptions{
		Temp:          true,
		FKConstraints: true,
		IfNotExists:   true,
	})

	if err != nil {
		println(err)
	}

}


Support for bun

bun will be the successor of go-pg and this package is under development to cover it as well.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bigint

type Bigint big.Int

func FromInt64

func FromInt64(x int64) *Bigint

func FromString

func FromString(x string) (*Bigint, error)

func NewBigint

func NewBigint(x *big.Int) *Bigint

func (*Bigint) Abs

func (b *Bigint) Abs() *Bigint

func (*Bigint) Add

func (b *Bigint) Add(x *Bigint) *Bigint

func (*Bigint) Cmp

func (b *Bigint) Cmp(target *Bigint) Cmp

func (*Bigint) Div

func (b *Bigint) Div(x *Bigint) *Bigint

func (*Bigint) FromBigInt

func (b *Bigint) FromBigInt(x *big.Int) *Bigint

same as NewBigint()

func (*Bigint) Mul

func (b *Bigint) Mul(x *Bigint) *Bigint

func (*Bigint) Neg

func (b *Bigint) Neg() *Bigint

func (*Bigint) Scan

func (b *Bigint) Scan(value interface{}) error

func (*Bigint) String

func (b *Bigint) String() string

func (*Bigint) Sub

func (b *Bigint) Sub(x *Bigint) *Bigint

func (*Bigint) ToInt64

func (b *Bigint) ToInt64() int64

func (*Bigint) ToUInt64

func (b *Bigint) ToUInt64() uint64

func (*Bigint) Value

func (b *Bigint) Value() (driver.Value, error)

type Cmp

type Cmp interface {
	Eq() bool
	// greater than
	Gt() bool
	// lower than
	Lt() bool
	// Greater or equal
	Geq() bool
	// Lower or equal
	Leq() bool
}

Jump to

Keyboard shortcuts

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