Documentation
¶
Overview ¶
Package pouchdb provides GopherJS bindings for PouchDB. Whenever possible, the PouchDB function calls have been made more Go idiomatic. This means:
- They don't take optional arguments. Where appropriate, multiple versions of a function exist with different argument lists.
- They don't use call backs or return Promises
- They have been made synchronous. If you need asynchronous operation, wrap your calls in goroutines
- They return errors as the last return value (Go style) rather than the first (JS style)
Index ¶
- Variables
- func ConvertJSONObject(input, output interface{}) error
- func ConvertJSObject(jsObj *js.Object, output interface{}) error
- func Debug(module string)
- func DebugDisable()
- func ErrorMessage(err error) string
- func ErrorName(err error) string
- func ErrorReason(err error) string
- func ErrorStatus(err error) int
- func IsConflict(err error) bool
- func IsNotExist(err error) bool
- func IsPouchError(err error) bool
- func IsWarning(err error) bool
- func NewPouchError(err *js.Error) error
- func NewResultWaiter() *resultWaiter
- func OnCreate(fn func(dbName string))
- func OnDestroy(fn func(dbName string))
- func Plugin(plugin *js.Object)
- type Attachment
- type DBInfo
- type MapFunc
- type Options
- type PouchDB
- func (db *PouchDB) AllDocs(result interface{}, opts Options) error
- func (db *PouchDB) Attachment(docid, name, rev string) (*Attachment, error)
- func (db *PouchDB) BulkDocs(docs interface{}, opts Options) ([]Result, error)
- func (db *PouchDB) Call(name string, args ...interface{}) *js.Object
- func (db *PouchDB) Compact(opts Options) error
- func (db *PouchDB) DeleteAttachment(docid, name, rev string) (newrev string, err error)
- func (db *PouchDB) Destroy(opts Options) error
- func (db *PouchDB) Get(docId string, doc interface{}, opts Options) error
- func (db *PouchDB) GetJS(name string) *js.Object
- func (db *PouchDB) Info() (DBInfo, error)
- func (db *PouchDB) Put(doc interface{}) (newrev string, err error)
- func (db *PouchDB) PutAttachment(docid string, att *Attachment, rev string) (newrev string, err error)
- func (db *PouchDB) Query(view string, result interface{}, opts Options) error
- func (db *PouchDB) QueryFunc(fn MapFunc, result interface{}, opts Options) error
- func (db *PouchDB) Remove(doc interface{}, opts Options) (newrev string, err error)
- func (db *PouchDB) ViewCleanup() error
- type PouchError
- type Result
- type Warning
Constants ¶
This section is empty.
Variables ¶
var GlobalPouch *js.Object
GlobalPouch is the global pouchdb object. The package will look for it in the global object (js.Global), or try to require it if it is not found. If this does not work for you, you ought to set it explicitly yourself:
pouchdb.GlobalPouch = js.Global.Call("require", "/path/to/your/copy/of/pouchdb")
Functions ¶
func ConvertJSONObject ¶
func ConvertJSONObject(input, output interface{}) error
ConvertJSONObject takes an intterface{} and runs it through json.Marshal() and json.Unmarshal() so that any struct tags will be applied.
func ConvertJSObject ¶
convertJSObject converts the provided *js.Object to an interface{} then calls convertJSONObject. This is necessary for objects, because json.Marshal ignores any unexported fields in objects, and this includes practically everything inside a js.Object.
func Debug ¶
func Debug(module string)
Debug enables debugging for the specified module. Note this only affects connections made after this is run. See: http://pouchdb.com/api.html#debug_mode
func ErrorMessage ¶
ErrorMessage returns the message portion of a PouchError, or "" for other errors
func ErrorReason ¶
ErrorReason returns the reason portion of a PouchError, or "" for other errors
func ErrorStatus ¶
ErrorStatus returns the status of a PouchError, or 0 for other errors
func IsConflict ¶
IsConflict returns true if the passed error is a PouchError with a status of 409 (conflict)
func IsNotExist ¶
IsNotExist returns true if the passed error represents a PouchError with a status of 404 (not found)
func IsPouchError ¶
IsPouchError returns true if the passed error is a PouchError, false if it is any other type of error.
func NewPouchError ¶
NewPouchError creates a new PouchError from a js.Error object returned from the PouchDB library
func NewResultWaiter ¶
func NewResultWaiter() *resultWaiter
func OnCreate ¶
func OnCreate(fn func(dbName string))
OnCreate registers the function as an event listener for the 'created' event. See https://pouchdb.com/api.html#events
func OnDestroy ¶
func OnDestroy(fn func(dbName string))
OnDestroy registers the function as an event listener for the 'destroyed' event. See https://pouchdb.com/api.html#events
Types ¶
type Attachment ¶
type Attachment struct { Name string // File name Type string // MIME type of the Body MD5 []byte // MD5 checksum of the Body Body io.Reader // The body itself }
Attachment represents document attachments. This structure is borrowed from http://godoc.org/github.com/fjl/go-couchdb#Attachment
type Options ¶
type Options struct { // This turns on auto compaction, which means compact() is called after // every change to the database. Defaults to false. // // Used by New(), for local databases only AutoCompaction bool // One of 'idb', 'leveldb', 'websql', or 'http'. If unspecified, PouchDB // will infer this automatically, preferring IndexedDB to WebSQL in // browsers that support both. // // Used by New(), for local databases only. Adapter string // See https://github.com/Level/levelup#options DB *js.Object // Specify how many old revisions we keep track (not a copy) of. // // Used by New(), for local databases only. RevsLimit int // Remote databases only.) Ajax requester options. These are passed // verbatim to request (in Node.js) or a request shim (in the browser), // with the exception of 'cache'. // - cache: Appends a random string to the end of all HTTP GET requests // to avoid them being cached on IE. Set this to true to prevent this // happening. // - headers: Allows you to customise headers that are sent to the remote // HTTP Server. // - username + password: Alternate method to provide auth credentians to // using a database name in the form `http://user:pass@host/name` // - withCredentials: Set to false to disable transferring cookies or HTTP // Auth information. Defaults to true. // - skip_setup: Initially PouchDB checks if the database exists, and // tries to create it, if it does not exist yet. Set this to true to skip // this setup. // // Used by any method that accesses a remote database. Ajax map[string]interface{} // Specifies whether you want to use persistent or temporary storage. // // Used by New(), for IndexedDB only. Storage string // Amount in MB to request for storage, which you will need if you are // storing >5MB in order to avoid storage limit errors on iOS/Safari. // // Used by New(), for WebSQL only. Size int // Fetch specific revision of a document. Defaults to winning revision. // // Used by Get(). Rev string // Include revision history of the document. // // Used by Get(). Revs bool // Include a list of revisions of the document, and their availability. // // Used by Get(). RevsInfo bool // Fetch requested leaf revisions in the order specified. // // Used by Get(). OpenRevs []string // Fetch all leaf revisions. // // Used by Get(). AllOpenRevs bool // If specified, conflicting leaf revisions will be attached in _conflicts // array. // // Used by Get(), AllDocs() and Query(). Conflicts bool // Include attachment data. // // Used by Get(), AllDocs() and Query(). Attachments bool // Include the document itself in each row in the doc field. The default // is to only return the _id and _rev properties. // // Used by AllDocs() and Query(). IncludeDocs bool // Get documents with IDs in a certain range (inclusive/inclusive). // // Used by AllDocs() and Query(). StartKey string EndKey string // Exclude documents having an ID equal to the given EndKey. // Note this flag has the reverse sense of the PouchDB inclusive_end flag. // // Used by AllDocs() and Query(). ExclusiveEnd bool // Maximum number of documents to return. // // Used by AllDocs() and Query() Limit int // Number of docs to skip before returning. // // Used by AllDocs() and Query(). Skip int // Reverse the order of the output documents. Note that the order of // StartKey and EndKey is reversed when Descending is true. // // Used by AllDocs() and Query(). Descending bool // Only return documents with IDs matching this string. // // Used by AllDocs() and Query(). Key string // Array of string keys to fetch in a single shot. // - Neither StartKey nor EndKey can be specified with this option. // - The rows are returned in the same order as the supplied keys array. // - The row for a deleted document will have the revision ID of the // deletion, and an extra key "deleted":true in the value property. // - The row for a nonexistent document will just contain an "error" // property with the value "not_found". // - For details, see the CouchDB query options documentation: // http://wiki.apache.org/couchdb/HTTP_view_API#Querying_Options // // Used by AllDocs() and Query(). Keys []string // Reference a filter function from a design document to selectively get // updates. To use a view function, pass _view here and provide a reference // to the view function in options.view. // See also: https://pouchdb.com/api.html#filtered-replication // // Used by Replicate() Filter string // Only show changes for docs with these ids (array of strings). // // Used by Replicate(). DocIDs []string // Object containing properties that are passed to the filter function, // e.g. {"foo":"bar"}. // // Used by Replicate(). QueryParams map[string]interface{} // Specify a view function (e.g. 'design_doc_name/view_name' or 'view_name' // as shorthand for 'view_name/view_name') to act as a filter. // // Used by Replicate(). View string // Replicate changes after the given sequence number. // // Used by Replicate(). Since int64 Heartbeat int64 Timeout int64 BatchSize int BatchesLimit int BackOffFunction func(int) int // The name of a view in an existing design document (e.g. // 'mydesigndoc/myview', or 'myview' as a shorthand for 'myview/myview'). // // Used by Query(). MapFuncName string // A JavaScript object representing a map function. It is not possible to // define map functions in GopherJS. // // Used by Query() MapFunc *js.Object // The name of a built-in reduce function: '_sum', '_count', or '_stats'. // // Used by Query() ReduceFuncName string // A JavaScript object representing a reduce function. It is not possible // to define reduce functions in GopherJS. // // Used by Query() ReduceFunc *js.Object // True if you want the reduce function to group results by keys, rather // than returning a single result. // // Used by Query(). Group bool // Number of elements in a key to group by, assuming the keys are arrays. // Defaults to the full length of the array. // // Used by Query(). GroupLevel int // Only applies to saved views. Can be one of: // - unspecified (default): Returns the latest results, waiting for the // view to build if necessary. // - 'ok': Returns results immediately, even if they’re out-of-date. // - 'update_after': Returns results immediately, but kicks off a build // afterwards. // // Used by Query(). Stale string }
Options represents the optional configuration options for a PouchDB operation.
type PouchDB ¶
type PouchDB struct {
// contains filtered or unexported fields
}
func New ¶
New creates a database or opens an existing one. See: http://pouchdb.com/api.html#create_database
func NewWithOpts ¶
NewWithOpts creates a database or opens an existing one. See: http://pouchdb.com/api.html#create_database
func (*PouchDB) AllDocs ¶
AllDocs will fetch multiple documents. The output of the query is unmarshalled into the given result. The format of the result depends on the options. Please refer to the CouchDB HTTP API documentation for all the possible options that can be set.
See http://pouchdb.com/api.html#batch_fetch and http://docs.couchdb.org/en/latest/api/database/bulk-api.html#db-all-docs
func (*PouchDB) Attachment ¶
func (db *PouchDB) Attachment(docid, name, rev string) (*Attachment, error)
Attachment retrieves an attachment. The rev argument can be left empty to retrieve the latest revision. The caller is responsible for closing the attachment's Body if the returned error is nil.
Note that PouchDB's getDocument() does not fetch meta data (except for the MIME type in the browser only), so the MD5 sum and (in node) the content type fields will be empty.
See http://pouchdb.com/api.html#get_attachment and http://godoc.org/github.com/fjl/go-couchdb#Attachment
func (*PouchDB) Call ¶
Call calls the underlying PouchDB object's method with the given name and arguments. This method is used internally, and may also facilitate the use of plugins which may add methods to PouchDB which are not implemented in the GopherJS bindings.
func (*PouchDB) DeleteAttachment ¶
func (*PouchDB) Destroy ¶
Deestroy will delete the database. See: http://pouchdb.com/api.html#delete_database
func (*PouchDB) Get ¶
Get retrieves a document, specified by docId. The document is unmarshalled into the given object. Some fields (like _conflicts) will only be returned if the options require it. Please refer to the CouchDB HTTP API documentation for more information.
See http://pouchdb.com/api.html#fetch_document and http://docs.couchdb.org/en/latest/api/document/common.html?highlight=doc#get--db-docid
func (*PouchDB) Put ¶
Put will create a new document or update an existing document. See: http://pouchdb.com/api.html#create_document
func (*PouchDB) PutAttachment ¶
func (db *PouchDB) PutAttachment(docid string, att *Attachment, rev string) (newrev string, err error)
PutAttachment creates or updates an attachment. To create an attachment on a non-existing document, pass an empty rev.
See http://pouchdb.com/api.html#save_attachment and http://godoc.org/github.com/fjl/go-couchdb#DB.PutAttachment
func (*PouchDB) Query ¶
Invoke a map/reduce function, which allows you to perform more complex queries on PouchDB than what you get with allDocs().
func (*PouchDB) Remove ¶
Remove will delete the document. The document must specify both _id and _rev. On success, it returns the _rev of the new document with _delete set to true.
func (*PouchDB) ViewCleanup ¶
ViewCleanup cleans up any stale map/reduce indexes.
type PouchError ¶
type PouchError struct { Status int `js:"status"` Message string `js:"message"` Name string `js:"name"` IsError bool `js:"isError"` Reason string `js:"reason"` // contains filtered or unexported fields }
PouchError records an error returned by the PouchDB library
func (*PouchError) Error ¶
func (e *PouchError) Error() string
Error satisfies the error interface for the PouchError type
func (*PouchError) Underlying ¶
func (e *PouchError) Underlying() *js.Error
Underlying returns the underlying js.Error object, as returned from the PouchDB library