...

Package couchdb

import "github.com/hyperledger/fabric/core/ledger/util/couchdb"
Overview
Index

Overview ▾

Index ▾

func ConstructMetadataDBName(dbName string) string
func ConstructNamespaceDBName(chainName, namespace string) string
func CreateSystemDatabasesIfNotExist(couchInstance *CouchInstance) error
func IsJSON(s string) bool
type AttachmentInfo
type Base64Attachment
type BatchRetrieveDocMetadataResponse
type BatchUpdateResponse
type ConnectionInfo
type CouchConnectionDef
    func CreateConnectionDefinition(couchDBAddress, username, password string, maxRetries, maxRetriesOnStartup int, requestTimeout time.Duration, createGlobalChangesDB bool) (*CouchConnectionDef, error)
type CouchDBDef
    func GetCouchDBDefinition() *CouchDBDef
type CouchDatabase
    func CreateCouchDatabase(couchInstance *CouchInstance, dbName string) (*CouchDatabase, error)
    func (dbclient *CouchDatabase) ApplyDatabaseSecurity(databaseSecurity *DatabaseSecurity) error
    func (dbclient *CouchDatabase) BatchRetrieveDocumentMetadata(keys []string) ([]*DocMetadata, error)
    func (dbclient *CouchDatabase) BatchUpdateDocuments(documents []*CouchDoc) ([]*BatchUpdateResponse, error)
    func (dbclient *CouchDatabase) CreateDatabaseIfNotExist() error
    func (dbclient *CouchDatabase) CreateIndex(indexdefinition string) (*CreateIndexResponse, error)
    func (dbclient *CouchDatabase) DeleteDoc(id, rev string) error
    func (dbclient *CouchDatabase) DeleteIndex(designdoc, indexname string) error
    func (dbclient *CouchDatabase) DropDatabase() (*DBOperationResponse, error)
    func (dbclient *CouchDatabase) EnsureFullCommit() (*DBOperationResponse, error)
    func (dbclient *CouchDatabase) GetDatabaseInfo() (*DBInfo, *DBReturn, error)
    func (dbclient *CouchDatabase) GetDatabaseSecurity() (*DatabaseSecurity, error)
    func (dbclient *CouchDatabase) ListIndex() ([]*IndexResult, error)
    func (dbclient *CouchDatabase) QueryDocuments(query string) ([]*QueryResult, string, error)
    func (dbclient *CouchDatabase) ReadDoc(id string) (*CouchDoc, string, error)
    func (dbclient *CouchDatabase) ReadDocRange(startKey, endKey string, limit int32) ([]*QueryResult, string, error)
    func (dbclient *CouchDatabase) SaveDoc(id string, rev string, couchDoc *CouchDoc) (string, error)
    func (dbclient *CouchDatabase) WarmIndex(designdoc, indexname string) error
    func (dbclient *CouchDatabase) WarmIndexAllIndexes() error
type CouchDoc
type CouchInstance
    func CreateCouchInstance(couchDBConnectURL, id, pw string, maxRetries, maxRetriesOnStartup int, connectionTimeout time.Duration, createGlobalChangesDB bool, metricsProvider metrics.Provider) (*CouchInstance, error)
    func (couchInstance *CouchInstance) HealthCheck(ctx context.Context) error
    func (couchInstance *CouchInstance) VerifyCouchConfig() (*ConnectionInfo, *DBReturn, error)
type CreateIndexResponse
type DBInfo
type DBOperationResponse
type DBReturn
type DatabaseSecurity
type DocID
type DocMetadata
type FileDetails
type IndexResult
type QueryResponse
type QueryResult
type RangeQueryResponse

Package files

config.go couchdb.go couchdbutil.go metrics.go

func ConstructMetadataDBName

func ConstructMetadataDBName(dbName string) string

ConstructMetadataDBName truncates the db name to couchdb allowed length to construct the metadataDBName

func ConstructNamespaceDBName

func ConstructNamespaceDBName(chainName, namespace string) string

