db

package
v0.0.0-...-a67bbdc Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect(dsn string) (*gorm.DB, error)

Connect connects to a database using the provided DSN.

Parameters: - dsn: The Data Source Name (DSN) used to connect to the database.

Returns: - *gorm.DB: A pointer to the connected gorm.DB object. - error: An error object indicating any connection errors that occurred.

Types

type Accounts

type Accounts struct {
	BaseModel
	ProjectID     uint64 `gorm:"column:project_id;type:bigint(20) unsigned;default:0;comment:项目 ID;NOT NULL" json:"project_id"`
	ChainType     string `gorm:"column:chain_type;type:char(3);NOT NULL" json:"chain_type"`
	Name          string `gorm:"column:name;type:varchar(255);comment:链账户名称" json:"name"`
	NativeAddress string `gorm:"column:native_address;type:char(42);comment:地址;NOT NULL" json:"native_address"`
	HexAddress    string `gorm:"column:hex_address;type:char(46);comment:地址;NOT NULL" json:"hex_address"`
	PubKey        string `gorm:"column:pub_key;type:char(172);comment:公钥;NOT NULL" json:"pub_key"`
	PriKey        string `gorm:"column:pri_key;type:char(216);comment:私钥;NOT NULL" json:"pri_key"`
	AccIndex      uint64 `gorm:"column:acc_index;type:bigint(20) unsigned;default:0;comment:链地址偏移下标;NOT NULL" json:"acc_index"`
	Status        uint   `` /* 126-byte string literal not displayed */
	TxID          uint64 `gorm:"column:tx_id;type:bigint(20) unsigned;default:0;comment:交易 ID;NOT NULL" json:"tx_id"`
	Algo          uint64 `gorm:"column:algo;type:bigint(20) unsigned;default:0;comment:加密算法, 1:secp256k1, 2:eth_secp256k1;NOT NULL" json:"algo"`
	OperationID   string `gorm:"column:operation_id;type:varchar(100);comment:操作 ID;NOT NULL" json:"operation_id"`
}

Accounts is the table of accounts.

func (Accounts) AddressPageQuery

func (Accounts) AddressPageQuery(limit, offset int) (addrs EthAddrs, err error)

AddressPageQuery retrieves a page of addresses from the Accounts table.

It takes in two parameters:

  • limit: an integer representing the maximum number of addresses to retrieve.
  • offset: an integer representing the starting position of the addresses to retrieve.

It returns two values:

  • addrs: a slice of strings containing the retrieved addresses.
  • err: an error, if any occurred during the retrieval process.

func (Accounts) TableName

func (Accounts) TableName() string

TableName returns the table name of Accounts.

type BaseModel

type BaseModel struct {
	ID        uint64   `gorm:"column:id;type:bigint(20) unsigned;primary_key;AUTO_INCREMENT;comment:ID" json:"id"`
	CreatedAt JSONTime `gorm:"<-:false" json:"-"`
	UpdatedAt JSONTime `gorm:"<-:false" json:"-"`
}

BaseModel is the base model for all models.

type EthAddress

type EthAddress common.Address

EthAddress is a common.Address wrapper

func (*EthAddress) Scan

func (a *EthAddress) Scan(value interface{}) error

Scan scans the given value and assigns it to the EthAddress.

The value parameter should be a string. It returns an error if the value cannot be assigned to the Address. The Address is assigned the value of the common.HexToAddress(str) after unmarshaling the JSONB value.

It returns an error if the value cannot be assigned to the Address, otherwise it returns nil.

func (*EthAddress) Value

func (a *EthAddress) Value() (driver.Value, error)

Value returns the value of the EthAddress as a driver.Value and an error.

It converts the EthAddress to a common.Address and returns the hexadecimal representation as a string.

type EthAddrs

type EthAddrs []EthAddress

EthAddrs is a slice of EthAddress

func (*EthAddrs) Address

func (e *EthAddrs) Address() []common.Address

Address returns a slice of common.Address containing the addresses from the EthAddrs receiver.

No parameters. Return type: []common.Address.

type JSONTime

type JSONTime struct {
	time.Time
}

JSONTime for serialize time to json

func ToJSONTime

func ToJSONTime(t time.Time) JSONTime

ToJSONTime convert time.Time to JSONTime

func (JSONTime) MarshalJSON

func (t JSONTime) MarshalJSON() ([]byte, error)

MarshalJSON implement json.Marshaler interface

func (*JSONTime) Scan

func (t *JSONTime) Scan(v interface{}) error

Scan value of time.Time

func (JSONTime) Value

func (t JSONTime) Value() (driver.Value, error)

Value insert timestamp into mysql need this function.

Jump to

Keyboard shortcuts

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