couchdb

package module
v0.0.0-...-486a684 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: MIT Imports: 8 Imported by: 0

README

couchdb

CouchDB client

Go Reference

Usage

Install with:

go get github.com/tetsuo/couchdb

Then use it like this:

package main

import (
	"context"
	"github.com/tetsuo/couchdb"
)

func main() {
	client := couchdb.NewClient("http://localhost:5984")

	// Create services
	dbs := couchdb.NewDatabaseService(client) // or client.Databases()
	docs := couchdb.Documents()

	ctx := context.Background()

	// Admin creates database
	dbs.CreateDatabase(ctx, "users_db", nil,
		couchdb.WithBasicAuth("admin", "adminpass"))

	// User creates document
	doc := map[string]any{
		"name":  "John Doe",
		"email": "john@example.com",
	}
	docs.CreateDocument(ctx, "users_db", doc, nil,
		couchdb.WithBasicAuth("john", "johnpass"))

	// Different user with JWT token
	docs.GetDocument(ctx, "users_db", "doc123", nil,
		couchdb.WithJWTAuth("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."))
}

Authentication

Supported authentication methods:

  • WithBasicAuth(username, password string) — HTTP Basic Auth
  • WithJWTAuth(token string) — JWT Bearer token
  • WithCookieAuth(cookie *http.Cookie) — Session cookie
  • WithProxyAuth(username string, roles []string, token string) — Proxy auth

FAQ

Which CouchDB versions are supported?

Tested with CouchDB v3.5.x, but should work with other 3.x versions as well.

Is every CouchDB API covered?

Not yet. If you need a specific API that is not implemented, feel free to open an issue or contribute a PR. For example, cluster and replication APIs are not yet implemented.

Documentation

Full API documentation is at pkg.go.dev.

Documentation

Overview

Package couchdb provides a client library for interacting with the CouchDB API (v3.5.x).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AllDocsOptions

type AllDocsOptions struct {
	Conflicts     bool     `url:"conflicts,omitempty"`
	Descending    bool     `url:"descending,omitempty"`
	EndKey        string   `url:"endkey,omitempty"`
	EndKeyDocID   string   `url:"endkey_docid,omitempty"`
	IncludeDocs   bool     `url:"include_docs,omitempty"`
	InclusiveEnd  bool     `url:"inclusive_end,omitempty"`
	Key           string   `url:"key,omitempty"`
	Keys          []string `url:"-"` // Special handling via POST
	Limit         int      `url:"limit,omitempty"`
	Skip          int      `url:"skip,omitempty"`
	StartKey      string   `url:"startkey,omitempty"`
	StartKeyDocID string   `url:"startkey_docid,omitempty"`
	UpdateSeq     bool     `url:"update_seq,omitempty"`
}

AllDocsOptions represents options for the _all_docs endpoint.

type AllDocsResponse

type AllDocsResponse struct {
	Offset    int          `json:"offset"`
	Rows      []AllDocsRow `json:"rows"`
	TotalRows int          `json:"total_rows"`
	UpdateSeq string       `json:"update_seq,omitempty"`
}

AllDocsResponse represents the response from _all_docs.

type AllDocsRow

type AllDocsRow struct {
	ID    string         `json:"id"`
	Key   string         `json:"key"`
	Value map[string]any `json:"value"`
	Doc   map[string]any `json:"doc,omitempty"`
}

AllDocsRow represents a single row in the all_docs response.

type AuthInfo

type AuthInfo struct {
	Authenticated          string   `json:"authenticated"`
	AuthenticationDB       string   `json:"authentication_db"`
	AuthenticationHandlers []string `json:"authentication_handlers"`
}

AuthInfo represents authentication information in a session.

type Authenticator

type Authenticator interface {
	// Authenticate adds authentication credentials to the request.
	Authenticate(req *http.Request) error
}

Authenticator defines the interface for different authentication methods.