ConstructNamespaceDBName truncates db name to couchdb allowed length to construct the namespaceDBName

func CreateSystemDatabasesIfNotExist

func CreateSystemDatabasesIfNotExist(couchInstance *CouchInstance) error

CreateSystemDatabasesIfNotExist - creates the system databases if they do not exist

func IsJSON

func IsJSON(s string) bool

IsJSON tests a string to determine if a valid JSON

type AttachmentInfo

AttachmentInfo contains the definition for an attached file for couchdb

type AttachmentInfo struct {
    Name            string
    ContentType     string `json:"content_type"`
    Length          uint64
    AttachmentBytes []byte `json:"data"`
}

type Base64Attachment

Base64Attachment contains the definition for an attached file for couchdb

type Base64Attachment struct {
    ContentType    string `json:"content_type"`
    AttachmentData string `json:"data"`
}

type BatchRetrieveDocMetadataResponse

BatchRetrieveDocMetadataResponse is used for processing REST batch responses from CouchDB

type BatchRetrieveDocMetadataResponse struct {
    Rows []struct {
        ID          string `json:"id"`
        DocMetadata struct {
            ID      string `json:"_id"`
            Rev     string `json:"_rev"`
            Version string `json:"~version"`
        } `json:"doc"`
    } `json:"rows"`
}

type BatchUpdateResponse

BatchUpdateResponse defines a structure for batch update response

type BatchUpdateResponse struct {
    ID     string `json:"id"`
    Error  string `json:"error"`
    Reason string `json:"reason"`
    Ok     bool   `json:"ok"`
    Rev    string `json:"rev"`
}

type ConnectionInfo

ConnectionInfo is a structure for capturing the database info and version

type ConnectionInfo struct {
    Couchdb string `json:"couchdb"`
    Version string `json:"version"`
    Vendor  struct {
        Name string `json:"name"`
    } `json:"vendor"`
}

type CouchConnectionDef

CouchConnectionDef contains parameters

type CouchConnectionDef struct {
    URL                   string
    Username              string
    Password              string
    MaxRetries            int
    MaxRetriesOnStartup   int
    RequestTimeout        time.Duration
    CreateGlobalChangesDB bool
}

func CreateConnectionDefinition

func CreateConnectionDefinition(couchDBAddress, username, password string, maxRetries,
    maxRetriesOnStartup int, requestTimeout time.Duration, createGlobalChangesDB bool) (*CouchConnectionDef, error)

CreateConnectionDefinition for a new client connection

type CouchDBDef

CouchDBDef contains parameters

type CouchDBDef struct {
    URL                   string
    Username              string
    Password              string
    MaxRetries            int
    MaxRetriesOnStartup   int
    RequestTimeout        time.Duration
    CreateGlobalChangesDB bool
}

func GetCouchDBDefinition

func GetCouchDBDefinition() *CouchDBDef

GetCouchDBDefinition exposes the useCouchDB variable

type CouchDatabase

CouchDatabase represents a database within a CouchDB instance

type CouchDatabase struct {
    CouchInstance    *CouchInstance //connection configuration
    DBName           string
    IndexWarmCounter int
}

func CreateCouchDatabase

func CreateCouchDatabase(couchInstance *CouchInstance, dbName string) (*CouchDatabase, error)

CreateCouchDatabase creates a CouchDB database object, as well as the underlying database if it does not exist

func (*CouchDatabase) ApplyDatabaseSecurity

func (dbclient *CouchDatabase) ApplyDatabaseSecurity(databaseSecurity *DatabaseSecurity) error

ApplyDatabaseSecurity method provides function to update the security config for a database

func (*CouchDatabase) BatchRetrieveDocumentMetadata

func (dbclient *CouchDatabase) BatchRetrieveDocumentMetadata(keys []string) ([]*DocMetadata, error)

BatchRetrieveDocumentMetadata - batch method to retrieve document metadata for a set of keys, including ID, couchdb revision number, and ledger version

