couchdb

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2018 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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

Types

type Attachment

type Attachment struct {
	Name            string
	ContentType     string
	Length          uint64
	AttachmentBytes []byte
}

Attachment contains the definition for an attached file for couchdb

type Base64Attachment

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

Base64Attachment contains the definition for an attached file for couchdb

type BatchRetrieveDocMedatadataResponse

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

BatchRetrieveDocMedatadataResponse is used for processing REST batch responses from CouchDB

type BatchUpdateResponse

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

BatchUpdateResponse defines a structure for batch update response

type ConnectionInfo

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

ConnectionInfo is a structure for capturing the database info and version

type CouchConnectionDef

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

CouchConnectionDef contains parameters

func CreateConnectionDefinition

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

CreateConnectionDefinition for a new client connection

type CouchDBDef

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

CouchDBDef contains parameters

func GetCouchDBDefinition

func GetCouchDBDefinition() *CouchDBDef

GetCouchDBDefinition exposes the useCouchDB variable

type CouchDatabase

type CouchDatabase struct {
	CouchInstance CouchInstance //connection configuration
	DBName        string
}

CouchDatabase represents a database within a CouchDB instance

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) BatchRetrieveIDRevision

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

BatchRetrieveIDRevision - batch method to retrieve IDs and revisions

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() (*DBOperationResponse, error)

CreateDatabaseIfNotExist method provides function to create database

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) 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) QueryDocuments

func (dbclient *CouchDatabase) QueryDocuments(query string) (*[]QueryResult, 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, skip int) (*[]QueryResult, 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

type CouchDoc

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

CouchDoc defines the structure for a JSON document value

type CouchInstance

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

CouchInstance represents a CouchDB instance

func CreateCouchInstance

func CreateCouchInstance(couchDBConnectURL, id, pw string, maxRetries,
	maxRetriesOnStartup int, connectionTimeout time.Duration) (*CouchInstance, error)

CreateCouchInstance creates a CouchDB instance

func (*CouchInstance) VerifyCouchConfig

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

VerifyCouchConfig method provides function to verify the connection information

type DBInfo

type DBInfo struct {
	DbName    string `json:"db_name"`
	UpdateSeq string `json:"update_seq"`
	Sizes     struct {
		File     int `json:"file"`
		External int `json:"external"`
		Active   int `json:"active"`
	} `json:"sizes"`
	PurgeSeq int `json:"purge_seq"`
	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"`
}

DBInfo is body for database information.

type DBOperationResponse

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

DBOperationResponse is body for successful database calls.

type DBReturn

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

DBReturn contains an error reported by CouchDB

type Doc

type Doc struct {
	ID          string          `json:"_id"`
	Rev         string          `json:"_rev"`
	Attachments json.RawMessage `json:"_attachments"`
}

Doc is used for capturing if attachments are return in the query from CouchDB

type DocID

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

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

type DocMetadata

type DocMetadata struct {
	ID      string
	Rev     string
	Version string
}

DocMetadata returns the ID, version and revision for a couchdb document

type FileDetails

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

FileDetails defines the structure needed to send an attachment to couchdb

type QueryResponse

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

QueryResponse is used for processing REST query responses from CouchDB

type QueryResult

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

QueryResult is used for returning query results from CouchDB

type RangeQueryResponse

type RangeQueryResponse struct {
	TotalRows int `json:"total_rows"`
	Offset    int `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"`
}

RangeQueryResponse is used for processing REST range query responses from CouchDB

Jump to

Keyboard shortcuts

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