bigint

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2022 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.

This project is forked from https://github.com/d-fal/bigint.

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.

package main

import (
	"github.com/iam047801/bigint"

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

func main() {
	type UserBalance struct {
		tableName struct{} `pg:"balances"`

		UserID uint64         `pg:",pk"`
		Value  *bigint.BigInt `pg:"type:numeric"`
	}

	db := pg.Connect(&pg.Options{
		Addr:     "127.0.0.1:5432",
		User:     "postgres",
		Password: "postgres",
		Database: "postgres",
	})

	err := db.Model((*UserBalance)(nil)).CreateTable(&orm.CreateTableOptions{
		Temp:          true,
		FKConstraints: true,
		IfNotExists:   true,
	})
	if err != nil {
		panic(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 FromBigInt

func FromBigInt(x *big.Int) *BigInt

FromBigInt is a shortcut for (*BigInt)(x).

func FromInt64

func FromInt64(x int64) *BigInt

FromInt64 allocates and returns a new BigInt set to x.

func FromString

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

FromString allocates and returns a new BigInt set to x, interpreted in the base 10.

func (*BigInt) Add

func (x *BigInt) Add(y *BigInt) *BigInt

Add sets new BigInt to the sum x+y and returns it.

func (*BigInt) Bytes

func (x *BigInt) Bytes() []byte

Bytes returns the absolute value of x as a big-endian byte slice.

To use a fixed length slice, or a preallocated one, use FillBytes.

func (*BigInt) Cmp

func (x *BigInt) Cmp(y *BigInt) int

Cmp compares x and y and returns:

-1 if x <  y
 0 if x == y
+1 if x >  y

func (*BigInt) Div

func (x *BigInt) Div(y *BigInt) *BigInt

Div sets new BigInt to the quotient x/y for y != 0 and returns it. If y == 0, a division-by-zero run-time panic occurs.

func (*BigInt) MarshalJSON

func (x *BigInt) MarshalJSON() ([]byte, error)

func (*BigInt) Mul

func (x *BigInt) Mul(y *BigInt) *BigInt

Mul sets new BigInt to the product x*y and returns it.

func (*BigInt) Neg

func (x *BigInt) Neg() *BigInt

Neg sets new BigInt to -x and returns it.

func (*BigInt) Scan

func (x *BigInt) Scan(value interface{}) error

Scan maps value to BigInt.

func (*BigInt) String

func (x *BigInt) String() string

String returns the decimal representation of x as generated by x.ToBigInt().Text(10).

func (*BigInt) Sub

func (x *BigInt) Sub(y *BigInt) *BigInt

Sub sets new BigInt to the difference x-y and returns it.

func (*BigInt) ToBigInt

func (x *BigInt) ToBigInt() *big.Int

ToBigInt is a shortcut for (*big.Int)(x).

func (*BigInt) ToInt64

func (x *BigInt) ToInt64() int64

ToInt64 returns the int64 representation of x. If x cannot be represented in an int64, the result is undefined.

func (*BigInt) ToUInt64

func (x *BigInt) ToUInt64() uint64

ToUInt64 returns the uint64 representation of x. If x cannot be represented in a uint64, the result is undefined.

func (*BigInt) UnmarshalJSON

func (x *BigInt) UnmarshalJSON(p []byte) error

func (*BigInt) Value

func (x *BigInt) Value() (driver.Value, error)

Value returns string representation of BigInt.

Jump to

Keyboard shortcuts

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