func (*CouchDatabase) BatchUpdateDocuments

func (dbclient *CouchDatabase) BatchUpdateDocuments(documents []*CouchDoc) ([]*BatchUpdateResponse, error)

BatchUpdateDocuments - batch method to batch update documents

func (*CouchDatabase) CreateDatabaseIfNotExist

func (dbclient *CouchDatabase) CreateDatabaseIfNotExist() error

CreateDatabaseIfNotExist method provides function to create database

func (*CouchDatabase) CreateIndex

func (dbclient *CouchDatabase) CreateIndex(indexdefinition string) (*CreateIndexResponse, error)

CreateIndex method provides a function creating an index

func (*CouchDatabase) DeleteDoc

func (dbclient *CouchDatabase) DeleteDoc(id, rev string) error

DeleteDoc method provides function to delete a document from the database by id

func (*CouchDatabase) DeleteIndex

func (dbclient *CouchDatabase) DeleteIndex(designdoc, indexname string) error

DeleteIndex method provides a function deleting an index

func (*CouchDatabase) DropDatabase

func (dbclient *CouchDatabase) DropDatabase() (*DBOperationResponse, error)

DropDatabase provides method to drop an existing database

func (*CouchDatabase) EnsureFullCommit

func (dbclient *CouchDatabase) EnsureFullCommit() (*DBOperationResponse, error)

EnsureFullCommit calls _ensure_full_commit for explicit fsync

func (*CouchDatabase) GetDatabaseInfo

func (dbclient *CouchDatabase) GetDatabaseInfo() (*DBInfo, *DBReturn, error)

GetDatabaseInfo method provides function to retrieve database information

func (*CouchDatabase) GetDatabaseSecurity

func (dbclient *CouchDatabase) GetDatabaseSecurity() (*DatabaseSecurity, error)

GetDatabaseSecurity method provides function to retrieve the security config for a database

func (*CouchDatabase) ListIndex

func (dbclient *CouchDatabase) ListIndex() ([]*IndexResult, error)

ListIndex method lists the defined indexes for a database

func (*CouchDatabase) QueryDocuments

func (dbclient *CouchDatabase) QueryDocuments(query string) ([]*QueryResult, string, error)

QueryDocuments method provides function for processing a query

func (*CouchDatabase) ReadDoc

func (dbclient *CouchDatabase) ReadDoc(id string) (*CouchDoc, string, error)

ReadDoc method provides function to retrieve a document and its revision from the database by id

func (*CouchDatabase) ReadDocRange

func (dbclient *CouchDatabase) ReadDocRange(startKey, endKey string, limit int32) ([]*QueryResult, string, error)

ReadDocRange method provides function to a range of documents based on the start and end keys startKey and endKey can also be empty strings. If startKey and endKey are empty, all documents are returned This function provides a limit option to specify the max number of entries and is supplied by config. Skip is reserved for possible future future use.

func (*CouchDatabase) SaveDoc

func (dbclient *CouchDatabase) SaveDoc(id string, rev string, couchDoc *CouchDoc) (string, error)

SaveDoc method provides a function to save a document, id and byte array

func (*CouchDatabase) WarmIndex

func (dbclient *CouchDatabase) WarmIndex(designdoc, indexname string) error

WarmIndex method provides a function for warming a single index

func (*CouchDatabase) WarmIndexAllIndexes

func (dbclient *CouchDatabase) WarmIndexAllIndexes() error

WarmIndexAllIndexes method provides a function for warming all indexes for a database

type CouchDoc

CouchDoc defines the structure for a JSON document value

type CouchDoc struct {
    JSONValue   []byte
    Attachments []*AttachmentInfo
}

type CouchInstance

CouchInstance represents a CouchDB instance

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

func CreateCouchInstance

func CreateCouchInstance(couchDBConnectURL, id, pw string, maxRetries,
    maxRetriesOnStartup int, connectionTimeout time.Duration, createGlobalChangesDB bool, metricsProvider metrics.Provider) (*CouchInstance, error)

