...

Package db

import "github.com/hyperledger/fabric-ca/lib/server/db"
Overview
Index
Subdirectories

Overview ▾

Index ▾

Variables
func CurrentDBLevels(db FabricCADB) (*util.Levels, error)
func Migrate(migrator Migrator, currentLevels, srvLevels *util.Levels) error
type AffiliationRecord
type CertRecord
type DB
    func New(db SqlxDB, caName string, metricsProvider metrics.Provider) *DB
    func (db *DB) BeginTx() FabricCATx
    func (db *DB) Close() error
    func (db *DB) DriverName() string
    func (db *DB) Exec(funcName, query string, args ...interface{}) (sql.Result, error)
    func (db *DB) Get(funcName string, dest interface{}, query string, args ...interface{}) error
    func (db *DB) IsInitialized() bool
    func (db *DB) MustBegin() *sqlx.Tx
    func (db *DB) NamedExec(funcName, query string, args interface{}) (sql.Result, error)
    func (db *DB) PingContext(ctx context.Context) error
    func (db *DB) Queryx(funcName, query string, args ...interface{}) (*sqlx.Rows, error)
    func (db *DB) Rebind(query string) string
    func (db *DB) Select(funcName string, dest interface{}, query string, args ...interface{}) error
    func (db *DB) SetDBInitialized(b bool)
    func (db *DB) SetMaxOpenConns(n int)
type FabricCADB
type FabricCATx
type Metrics
type Migrator
type SqlxDB
type SqlxTx
type TX
    func (tx *TX) Commit(funcName string) error
    func (tx *TX) Exec(funcName, query string, args ...interface{}) (sql.Result, error)
    func (tx *TX) Get(funcName string, dest interface{}, query string, args ...interface{}) error
    func (tx *TX) Queryx(funcName, query string, args ...interface{}) (*sqlx.Rows, error)
    func (tx *TX) Rebind(query string) string
    func (tx *TX) Rollback(funcName string) error
    func (tx *TX) Select(funcName string, dest interface{}, query string, args ...interface{}) error

Package files

db.go metrics.go migrator.go tx.go

Variables

var (
    // APICounterOpts define the counter opts for database APIs
    APICounterOpts = metrics.CounterOpts{
        Namespace:    "db_api_request",
        Subsystem:    "",
        Name:         "count",
        Help:         "Number of requests made to a database API",
        LabelNames:   []string{"ca_name", "func_name", "dbapi_name"},
        StatsdFormat: "%{#fqname}.%{ca_name}.%{func_name}.%{dbapi_name}",
    }

    // APIDurationOpts define the duration opts for database APIs
    APIDurationOpts = metrics.HistogramOpts{
        Namespace:    "db_api_request",
        Subsystem:    "",
        Name:         "duration",
        Help:         "Time taken in seconds for the request to a database API to be completed",
        LabelNames:   []string{"ca_name", "func_name", "dbapi_name"},
        StatsdFormat: "%{#fqname}.%{ca_name}.%{func_name}.%{dbapi_name}",
    }
)

func CurrentDBLevels

func CurrentDBLevels(db FabricCADB) (*util.Levels, error)

CurrentDBLevels returns current levels from the database

func Migrate

func Migrate(migrator Migrator, currentLevels, srvLevels *util.Levels) error

Migrate updates the database tables to use the latest schema and does data migration if needed

type AffiliationRecord

AffiliationRecord defines the properties of an affiliation

type AffiliationRecord struct {
    ID     int    `db:"id"`
    Name   string `db:"name"`
    Prekey string `db:"prekey"`
    Level  int    `db:"level"`
}

type CertRecord

CertRecord extends CFSSL CertificateRecord by adding an enrollment ID to the record

type CertRecord struct {
    ID    string `db:"id"`
    Level int    `db:"level"`
    certdb.CertificateRecord
}

type DB

DB is an adapter for sqlx.DB and implements FabricCADB interface

type DB struct {
    DB SqlxDB
    // Indicates if database was successfully initialized
    IsDBInitialized bool

    CAName string

    Metrics Metrics
}

func New

func New(db SqlxDB, caName string, metricsProvider metrics.Provider) *DB

New creates an instance of DB

func (*DB) BeginTx

func (db *DB) BeginTx() FabricCATx

BeginTx implements BeginTx method of FabricCADB interface

func (*DB) Close

func (db *DB) Close() error

Close closes db

func (*DB) DriverName

func (db *DB) DriverName() string

DriverName returns database driver name

func (*DB) Exec

func (db *DB) Exec(funcName, query string, args ...interface{}) (sql.Result, error)

Exec executes query

func (*DB) Get

func (db *DB) Get(funcName string, dest interface{}, query string, args ...interface{}) error

Get executes query

func (*DB) IsInitialized

func (db *DB) IsInitialized() bool

IsInitialized returns true if db is intialized, else false

func (*DB) MustBegin

func (db *DB) MustBegin() *sqlx.Tx

MustBegin starts a transaction

func (*DB) NamedExec

func (db *DB) NamedExec(funcName, query string, args interface{}) (sql.Result, error)

NamedExec executes query