type BasicAuthenticator

type BasicAuthenticator struct {
	Username string
	Password string
}

BasicAuthenticator implements HTTP Basic Authentication.

func (*BasicAuthenticator) Authenticate

func (a *BasicAuthenticator) Authenticate(req *http.Request) error

type BulkDocItem

type BulkDocItem struct {
	ID  string `json:"id"`
	OK  bool   `json:"ok"`
	Rev string `json:"rev"`
}

BulkDocItem represents a single document in a bulk operation response.

type BulkDocsResponse

type BulkDocsResponse []BulkDocItem

BulkDocsResponse represents the response from bulk operations.

type Client

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

Client is an HTTP client for interacting with a CouchDB server.

func NewClient

func NewClient(baseURL string, opts ...ClientOption) *Client

NewClient creates a new CouchDB client with the given options. Example usage:

client := NewClient("http://localhost:5984")
client := NewClient("http://localhost:5984", WithHTTPClient(customClient))

func (*Client) Configuration

func (c *Client) Configuration() *ConfigurationService

Configuration returns the ConfigurationService.

func (*Client) Databases

func (c *Client) Databases() *DatabaseService

Databases returns the DatabaseService.

func (*Client) DesignDocuments

func (c *Client) DesignDocuments() *DesignDocumentService

DesignDocuments returns the DesignDocumentService.

func (*Client) Documents

func (c *Client) Documents() *DocumentService

Documents returns the DocumentService.

func (*Client) Security

func (c *Client) Security() *SecurityService

Security returns the SecurityService.

func (*Client) Server

func (c *Client) Server() *ServerService

Server returns the ServerService.

func (*Client) Sessions

func (c *Client) Sessions() *SessionService

Sessions returns the SessionService.

func (*Client) Users

func (c *Client) Users() *UserService

Users returns the UserService.

type ClientOption

type ClientOption func(*Client)

ClientOption is a functional option for configuring CouchDBClient.

func WithHTTPClient

func WithHTTPClient(client *http.Client) ClientOption

WithHTTPClient sets a custom HTTP client.

type ConfigurationService

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

ConfigurationService provides methods for managing CouchDB configuration. See: https://docs.couchdb.org/en/stable/api/server/configuration.html

Note: CouchDB configuration API returns and accepts JSON-encoded string values. For example, setting a value to "5" requires sending the JSON string "\"5\"".

Node Management: All methods accept a nodeName parameter to configure specific nodes in a cluster. Use "_local" to configure the local node (most common case).

func NewConfigurationService

func NewConfigurationService(client *Client) *ConfigurationService

NewConfigurationService creates a new ConfigurationService.

func (*ConfigurationService) CreateAdmin

func (s *ConfigurationService) CreateAdmin(ctx context.Context, nodeName, username, password string, opts ...RequestOption) error

CreateAdmin creates a new admin user by setting their password in the admins section. This is a convenience wrapper around SetConfigurationValue.

func (*ConfigurationService) DeleteAdmin

func (s *ConfigurationService) DeleteAdmin(ctx context.Context, nodeName, username string, opts ...RequestOption) error

DeleteAdmin removes an admin user. This is a convenience wrapper around DeleteConfigurationValue.

func (*ConfigurationService) DeleteConfigurationValue

func (s *ConfigurationService) DeleteConfigurationValue(ctx context.Context, nodeName, section, key string, opts ...RequestOption) (string, error)

DeleteConfigurationValue deletes a configuration value. DELETE /_node/{node-name}/_config/{section}/{key} Returns the deleted value.

func (*ConfigurationService) GetAdmins

func (s *ConfigurationService) GetAdmins(ctx context.Context, nodeName string, opts ...RequestOption) (map[string]string, error)

GetAdmins returns all admin usernames and their password hashes. This is a convenience wrapper around GetConfigurationSection.

func (*ConfigurationService) GetConfiguration

