bindings

package
v3.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package bindings provides minimal GopherJS bindings around the PouchDB library. (https://pouchdb.com/api.html)

Index

Constants

View Source
const (
	ReplicationEventChange   = "change"
	ReplicationEventComplete = "complete"
	ReplicationEventPaused   = "paused"
	ReplicationEventActive   = "active"
	ReplicationEventDenied   = "denied"
	ReplicationEventError    = "error"
)

Replication events

Variables

This section is empty.

Functions

func NewPouchError

func NewPouchError(o *js.Object) error

NewPouchError parses a PouchDB error.

func Objectify

func Objectify(i interface{}) (interface{}, error)

Objectify unmarshals a string, []byte, or json.RawMessage into an interface{}. All other types are just passed through.

func RecoverError

func RecoverError(err *error)

RecoverError recovers from a thrown JS error. If an error is caught, err is set to its value.

To use, put this at the beginning of a function:

defer RecoverError(&err)

Types

type DB

type DB struct {
	*js.Object
}

DB is a PouchDB database object.

func (*DB) AllDocs

func (db *DB) AllDocs(ctx context.Context, options map[string]interface{}) (*js.Object, error)

AllDocs returns a list of all documents in the database.

func (*DB) BulkDocs

func (db *DB) BulkDocs(ctx context.Context, docs []interface{}, options map[string]interface{}) (result *js.Object, err error)

BulkDocs creates, updates, or deletes docs in bulk. See https://pouchdb.com/api.html#batch_create

func (*DB) Changes

func (db *DB) Changes(ctx context.Context, options map[string]interface{}) (changes *js.Object, e error)

Changes returns an event emitter object.

See https://pouchdb.com/api.html#changes

func (*DB) Close

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

func (*DB) Compact

func (db *DB) Compact() error

Compact compacts the database, and waits for it to complete. This may take a long time! Please wrap this call in a goroutine.

func (*DB) CreateIndex

func (db *DB) CreateIndex(ctx context.Context, index interface{}) (*js.Object, error)

CreateIndex creates an index to be used by MongoDB-style queries with the pouchdb-find plugin, if it is installed. If the plugin is not installed, a NotImplemented error will be returned.

See https://github.com/pouchdb/pouchdb/tree/master/packages/node_modules/pouchdb-find#dbcreateindexindex--callback

func (*DB) Delete

func (db *DB) Delete(ctx context.Context, docID, rev string, opts map[string]interface{}) (newRev string, err error)

Delete marks a document as deleted. See https://pouchdb.com/api.html#delete_document

func (*DB) DeleteIndex

func (db *DB) DeleteIndex(ctx context.Context, index interface{}) (*js.Object, error)

DeleteIndex deletes an index used by the MongoDB-style queries with the pouchdb-find plugin, if it is installed. If the plugin is not installed, a NotImplemeneted error will be returned.

See: https://github.com/pouchdb/pouchdb/tree/master/packages/node_modules/pouchdb-find#dbdeleteindexindex--callback

func (*DB) Destroy

func (db *DB) Destroy(ctx context.Context, options map[string]interface{}) error

Destroy destroys the database.

func (*DB) Explain

func (db *DB) Explain(ctx context.Context, query interface{}) (*js.Object, error)

Explain the query plan for a given query

See https://pouchdb.com/api.html#explain_index

func (*DB) Find

func (db *DB) Find(ctx context.Context, query interface{}) (*js.Object, error)

Find executes a MongoDB-style find query with the pouchdb-find plugin, if it is installed. If the plugin is not installed, a NotImplemented error will be returned.

See https://github.com/pouchdb/pouchdb/tree/master/packages/node_modules/pouchdb-find#dbfindrequest--callback

func (*DB) Get

func (db *DB) Get(ctx context.Context, docID string, opts map[string]interface{}) (doc []byte, rev string, err error)

Get fetches the requested document from the database. See https://pouchdb.com/api.html#fetch_document

func (*DB) GetAttachment

func (db *DB) GetAttachment(ctx context.Context, docID, filename string, options map[string]interface{}) (*js.Object, error)

GetAttachment returns attachment data.

See https://pouchdb.com/api.html#get_attachment

func (*DB) GetIndexes

func (db *DB) GetIndexes(ctx context.Context) (*js.Object, error)

GetIndexes returns the list of currently defined indexes on the database.

See https://github.com/pouchdb/pouchdb/tree/master/packages/node_modules/pouchdb-find#dbgetindexescallback

func (*DB) Info

func (db *DB) Info(ctx context.Context) (*DBInfo, error)

Info returns info about the database.

func (*DB) Post

func (db *DB) Post(ctx context.Context, doc interface{}, opts map[string]interface{}) (docID, rev string, err error)

Post creates a new document and lets PouchDB auto-generate the ID. See https://pouchdb.com/api.html#using-dbpost

func (*DB) Put

func (db *DB) Put(ctx context.Context, doc interface{}, opts map[string]interface{}) (rev string, err error)

Put creates a new document or update an existing document. See https://pouchdb.com/api.html#create_document

func (*DB) PutAttachment

func (db *DB) PutAttachment(ctx context.Context, docID, filename, rev string, body io.Reader, ctype string) (*js.Object, error)

PutAttachment attaches a binary object to a document.

See https://pouchdb.com/api.html#save_attachment

func (*DB) Query

func (db *DB) Query(ctx context.Context, ddoc, view string, options map[string]interface{}) (*js.Object, error)

Query queries a map/reduce function.

func (*DB) RemoveAttachment

func (db *DB) RemoveAttachment(ctx context.Context, docID, filename, rev string) (*js.Object, error)

RemoveAttachment deletes an attachment from a document.

See https://pouchdb.com/api.html#delete_attachment

func (*DB) ViewCleanup

func (db *DB) ViewCleanup() error

ViewCleanup cleans up views, and waits for it to complete. This may take a long time! Please wrap this call in a goroutine.

type DBInfo

type DBInfo struct {
	*js.Object
	Name      string `js:"db_name"`
	DocCount  int64  `js:"doc_count"`
	UpdateSeq string `js:"update_seq"`
}

DBInfo is a struct respresenting information about a specific database.

type PouchDB

type PouchDB struct {
	*js.Object
}

PouchDB represents a PouchDB constructor.

func Defaults

func Defaults(options map[string]interface{}) *PouchDB

Defaults returns a new PouchDB constructor with the specified default options. See https://pouchdb.com/api.html#defaults

func GlobalPouchDB

func GlobalPouchDB() *PouchDB

GlobalPouchDB returns the global PouchDB object.

func (*PouchDB) AllDBs

func (p *PouchDB) AllDBs(ctx context.Context) ([]string, error)

AllDBs returns the list of all existing (undeleted) databases.

func (*PouchDB) New

func (p *PouchDB) New(dbName string, options map[string]interface{}) *DB

New creates a database or opens an existing one.

See https://pouchdb.com/api.html#create_database

func (*PouchDB) Replicate

func (p *PouchDB) Replicate(source, target interface{}, options map[string]interface{}) (result *js.Object, err error)

Replicate initiates a replication. See https://pouchdb.com/api.html#replication

func (*PouchDB) Version

func (p *PouchDB) Version() string

Version returns the version of the currently running PouchDB library.

Directories

Path Synopsis
Package poucherr exists only for the purpose of testing the PouchDB binding's handling of PouchDB-specific error messages.
Package poucherr exists only for the purpose of testing the PouchDB binding's handling of PouchDB-specific error messages.

Jump to

Keyboard shortcuts

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