bigint

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2021 License: GPL-3.0 Imports: 4 Imported by: 0

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/d-fal/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)
	}

}


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) Add

func (i *Bigint) Add(x *Bigint) *Bigint

func (*Bigint) Div

func (i *Bigint) Div(x *Bigint) *Bigint

func (*Bigint) FromBigInt

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

func (*Bigint) Mul

func (i *Bigint) Mul(x *Bigint) *Bigint

func (*Bigint) Neg

func (i *Bigint) Neg() *Bigint

func (*Bigint) Scan

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

func (*Bigint) String

func (i *Bigint) String() string

func (*Bigint) Sub

func (i *Bigint) Sub(x *Bigint) *Bigint

func (*Bigint) ToInt64

func (i *Bigint) ToInt64() int64

func (*Bigint) ToUInt64

func (i *Bigint) ToUInt64() uint64

func (*Bigint) Value

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

Jump to

Keyboard shortcuts

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