pillow

package
v0.0.0-...-ca030e2 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2021 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package pillow provides a generic interface to CouchDB.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ID

func ID(id string) string

func StatusCode

func StatusCode(err error) int

StatusCode returns the HTTP status code embedded in the error, or 500 (internal server error), if there was no specified status code. If err is nil, StatusCode returns 0. This provides a convenient way to determine the precise nature of a Kivik-returned error.

For example, to panic for all but NotFound errors:

err := db.Get(context.TODO(), "docID").ScanDoc(&doc)
if pillow.StatusCode(err) == pillow.StatusNotFound {
    return
}
if err != nil {
    panic(err)
}

This method uses the statusCoder interface, which is not exported by this package, but is considered part of the stable public API. Driver implementations are expected to return errors which conform to this interface.

type statusCoder interface {
    StatusCode() (httpStatusCode int)
}

Types

type Client

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

Client

func New

func New(dsn string, opts ...*ClientOptions) (*Client, error)

New

func (*Client) DSN

func (client *Client) DSN() string

DSN returns the data source name used to connect this client.

func (*Client) Database

func (client *Client) Database(ctx context.Context, name string) (db *DB)

Database

func (*Client) ListDatabases

func (client *Client) ListDatabases(ctx context.Context, options ...map[string]interface{}) (databases []string, err error)

ListDatabases

func (*Client) Ping

func (client *Client) Ping(ctx context.Context) (pong bool, err error)

Ping

type ClientOptions

type ClientOptions struct {
	Timeout int
}

ClientOptions

type CreateDatabaseResponse

type CreateDatabaseResponse struct {
	OK     bool   `json:"ok,omitempty"`
	Error  string `json:"error,omitempty"`
	Reason string `json:"reason,omitempty"`
}

type DB

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

func (*DB) CheckDocument

func (db *DB) CheckDocument(ctx context.Context, id string, options ...map[string]interface{}) (exists bool, err error)

CheckDocument

func (*DB) Client

func (db *DB) Client() *Client

Client

func (*DB) Create

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

Create {"ok":true} {"error":"file_exists","reason":"The database could not be created, the file already exists."}

func (*DB) CreateDesignDocument

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

func (*DB) CreateDocument

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

CreateDocument

func (*DB) Delete

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

Delete {"ok":true}

func (*DB) DeleteDocument

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

DeleteDocument

func (*DB) Exists

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

Exists

func (*DB) ListDocuments

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

ListDocuments

func (*DB) Name

func (db *DB) Name() string

Name

func (*DB) Query

func (db *DB) Query(ctx context.Context, ddcoc, view string, options ...map[string]interface{}) (output map[string]interface{}, err error)

Query

func (*DB) RetrieveDocument

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

RetrieveDocument

func (*DB) UpdateDocument

func (db *DB) UpdateDocument(ctx context.Context, id string, document interface{}, options ...map[string]interface{}) (output map[string]interface{}, err error)

UpdateDocument

type DeleteDatabaseResponse

type DeleteDatabaseResponse struct {
	OK     bool   `json:"ok,omitempty"`
	Error  string `json:"error,omitempty"`
	Reason string `json:"reason,omitempty"`
}

type Error

type Error struct {
	// HTTPStatus is the HTTP status code associated with this error. Normally
	// this is the actual HTTP status returned by the server, but in some cases
	// it may be generated by Kivik directly. Check the FromServer value if
	// the distinction matters to you.
	HTTPStatus int

	// Message is the error message.
	Message string

	// Err is the originating error, if any.
	Err error
}

Error represents an error returned by Kivik.

This type definition is not guaranteed to remain stable, or even exported. When examining errors programatically, you should rely instead on the StatusCode() function in this package, rather than on directly observing the fields of this type.

func (*Error) Cause

func (e *Error) Cause() error

Cause satisfies the github.com/pkg/errors.causer interface by returning e.Err.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Format

func (e *Error) Format(f fmt.State, c rune)

Format implements fmt.Formatter

func (*Error) StatusCode

func (e *Error) StatusCode() int

StatusCode returns the HTTP status code associated with the error, or 500 (internal server error), if none.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap satisfies the Go 1.13 errors.Wrapper interface (golang.org/x/xerrors.Unwrap for older versions of Go).

Jump to

Keyboard shortcuts

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