func (s *ConfigurationService) GetConfiguration(ctx context.Context, nodeName string, opts ...RequestOption) (map[string]map[string]string, error)

GetConfiguration returns the entire CouchDB configuration as a nested map. GET /_node/{node-name}/_config

func (*ConfigurationService) GetConfigurationSection

func (s *ConfigurationService) GetConfigurationSection(ctx context.Context, nodeName, section string, opts ...RequestOption) (map[string]string, error)

GetConfigurationSection gets the configuration structure for a single section. GET /_node/{node-name}/_config/{section}

func (*ConfigurationService) GetConfigurationValue

func (s *ConfigurationService) GetConfigurationValue(ctx context.Context, nodeName, section, key string, opts ...RequestOption) (string, error)

GetConfigurationValue gets a single configuration value from within a specific section. GET /_node/{node-name}/_config/{section}/{key}

func (*ConfigurationService) ReloadConfiguration

func (s *ConfigurationService) ReloadConfiguration(ctx context.Context, nodeName string, opts ...RequestOption) error

ReloadConfiguration reloads the configuration from disk. POST /_node/{node-name}/_config/_reload

func (*ConfigurationService) SetConfigurationValue

func (s *ConfigurationService) SetConfigurationValue(ctx context.Context, nodeName, section, key, value string, opts ...RequestOption) (string, error)

SetConfigurationValue sets a single configuration value. PUT /_node/{node-name}/_config/{section}/{key} Returns the old value if it existed.

func (*ConfigurationService) UpdateAdminPassword

func (s *ConfigurationService) UpdateAdminPassword(ctx context.Context, nodeName, username, newPassword string, opts ...RequestOption) error

UpdateAdminPassword updates an admin's password. This is a convenience wrapper around SetConfigurationValue.

type CookieAuthenticator

type CookieAuthenticator struct {
	Cookie *http.Cookie
}

CookieAuthenticator implements Cookie-based Authentication.

func (*CookieAuthenticator) Authenticate

func (a *CookieAuthenticator) Authenticate(req *http.Request) error

type DatabaseCreateOptions

type DatabaseCreateOptions struct {
	Q           int  `json:"q,omitempty"`
	N           int  `json:"n,omitempty"`
	Partitioned bool `json:"partitioned,omitempty"`
}

DatabaseCreateOptions represents options for creating a database.

type DatabaseInfo

type DatabaseInfo struct {
	Cluster           DatabaseInfoCluster `json:"cluster"`
	CompactRunning    bool                `json:"compact_running"`
	DBName            string              `json:"db_name"`
	DiskFormatVersion int                 `json:"disk_format_version"`
	DocCount          int                 `json:"doc_count"`
	DocDelCount       int                 `json:"doc_del_count"`
	InstanceStartTime string              `json:"instance_start_time"`
	PurgeSeq          string              `json:"purge_seq"`
	Sizes             DatabaseInfoSizes   `json:"sizes"`
	UpdateSeq         string              `json:"update_seq"`
	Props             DatabaseInfoProps   `json:"props,omitempty"`
}

DatabaseInfo represents information about a database.

type DatabaseInfoCluster

type DatabaseInfoCluster struct {
	N int `json:"n"`
	Q int `json:"q"`
	R int `json:"r"`
	W int `json:"w"`
}

type DatabaseInfoProps

type DatabaseInfoProps struct {
	Partitioned bool `json:"partitioned,omitempty"`
}

type DatabaseInfoSizes

type DatabaseInfoSizes struct {
	Active   int `json:"active"`
	File     int `json:"file"`
	External int `json:"external"`
}

type DatabaseResponse

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

DatabaseResponse represents the response from database operations.

type DatabaseService

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

DatabaseService provides methods for managing CouchDB databases.

func NewDatabaseService

func NewDatabaseService(client *Client) *DatabaseService

NewDatabaseService creates a new DatabaseService.