CreateCouchInstance creates a CouchDB instance

func (*CouchInstance) HealthCheck

func (couchInstance *CouchInstance) HealthCheck(ctx context.Context) error

HealthCheck checks if the peer is able to communicate with CouchDB

func (*CouchInstance) VerifyCouchConfig

func (couchInstance *CouchInstance) VerifyCouchConfig() (*ConnectionInfo, *DBReturn, error)

VerifyCouchConfig method provides function to verify the connection information

type CreateIndexResponse

CreateIndexResponse contains an the index creation response from CouchDB

type CreateIndexResponse struct {
    Result string `json:"result"`
    ID     string `json:"id"`
    Name   string `json:"name"`
}

type DBInfo

DBInfo is body for database information.

type DBInfo struct {
    DbName string `json:"db_name"`
    Sizes  struct {
        File     int `json:"file"`
        External int `json:"external"`
        Active   int `json:"active"`
    } `json:"sizes"`
    Other struct {
        DataSize int `json:"data_size"`
    } `json:"other"`
    DocDelCount       int    `json:"doc_del_count"`
    DocCount          int    `json:"doc_count"`
    DiskSize          int    `json:"disk_size"`
    DiskFormatVersion int    `json:"disk_format_version"`
    DataSize          int    `json:"data_size"`
    CompactRunning    bool   `json:"compact_running"`
    InstanceStartTime string `json:"instance_start_time"`
}

type DBOperationResponse

DBOperationResponse is body for successful database calls.

type DBOperationResponse struct {
    Ok bool
    // contains filtered or unexported fields
}

type DBReturn

DBReturn contains an error reported by CouchDB

type DBReturn struct {
    StatusCode int    `json:"status_code"`
    Error      string `json:"error"`
    Reason     string `json:"reason"`
}

type DatabaseSecurity

DatabaseSecurity contains the definition for CouchDB database security

type DatabaseSecurity struct {
    Admins struct {
        Names []string `json:"names"`
        Roles []string `json:"roles"`
    } `json:"admins"`
    Members struct {
        Names []string `json:"names"`
        Roles []string `json:"roles"`
    } `json:"members"`
}

type DocID

DocID is a minimal structure for capturing the ID from a query result

type DocID struct {
    ID string `json:"_id"`
}

type DocMetadata

DocMetadata is used for capturing CouchDB document header info, used to capture id, version, rev and attachments returned in the query from CouchDB

type DocMetadata struct {
    ID              string                     `json:"_id"`
    Rev             string                     `json:"_rev"`
    Version         string                     `json:"~version"`
    AttachmentsInfo map[string]*AttachmentInfo `json:"_attachments"`
}

type FileDetails

FileDetails defines the structure needed to send an attachment to couchdb

type FileDetails struct {
    Follows     bool   `json:"follows"`
    ContentType string `json:"content_type"`
    Length      int    `json:"length"`
}

type IndexResult

IndexResult contains the definition for a couchdb index

type IndexResult struct {
    DesignDocument string `json:"designdoc"`
    Name           string `json:"name"`
    Definition     string `json:"definition"`
}

type QueryResponse

QueryResponse is used for processing REST query responses from CouchDB

type QueryResponse struct {
    Warning  string            `json:"warning"`
    Docs     []json.RawMessage `json:"docs"`
    Bookmark string            `json:"bookmark"`
}

type QueryResult

QueryResult is used for returning query results from CouchDB

type QueryResult struct {
    ID          string
    Value       []byte
    Attachments []*AttachmentInfo
}

type RangeQueryResponse

RangeQueryResponse is used for processing REST range query responses from CouchDB

type RangeQueryResponse struct {
    TotalRows int32 `json:"total_rows"`
    Offset    int32 `json:"offset"`
    Rows      []struct {
        ID    string `json:"id"`
        Key   string `json:"key"`
        Value struct {
            Rev string `json:"rev"`
        } `json:"value"`
        Doc json.RawMessage `json:"doc"`
    } `json:"rows"`
}