func (*DB) PingContext

func (db *DB) PingContext(ctx context.Context) error

PingContext pings the database

func (*DB) Queryx

func (db *DB) Queryx(funcName, query string, args ...interface{}) (*sqlx.Rows, error)

Queryx executes query

func (*DB) Rebind

func (db *DB) Rebind(query string) string

Rebind parses query to properly format query

func (*DB) Select

func (db *DB) Select(funcName string, dest interface{}, query string, args ...interface{}) error

Select performs select sql statement

func (*DB) SetDBInitialized

func (db *DB) SetDBInitialized(b bool)

SetDBInitialized sets the value for Isdbinitialized

func (*DB) SetMaxOpenConns

func (db *DB) SetMaxOpenConns(n int)

SetMaxOpenConns sets number of max open connections

type FabricCADB

FabricCADB is the interface that wrapper off SqlxDB

type FabricCADB interface {
    IsInitialized() bool
    SetDBInitialized(bool)
    // BeginTx has same behavior as MustBegin except it returns FabricCATx
    // instead of *sqlx.Tx
    BeginTx() FabricCATx
    DriverName() string

    Select(funcName string, dest interface{}, query string, args ...interface{}) error
    Exec(funcName, query string, args ...interface{}) (sql.Result, error)
    NamedExec(funcName, query string, arg interface{}) (sql.Result, error)
    Get(funcName string, dest interface{}, query string, args ...interface{}) error
    Queryx(funcName, query string, args ...interface{}) (*sqlx.Rows, error)
    Rebind(query string) string
    MustBegin() *sqlx.Tx
    Close() error
    SetMaxOpenConns(n int)
    PingContext(ctx context.Context) error
}

type FabricCATx

FabricCATx is the interface with functions implemented by sqlx.Tx object that are used by Fabric CA server

type FabricCATx interface {
    Select(funcName string, dest interface{}, query string, args ...interface{}) error
    Exec(funcName, query string, args ...interface{}) (sql.Result, error)
    Queryx(funcName, query string, args ...interface{}) (*sqlx.Rows, error)
    Get(funcName string, dest interface{}, query string, args ...interface{}) error
    Rebind(query string) string
    Commit(funcName string) error
    Rollback(funcName string) error
}

type Metrics

Metrics is the set of meters for the database

type Metrics struct {
    // APICounter keeps track of number of times a database API is called
    APICounter metrics.Counter
    // APIDuration keeps track of time taken for request to complete to a database API
    APIDuration metrics.Histogram
}

type Migrator

Migrator is the interface that defines a migrator

type Migrator interface {
    MigrateUsersTable() error
    MigrateCertificatesTable() error
    MigrateAffiliationsTable() error
    MigrateCredentialsTable() error
    MigrateRAInfoTable() error
    MigrateNoncesTable() error
    Rollback() error
    Commit() error
}

type SqlxDB

SqlxDB is the interface with functions implemented by sqlx.DB object that are used by Fabric CA server

type SqlxDB interface {
    DriverName() string
    Select(dest interface{}, query string, args ...interface{}) error
    Exec(query string, args ...interface{}) (sql.Result, error)
    NamedExec(query string, arg interface{}) (sql.Result, error)
    Get(dest interface{}, query string, args ...interface{}) error
    Queryx(query string, args ...interface{}) (*sqlx.Rows, error)
    Rebind(query string) string
    MustBegin() *sqlx.Tx
    Close() error
    SetMaxOpenConns(n int)
    PingContext(ctx context.Context) error
}

type SqlxTx

SqlxTx is the contract with sqlx

type SqlxTx interface {
    Queryx(query string, args ...interface{}) (*sqlx.Rows, error)
    Get(dest interface{}, query string, args ...interface{}) error
    Select(dest interface{}, query string, args ...interface{}) error
    Rebind(query string) string
    Exec(query string, args ...interface{}) (sql.Result, error)
    Commit() error
    Rollback() error
}

type TX

TX is the database transaction

type TX struct {
    TX     SqlxTx
    Record record
}

func (*TX) Commit

func (tx *TX) Commit(funcName string) error

Commit commits the transaction

func (*TX) Exec

func (tx *TX) Exec(funcName, query string, args ...interface{}) (sql.Result, error)

Exec executes query

func (*TX) Get

func (tx *TX) Get(funcName string, dest interface{}, query string, args ...interface{}) error

Get executes query

func (*TX) Queryx

func (tx *TX) Queryx(funcName, query string, args ...interface{}) (*sqlx.Rows, error)

Queryx executes query

func (*TX) Rebind

func (tx *TX) Rebind(query string) string

Rebind rebinds the query

func (*TX) Rollback

func (tx *TX) Rollback(funcName string) error

Rollback roll backs the transaction

func (*TX) Select

func (tx *TX) Select(funcName string, dest interface{}, query string, args ...interface{}) error

Select performs select sql statement

Subdirectories

Name Synopsis
..
factory
mocks Code generated by counterfeiter.
mysql
mocks Code generated by counterfeiter.
postgres
mocks Code generated by counterfeiter.
sqlite
mocks Code generated by counterfeiter.
util