dao

package
v0.0.0-...-e5308b5 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	*gorm.DB
	// contains filtered or unexported fields
}

DB is a struct that embeds gorm.DB to provide additional database functionality.

func NewDB

func NewDB(opts ...DBOption) (*DB, error)

NewDB is a function that creates a new DB instance with the provided options.

func (*DB) AddUndoLog

func (d *DB) AddUndoLog(height uint32, sql string) error

AddUndoLog is a method that adds an undo log to the database. It takes two parameters: height of type uint32 and sql of type string. The height parameter represents the height of the undo log. The sql parameter represents the SQL statement of the undo log.

The method first calls the OldestSavepoint method to get the oldest savepoint. If an error occurs during this operation, it returns the error. If the ID of the oldest savepoint is 0, it returns nil.

The method then creates a new UndoLog struct with the provided height and SQL statement, and calls the Create method to add the undo log to the database. If an error occurs during this operation, it returns the error.

The method returns an error if any operation fails, or nil if the operations succeed.

func (*DB) BlockCount

func (d *DB) BlockCount() (count uint32, err error)

BlockCount retrieves the total number of blocks in the database. It returns the count as an uint32 and any error encountered.

func (*DB) BlockHash

func (d *DB) BlockHash(height ...uint32) (blockHash string, err error)

func (*DB) CreateBlockInfo

func (d *DB) CreateBlockInfo(block *tables.BlockParserInfo) error

func (*DB) CreateInscribeOrder

func (d *DB) CreateInscribeOrder(order *tables.InscribeOrder) error

func (*DB) DeleteBlockInfo

func (d *DB) DeleteBlockInfo(height uint32) error

func (*DB) DeleteSavepoint

func (d *DB) DeleteSavepoint(id uint64) error

DeleteSavepoint is a method that deletes all savepoints from the database. It returns an error. The method creates a new SavePoint struct and uses its TableName method to get the name of the table. It then uses the Exec method of the DB struct to execute a SQL delete statement on the table. If an error occurs during the deletion, it returns the error.

func (*DB) DeleteUndoLog

func (d *DB) DeleteUndoLog() error

DeleteUndoLog is a method that deletes all undo logs from the database. It returns an error. The method creates a new UndoLog struct and uses its TableName method to get the name of the table. It then uses the Exec method of the DB struct to execute a SQL delete statement on the table. If an error occurs during the deletion, it returns the error.

func (*DB) FindInscribeOrdersByReceiveAddress

func (d *DB) FindInscribeOrdersByReceiveAddress(address string, page, limit int) (orders []*tables.InscribeOrder, total int64, err error)

func (*DB) FindUndoLog

func (d *DB) FindUndoLog() (*sql.Rows, error)

FindUndoLog is a method that retrieves all undo logs from the database in descending order of their IDs. It returns a slice of pointers to UndoLog structs and an error. The method uses the Order method of the DB struct to order the undo logs by their IDs in descending order. It then uses the Find method of the DB struct to retrieve the undo logs and assigns them to undoLogs. If an error occurs during the retrieval, it returns the undoLogs and the error.

func (*DB) GetInscribeOrderByOrderId

func (d *DB) GetInscribeOrderByOrderId(orderId string) (order tables.InscribeOrder, err error)

func (*DB) GetInscribeOrdersByRevealAddress

func (d *DB) GetInscribeOrdersByRevealAddress(address string) (order tables.InscribeOrder, err error)

func (*DB) ListSavepoint

func (d *DB) ListSavepoint() (list []*tables.SavePoint, err error)

ListSavepoint is a method that retrieves a list of all savepoints from the database. It returns a slice of pointers to SavePoint structs and an error. The method uses the Find method of the DB struct to retrieve the savepoints and assigns them to the list. If an error occurs during the retrieval, it checks if the error is a ErrRecordNotFound error from the gorm package. If it is, it assigns nil to the error, effectively ignoring the error. The method then returns the list of savepoints and the error.

func (*DB) OldestSavepoint

func (d *DB) OldestSavepoint() (savepoint *tables.SavePoint, err error)

OldestSavepoint is a method that retrieves the oldest savepoint from the database. It returns a pointer to a SavePoint struct and an error. The method uses the First method of the DB struct to retrieve the oldest savepoint and assigns it to savepoint. If an error occurs during the retrieval, it returns the savepoint and the error.

func (*DB) Transaction

func (d *DB) Transaction(fn func(tx *DB) error) error

Transaction is a method on DB that executes a function within a database transaction.

func (*DB) UpdateInscribeOrderStatus

func (d *DB) UpdateInscribeOrderStatus(height uint32, newOrder *tables.InscribeOrder) error

type DBOption

type DBOption func(*DBOptions)

DBOption is a function type that modifies DBOptions.

func WithAddr

func WithAddr(addr string) DBOption

WithAddr returns a DBOption that sets the address of the database.

func WithAutoMigrateTables

func WithAutoMigrateTables(tables ...interface{}) DBOption

WithAutoMigrateTables returns a DBOption that sets the tables to be auto migrated in the database.

func WithDBName

func WithDBName(dbName string) DBOption

WithDBName returns a DBOption that sets the name of the database.

func WithPassword

func WithPassword(password string) DBOption

WithPassword returns a DBOption that sets the password of the database.

func WithUser

func WithUser(user string) DBOption

WithUser returns a DBOption that sets the user of the database.

type DBOptions

type DBOptions struct {
	// contains filtered or unexported fields
}

DBOptions is a struct that holds the configuration options for the database.

type GormLogger

type GormLogger struct {
	btclog.Logger
}

GormLogger is a struct that embeds btclog.Logger to provide additional logging functionality.

func (*GormLogger) Error

func (g *GormLogger) Error(ctx context.Context, msg string, data ...interface{})

Error is a method on GormLogger that logs an error message.

func (*GormLogger) Info

func (g *GormLogger) Info(ctx context.Context, msg string, data ...interface{})

Info is a method on GormLogger that logs an informational message.

func (*GormLogger) LogMode

func (g *GormLogger) LogMode(level logger.LogLevel) logger.Interface

LogMode is a method on GormLogger that sets the log level.

func (*GormLogger) Print

func (g *GormLogger) Print(data ...interface{})

func (*GormLogger) Trace

func (g *GormLogger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)

Trace is a method on GormLogger that logs a trace message.

func (*GormLogger) Warn

func (g *GormLogger) Warn(ctx context.Context, msg string, data ...interface{})

Warn is a method on GormLogger that logs a warning message.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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