func (*DatabaseService) AllDocs

func (s *DatabaseService) AllDocs(ctx context.Context, dbName string, options *AllDocsOptions, opts ...RequestOption) (*AllDocsResponse, error)

AllDocs retrieves all documents in a database.

func (*DatabaseService) BulkInsert

func (s *DatabaseService) BulkInsert(ctx context.Context, dbName string, docs []map[string]any, opts ...RequestOption) (BulkDocsResponse, error)

BulkInsert inserts multiple documents in a single request.

func (*DatabaseService) BulkUpdate

func (s *DatabaseService) BulkUpdate(ctx context.Context, dbName string, docs []map[string]any, opts ...RequestOption) (BulkDocsResponse, error)

BulkUpdate updates or deletes multiple documents in a single request.

func (*DatabaseService) CreateDatabase

func (s *DatabaseService) CreateDatabase(ctx context.Context, dbName string, options *DatabaseCreateOptions, opts ...RequestOption) (*DatabaseResponse, error)

CreateDatabase creates a new database.

func (*DatabaseService) DatabaseExists

func (s *DatabaseService) DatabaseExists(ctx context.Context, dbName string, opts ...RequestOption) (bool, error)

DatabaseExists checks if a database exists.

func (*DatabaseService) DeleteDatabase

func (s *DatabaseService) DeleteDatabase(ctx context.Context, dbName string, opts ...RequestOption) (*DatabaseResponse, error)

DeleteDatabase deletes a database.

func (*DatabaseService) Find

func (s *DatabaseService) Find(ctx context.Context, dbName string, query *FindRequest, opts ...RequestOption) (*FindResponse, error)

Find queries a database using Mango query language.

func (*DatabaseService) GetDatabase

func (s *DatabaseService) GetDatabase(ctx context.Context, dbName string, opts ...RequestOption) (*DatabaseInfo, error)

GetDatabase retrieves information about a database.

type DesignDocumentService

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

DesignDocumentService provides methods for working with design documents and views.

func NewDesignDocumentService

func NewDesignDocumentService(client *Client) *DesignDocumentService

NewDesignDocumentService creates a new DesignDocumentService.

func (*DesignDocumentService) QueryView

func (s *DesignDocumentService) QueryView(ctx context.Context, dbName, ddoc, viewName string, options *ViewOptions, opts ...RequestOption) (*ViewResponse, error)

QueryView queries a design document view.

type Document

type Document struct {
	ID  string `json:"_id,omitempty"`
	Rev string `json:"_rev,omitempty"`
}

Document represents a CouchDB document.

type DocumentGetOptions

type DocumentGetOptions struct {
	Rev              string   `url:"rev,omitempty"`
	Revs             bool     `url:"revs,omitempty"`
	RevsInfo         bool     `url:"revs_info,omitempty"`
	OpenRevs         []string `url:"-"` // Special handling needed
	Latest           bool     `url:"latest,omitempty"`
	Conflicts        bool     `url:"conflicts,omitempty"`
	DeletedConflicts bool     `url:"deleted_conflicts,omitempty"`
	LocalSeq         bool     `url:"local_seq,omitempty"`
	Meta             bool     `url:"meta,omitempty"`
}

DocumentGetOptions represents options for getting a document.

type DocumentPutOptions

type DocumentPutOptions struct {
	Rev   string `url:"rev,omitempty"`
	Batch string `url:"batch,omitempty"` // "ok" for batch mode
}

DocumentPutOptions represents options for creating/updating a document.

type DocumentResponse

type DocumentResponse struct {
	OK  bool   `json:"ok"`
	ID  string `json:"id,omitempty"`
	Rev string `json:"rev,omitempty"`
}

DocumentResponse represents the response from document operations.

type DocumentService

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

DocumentService provides methods for managing CouchDB documents.

func NewDocumentService

func NewDocumentService(client *Client) *DocumentService

