Documentation ¶
Overview ¶
Package db have some common utilities shared by db/l2db and db/historydb, the most relevant ones are: - SQL connection utilities - Managing the SQL schema: this is done using migration files placed under db/migrations. The files are executed by order of the file name. - Custom meddlers: used to easily transform struct <==> table
Index ¶
- Constants
- func BulkInsert(db meddler.DB, q string, args interface{}) error
- func ConnectSQLDB(port int, host, user, password, name string) (*sqlx.DB, error)
- func InitSQLDB(port int, host, user, password, name string) (*sqlx.DB, error)
- func InitTestSQLDB() (*sqlx.DB, error)
- func MigrationsDown(db *sql.DB, migrationsToRun uint) error
- func MigrationsUp(db *sql.DB) error
- func Rollback(txn *sqlx.Tx)
- func RowsClose(rows *sql.Rows)
- func SlicePtrsToSlice(slice interface{}) interface{}
- func SliceToSlicePtrs(slice interface{}) interface{}
- type APIConnectionController
- type BigIntMeddler
- type BigIntNullMeddler
Constants ¶
const ( // OrderAsc indicates ascending order when using pagination OrderAsc = "ASC" // OrderDesc indicates descending order when using pagination OrderDesc = "DESC" )
Variables ¶
This section is empty.
Functions ¶
func BulkInsert ¶
BulkInsert performs a bulk insert with a single statement into the specified table. Example: `db.BulkInsert(myDB, "INSERT INTO block (eth_block_num, timestamp, hash) VALUES %s", blocks[:])` Note that all the columns must be specified in the query, and they must be in the same order as in the table. Note that the fields in the structs need to be defined in the same order as in the table columns.
func ConnectSQLDB ¶
ConnectSQLDB connects to the SQL DB
func InitTestSQLDB ¶ added in v1.2.0
InitTestSQLDB opens test PostgreSQL database
func MigrationsDown ¶
MigrationsDown runs the SQL migrations Down, migrationsToRun specifies how many migrations will be run, 0 means any.
func SlicePtrsToSlice ¶
func SlicePtrsToSlice(slice interface{}) interface{}
SlicePtrsToSlice converts any []*Foo to []Foo
func SliceToSlicePtrs ¶
func SliceToSlicePtrs(slice interface{}) interface{}
SliceToSlicePtrs converts any []Foo to []*Foo
Types ¶
type APIConnectionController ¶
type APIConnectionController struct {
// contains filtered or unexported fields
}
APIConnectionController is used to limit the SQL open connections used by the API
func NewAPIConnectionController ¶
func NewAPIConnectionController(maxConnections int, timeout time.Duration) *APIConnectionController
NewAPIConnectionController initialize APIConnectionController
func (*APIConnectionController) Acquire ¶
func (acc *APIConnectionController) Acquire() (context.CancelFunc, error)
Acquire reserves a SQL connection. If the connection is not acquired within the timeout, the function will return an error
func (*APIConnectionController) Release ¶
func (acc *APIConnectionController) Release()
Release frees a SQL connection
type BigIntMeddler ¶
type BigIntMeddler struct{}
BigIntMeddler encodes or decodes the field value to or from JSON
func (BigIntMeddler) PostRead ¶
func (b BigIntMeddler) PostRead(fieldPtr, scanTarget interface{}) error
PostRead is called after a Scan operation for fields that have the BigIntMeddler
func (BigIntMeddler) PreRead ¶
func (b BigIntMeddler) PreRead(fieldAddr interface{}) (scanTarget interface{}, err error)
PreRead is called before a Scan operation for fields that have the BigIntMeddler
func (BigIntMeddler) PreWrite ¶
func (b BigIntMeddler) PreWrite(fieldPtr interface{}) (saveValue interface{}, err error)
PreWrite is called before an Insert or Update operation for fields that have the BigIntMeddler
type BigIntNullMeddler ¶
type BigIntNullMeddler struct{}
BigIntNullMeddler encodes or decodes the field value to or from JSON
func (BigIntNullMeddler) PostRead ¶
func (b BigIntNullMeddler) PostRead(fieldPtr, scanTarget interface{}) error
PostRead is called after a Scan operation for fields that have the BigIntNullMeddler
func (BigIntNullMeddler) PreRead ¶
func (b BigIntNullMeddler) PreRead(fieldAddr interface{}) (scanTarget interface{}, err error)
PreRead is called before a Scan operation for fields that have the BigIntNullMeddler
func (BigIntNullMeddler) PreWrite ¶
func (b BigIntNullMeddler) PreWrite(fieldPtr interface{}) (saveValue interface{}, err error)
PreWrite is called before an Insert or Update operation for fields that have the BigIntNullMeddler
Directories ¶
Path | Synopsis |
---|---|
Package historydb is responsible for storing and retrieving the historic data of the Hermez network.
|
Package historydb is responsible for storing and retrieving the historic data of the Hermez network. |
Package kvdb provides a key-value database with Checkpoints & Resets system
|
Package kvdb provides a key-value database with Checkpoints & Resets system |
Package l2db is responsible for storing and retrieving the data received by the coordinator through the api.
|
Package l2db is responsible for storing and retrieving the data received by the coordinator through the api. |