NewDocumentService creates a new DocumentService.

func (*DocumentService) CreateDocument

func (s *DocumentService) CreateDocument(ctx context.Context, dbName string, doc any, options *DocumentPutOptions, opts ...RequestOption) (*DocumentResponse, error)

CreateDocument creates a new document in a database.

func (*DocumentService) DeleteDocument

func (s *DocumentService) DeleteDocument(ctx context.Context, dbName, docID string, rev string, opts ...RequestOption) (*DocumentResponse, error)

DeleteDocument deletes a document from a database.

func (*DocumentService) GetDocument

func (s *DocumentService) GetDocument(ctx context.Context, dbName, docID string, options *DocumentGetOptions, opts ...RequestOption) (map[string]any, error)

GetDocument retrieves a document from a database.

func (*DocumentService) HeadDocument

func (s *DocumentService) HeadDocument(ctx context.Context, dbName, docID string, options *DocumentGetOptions, opts ...RequestOption) (string, error)

HeadDocument checks if a document exists and returns its revision.

func (*DocumentService) UpdateDocument

func (s *DocumentService) UpdateDocument(ctx context.Context, dbName, docID string, doc any, options *DocumentPutOptions, opts ...RequestOption) (*DocumentResponse, error)

UpdateDocument updates an existing document in a database.

type ErrorResponse

type ErrorResponse struct {
	Error  string `json:"error"`
	Reason string `json:"reason"`
}

ErrorResponse represents an error response from CouchDB.

type FindExecutionStats

type FindExecutionStats struct {
	TotalKeysExamined       int     `json:"total_keys_examined"`
	TotalDocsExamined       int     `json:"total_docs_examined"`
	TotalQuorumDocsExamined int     `json:"total_quorum_docs_examined"`
	ResultsReturned         int     `json:"results_returned"`
	ExecutionTimeMs         float64 `json:"execution_time_ms"`
}

FindExecutionStats represents execution statistics for a find query.

type FindRequest

type FindRequest struct {
	Selector       map[string]any      `json:"selector"`
	Limit          int                 `json:"limit,omitempty"`
	Skip           int                 `json:"skip,omitempty"`
	Sort           []map[string]string `json:"sort,omitempty"`
	Fields         []string            `json:"fields,omitempty"`
	UseIndex       any                 `json:"use_index,omitempty"` // string or []string
	R              int                 `json:"r,omitempty"`
	Bookmark       string              `json:"bookmark,omitempty"`
	Update         bool                `json:"update,omitempty"`
	Stable         bool                `json:"stable,omitempty"`
	Conflicts      bool                `json:"conflicts,omitempty"`
	ExecutionStats bool                `json:"execution_stats,omitempty"`
}

FindRequest represents a Mango query request.

type FindResponse

type FindResponse struct {
	Docs           []map[string]any    `json:"docs"`
	Bookmark       string              `json:"bookmark"`
	ExecutionStats *FindExecutionStats `json:"execution_stats,omitempty"`
	Warning        string              `json:"warning,omitempty"`
}

FindResponse represents the response from a find query.

type JWTAuthenticator

type JWTAuthenticator struct {
	Token string
}

JWTAuthenticator implements JWT Bearer Token Authentication.

func (*JWTAuthenticator) Authenticate

func (a *JWTAuthenticator) Authenticate(req *http.Request) error

type LoginResponse

type LoginResponse struct {
	OK    bool     `json:"ok"`
	Name  string   `json:"name"`
	Roles []string `json:"roles"`
}

LoginResponse represents the response from a login request.

type Members

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

Members represents the members/admins section of the security object.

type ProxyAuthenticator

type ProxyAuthenticator struct {
	Roles    []string
	Username string
	Token    string // Secret token shared between proxy and CouchDB
}

ProxyAuthenticator implements Proxy Authentication. Sets X-Auth-CouchDB-UserName, X-Auth-CouchDB-Roles, and X-Auth-CouchDB-Token headers.

func (*ProxyAuthenticator) Authenticate

func (a *ProxyAuthenticator) Authenticate(req *http.Request) error

type RequestOption

type RequestOption func() Authenticator

RequestOption is a functional option for configuring individual requests.

func WithBasicAuth

func WithBasicAuth(username, password string) RequestOption

WithBasicAuth configures the request to use HTTP Basic Authentication.

func WithCookieAuth

func WithCookieAuth(cookie *http.Cookie) RequestOption

WithCookieAuth configures the request to use Cookie Authentication. Typically used with the AuthSession cookie from SessionService.Login.

func WithJWTAuth

func WithJWTAuth(token string) RequestOption

WithJWTAuth configures the request to use JWT Bearer Token Authentication. This requires CouchDB to be configured with JWT authentication enabled.

func WithProxyAuth

func WithProxyAuth(username string, roles []string, token string) RequestOption

WithProxyAuth configures the request to use Proxy Authentication. This requires CouchDB to be configured with proxy authentication enabled.

type SecurityObject

type SecurityObject struct {
	Admins  Members `json:"admins"`
	Members Members `json:"members"`
}

SecurityObject represents the security object for a database.

type SecurityService

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

SecurityService provides methods for managing database security.

func NewSecurityService

func NewSecurityService(client *Client) *SecurityService

NewSecurityService creates a new SecurityService.

func (*SecurityService) GetSecurity

func (s *SecurityService) GetSecurity(ctx context.Context, dbName string, opts ...RequestOption) (*SecurityObject, error)

GetSecurity retrieves the security object for a database.

func (*SecurityService) SetSecurity

func (s *SecurityService) SetSecurity(ctx context.Context, dbName string, security *SecurityObject, opts ...RequestOption) error

SetSecurity sets the security object for a database.

type ServerService

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

ServerService provides methods for server-level operations.

func NewServerService

func NewServerService(client *Client) *ServerService

NewServerService creates a new ServerService.

func (*ServerService) GetUUIDs

func (s *ServerService) GetUUIDs(ctx context.Context, count int, opts ...RequestOption) (*UUIDsResponse, error)

GetUUIDs requests one or more UUIDs from the server.

type SessionInfo

type SessionInfo struct {
	OK      bool        `json:"ok"`
	Info    AuthInfo    `json:"info"`
	UserCtx UserContext `json:"userCtx"`
}

SessionInfo represents information about the current session.

type SessionService

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

SessionService provides methods for session-based authentication.

func NewSessionService

func NewSessionService(client *Client) *SessionService

NewSessionService creates a new SessionService.

func (*SessionService) GetSession

func (s *SessionService) GetSession(ctx context.Context, opts ...RequestOption) (*SessionInfo, error)

GetSession retrieves information about the current session.

func (*SessionService) Login

func (s *SessionService) Login(ctx context.Context, username, password string, opts ...RequestOption) (*LoginResponse, *http.Cookie, error)

Login authenticates a user and creates a session.

func (*SessionService) Logout

func (s *SessionService) Logout(ctx context.Context, opts ...RequestOption) error

Logout ends the current session.

type UUIDsResponse

type UUIDsResponse struct {
	UUIDs []string `json:"uuids"`
}

UUIDsResponse represents the response from the _uuids endpoint.

type User

type User struct {
	ID             string   `json:"_id,omitempty"`
	Rev            string   `json:"_rev,omitempty"`
	Name           string   `json:"name"`
	Type           string   `json:"type"`
	Roles          []string `json:"roles"`
	Password       string   `json:"password,omitempty"`
	Salt           string   `json:"salt,omitempty"`
	DerivedKey     string   `json:"derived_key,omitempty"`
	Iterations     int      `json:"iterations,omitempty"`
	PasswordScheme string   `json:"password_scheme,omitempty"`
}

User represents a CouchDB user document.

type UserContext

type UserContext struct {
	Name  string   `json:"name"`
	Roles []string `json:"roles"`
}

UserContext represents the user context in a session.

type UserResponse

type UserResponse struct {
	OK  bool   `json:"ok"`
	ID  string `json:"id"`
	Rev string `json:"rev"`
}

UserResponse represents the response from CouchDB for user operations.

type UserService

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

UserService provides methods for managing CouchDB users.

func NewUserService

func NewUserService(client *Client) *UserService

NewUserService creates a new UserService.

func (*UserService) CreateUser

func (s *UserService) CreateUser(ctx context.Context, name, password string, roles []string, opts ...RequestOption) (*UserResponse, error)

CreateUser creates a new user in the _users database.

func (*UserService) DeleteUser

func (s *UserService) DeleteUser(ctx context.Context, name, rev string, opts ...RequestOption) (*UserResponse, error)

DeleteUser deletes a user from the _users database.

func (*UserService) GetUser

func (s *UserService) GetUser(ctx context.Context, name string, opts ...RequestOption) (*User, error)

GetUser retrieves a user from the _users database.

func (*UserService) ListUsers

func (s *UserService) ListUsers(ctx context.Context, opts ...RequestOption) ([]User, error)

ListUsers retrieves all users from the _users database.

func (*UserService) UpdatePassword

func (s *UserService) UpdatePassword(ctx context.Context, name, rev, newPassword string, opts ...RequestOption) (*UserResponse, error)

UpdatePassword updates only the password for an existing user.

func (*UserService) UpdateRoles

func (s *UserService) UpdateRoles(ctx context.Context, name, rev string, roles []string, opts ...RequestOption) (*UserResponse, error)

UpdateRoles updates only the roles for an existing user.

func (*UserService) UpdateUser

func (s *UserService) UpdateUser(ctx context.Context, name, rev string, password *string, roles []string, opts ...RequestOption) (*UserResponse, error)

UpdateUser updates an existing user in the _users database.

type ViewOptions

type ViewOptions struct {
	Conflicts     bool   `url:"conflicts,omitempty"`
	Descending    bool   `url:"descending,omitempty"`
	EndKey        any    `url:"-"` // JSON encoded
	EndKeyDocID   string `url:"endkey_docid,omitempty"`
	Group         bool   `url:"group,omitempty"`
	GroupLevel    int    `url:"group_level,omitempty"`
	IncludeDocs   bool   `url:"include_docs,omitempty"`
	InclusiveEnd  bool   `url:"inclusive_end,omitempty"`
	Key           any    `url:"-"` // JSON encoded
	Keys          []any  `url:"-"` // POST body
	Limit         int    `url:"limit,omitempty"`
	Reduce        *bool  `url:"-"` // Special handling - explicit true/false
	Skip          int    `url:"skip,omitempty"`
	Sorted        bool   `url:"sorted,omitempty"`
	Stable        bool   `url:"stable,omitempty"`
	Stale         string `url:"stale,omitempty"`
	StartKey      any    `url:"-"` // JSON encoded
	StartKeyDocID string `url:"startkey_docid,omitempty"`
	Update        string `url:"update,omitempty"`
	UpdateSeq     bool   `url:"update_seq,omitempty"`
}

ViewOptions represents options for querying a view.

type ViewResponse

type ViewResponse struct {
	Offset    int       `json:"offset"`
	TotalRows int       `json:"total_rows"`
	Rows      []ViewRow `json:"rows"`
	UpdateSeq string    `json:"update_seq,omitempty"`
}

ViewResponse represents the response from a view query.

type ViewRow

type ViewRow struct {
	ID    string         `json:"id"`
	Key   any            `json:"key"`
	Value any            `json:"value"`
	Doc   map[string]any `json:"doc,omitempty"`
}

ViewRow represents a single row in a view response.

Jump to

Keyboard shortcuts

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