model

package
v0.0.0-...-14d575d Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2021 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SortOrderAsc  = false
	SortOrderDesc = true
)
View Source
const (
	SelectorValueTypeNil = iota
	SelectorValueTypeBool
	SelectorValueTypeArray
	SelectorValueTypeObject
	SelectorValueTypeInt
	SelectorValueTypeFloat
	SelectorValueTypeString
	SelectorValueTypeOther
)
View Source
const RoleServerAdmin = "_admin"

Variables

View Source
var DocsBucket = []byte("docs")

Functions

This section is empty.

Types

type AdminUser

type AdminUser struct {
	Username string
	Password string
}

func (AdminUser) Session

func (u AdminUser) Session() *Session

func (AdminUser) String

func (u AdminUser) String() string

type AdminUsers

type AdminUsers []AdminUser

func ParseAdmins

func ParseAdmins(admins string) (AdminUsers, error)

func (AdminUsers) Authenticate

func (a AdminUsers) Authenticate(username, password string) *AdminUser

type Admins

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

type Attachment

type Attachment struct {
	Filename    string `bson:"-" json:"-"`
	ContentType string `json:"content_type"`
	Revpos      int    `json:"revpos"`
	Digest      string `json:"digest"`
	Length      int64  `json:"length"`
	Stub        bool   `json:"stub"`

	Reader io.ReadCloser `bson:"-" json:"-"`
}

type ChangesOptions

type ChangesOptions struct {
	Since   string
	Limit   int
	Timeout time.Duration
}

func (*ChangesOptions) SinceNow

func (o *ChangesOptions) SinceNow() bool

type DatabaseStats

type DatabaseStats struct {
	FileSize    uint64
	DocCount    uint64
	DocDelCount uint64
	Alloc       uint64
	InUse       uint64
}

type DesignDocFn

type DesignDocFn struct {
	Type        FnType
	DesignDocID string
	FnName      string
}

func NewSearchFn

func NewSearchFn(designDocID, fnName string) DesignDocFn

func NewViewFn

func NewViewFn(designDocID, fnName string) DesignDocFn

func ParseDesignDocFn

func ParseDesignDocFn(str string) (*DesignDocFn, error)

func (DesignDocFn) Bucket

func (ddfn DesignDocFn) Bucket() []byte

func (DesignDocFn) String

func (ddfn DesignDocFn) String() string

type DocPrefix

type DocPrefix string
var (
	DesignDocPrefix DocPrefix = "_design/"
	LocalDocPrefix  DocPrefix = "_local/"
)

type Document

type Document struct {
	// Meta
	ID       string `json:"_id,omitempty"`
	Rev      string `json:"_rev,omitempty"`
	Deleted  bool   `json:"_deleted,omitempty"`
	LocalSeq uint64 `json:"_local_seq,omitempty"`

	// Data
	Attachments map[string]*Attachment `json:"_attachments,omitempty"`
	Data        map[string]interface{} `json:"data,omitempty"`

	// View
	Key   interface{} `json:"key,omitempty"`
	Value interface{} `json:"value,omitempty"`

	// Search
	Fields  map[string]interface{}       `json:"fields,omitempty"`
	Options map[string]SearchIndexOption `json:"options,omitempty"`
}

func (*Document) Exists

func (doc *Document) Exists(path string) bool

func (*Document) Field

func (doc *Document) Field(path string) interface{}

func (*Document) Functions

func (doc *Document) Functions() []*Function

func (Document) IsDesignDoc

func (doc Document) IsDesignDoc() bool

func (Document) IsLocalDoc

func (doc Document) IsLocalDoc() bool

func (Document) Language

func (doc Document) Language() string

func (Document) NextSequenceRevision

func (doc Document) NextSequenceRevision() int

func (Document) Revision

func (doc Document) Revision() (string, bool)

func (Document) Revisions

func (doc Document) Revisions() Revisions

func (Document) ValidUpdateRevision

func (doc Document) ValidUpdateRevision(newDoc *Document) bool

func (*Document) View

func (doc *Document) View(name string) (view *View, ok bool)

type DocumentField

type DocumentField interface {
	// Field get a field value (nesting supported with . operator)
	Field(path string) interface{}
	Exists(path string) bool
}

DocumentField provide a field from a document handles nested document traversal

type ExecutionStats

type ExecutionStats struct {
	// TotalKeysExamined
	// Number of index keys examined. Currently always 0.
	TotalKeysExamined int `json:"total_keys_examined"`

	// TotalDocsExamined
	// Number of documents fetched from the database / index,
	// equivalent to using include_docs=true in a view. These
	// may then be filtered in-memory to further narrow down
	// the result set based on the selector.
	TotalDocsExamined int `json:"total_docs_examined"`

	// TotalQuorumDocsExamined
	// Number of documents fetched from the database using an
	// out-of-band document fetch. This is only non-zero when
	// read quorum > 1 is specified in the query parameters.
	TotalQuorumDocsExamined int `json:"total_quorum_docs_examined"`

	// ResultsReturned
	// Number of results returned from the query. Ideally this
	// should not be significantly lower than the total
	// documents / keys examined.
	ResultsReturned int `json:"results_returned"`

	// ExecutionTime
	// Total execution time in milliseconds as measured by the
	// database.
	ExecutionTime float64 `json:"execution_time_ms"`
}

type FieldSelector

type FieldSelector struct {
	Field     string
	Value     interface{}
	Operation SelectorOp
}

func (FieldSelector) Match

func (fs FieldSelector) Match(df DocumentField) (bool, error)

func (FieldSelector) String

func (fs FieldSelector) String() string

func (*FieldSelector) UnmarshalJSON

func (fs *FieldSelector) UnmarshalJSON(blob []byte) error

type FindQuery

type FindQuery struct {
	// Selector JSON object describing criteria used to select documents.
	// More information provided in the section on selector syntax.
	Selector SelectorGroup `json:"selector"`
	// Sort JSON array following sort syntax. Optional
	Sort SortList `json:"sort"`
	// Fields JSON array specifying which fields of each object should be returned.
	// If it is omitted, the entire object is returned. More information
	// 	provided in the section on filtering fields. Optional
	Fields []string `json:"fields"`
	// Limit Maximum number of results returned. Default is 25. Optional
	Limit int `json:"limit"`
	// Skip the first ‘n’ results, where ‘n’ is the value specified. Optional
	Skip int `json:"skip"`
	// Bookmark a string that enables you to specify which page of
	// results you require. Used for paging through result sets.
	// Every query returns an opaque string under the bookmark key
	// that can then be passed back in a query to get the next page
	// of results. If any part of the selector query changes between
	// requests, the results are undefined.
	Bookmark string `json:"bookmark"`
	// Include execution statistics in the query response.
	ExecutionStats bool `json:"execution_stats"`
}

func (FindQuery) Match

func (fq FindQuery) Match(doc *Document) (bool, error)

func (FindQuery) SortDocuments

func (fq FindQuery) SortDocuments(docs []*Document)

type FnType

type FnType string
const (
	ViewFn   FnType = "views"
	SearchFn FnType = "indexes"
)

type Function

type Function struct {
	Name string
	Type FnType

	MapFn    string
	ReduceFn string
	SearchFn string
	Analyzer string
	// contains filtered or unexported fields
}

func (*Function) DesignDocFn

func (f *Function) DesignDocFn() *DesignDocFn

type IndexStats

type IndexStats struct {
	// Documents number of document in the index
	Documents uint64
	// Keys number of keys in the index
	Keys uint64
	// Used number of bytes used by the index
	Used uint64
	// Allocated number of bytes allocated by the index
	Allocated uint64
}

IndexStats

Since an index may have multiple records pointing to the same document or may ignore documents, the number of Records may be higher than the number of Documents.

func (IndexStats) String

func (s IndexStats) String() string

type IteratorOptions

type IteratorOptions struct {
	Skip     int
	Limit    int
	StartKey []byte
	EndKey   []byte

	SkipDeleted   bool
	SkipDesignDoc bool
	SkipLocalDoc  bool

	CleanKey func([]byte) string
	KeyFunc  func(k []byte) []byte

	BucketName []byte
}

type Members

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

type Proxy

type Proxy struct {
	Type        ProxyType `mapstructure:"type" json:"type"`
	Target      string    `mapstructure:"target" json:"target"`
	StripPrefix bool      `mapstructure:"stripPrefix" json:"stripPrefix"`
}

func (Proxy) String

func (p Proxy) String() string

type ProxyType

type ProxyType string
const (
	ProxyDB      ProxyType = "db"
	ProxyReverse ProxyType = "reverse"
)

type Revisions

type Revisions struct {
	IDs   []string `json:"ids"`
	Start int64    `json:"start"`
}

type SearchIndexOption

type SearchIndexOption struct {
	// Boost, a number that specifies the relevance in search results.
	// Content that is indexed with a boost value greater than
	// 1 is more relevant than content that is indexed without
	// a boost value. Content with a boost value less than one
	// is not so relevant. Value is a positive floating point
	// number. Default is 1 (no boosting).
	Boost int `json:"boost"`

	// Facet, creates a faceted index. See Faceting. Values are true
	// or false. Default is false.
	Facet bool `json:"facet"`

	// Index, whether the data is indexed, and if so, how. If set to
	// false, the data cannot be used for searches, but can still be
	// retrieved from the index if store is set to true. See Analyzers.
	// Values are true or false. Default is true
	Index *bool `json:"index"`

	// Store, if true, the value is returned in the search result;
	// otherwise, the value is not returned. Values are true or false.
	// Default is false.
	Store bool `json:"store"`
}

func (SearchIndexOption) ShouldIndex

func (o SearchIndexOption) ShouldIndex() bool

Returns true when the data should be indexed

type Security

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

func DefaultSecurity

func DefaultSecurity() *Security

type SelectorGroup

type SelectorGroup struct {
	Members   []SelectorQuery
	Operation SelectorGroupOp
}

func (SelectorGroup) Match

func (sg SelectorGroup) Match(df DocumentField) (bool, error)

func (SelectorGroup) String

func (sg SelectorGroup) String() string

func (*SelectorGroup) UnmarshalJSON

func (sg *SelectorGroup) UnmarshalJSON(blob []byte) error

type SelectorGroupOp

type SelectorGroupOp string
const (
	SelectorAnd         SelectorGroupOp = "$and"         // Matches if all the selectors in the array match.
	SelectorOr          SelectorGroupOp = "$or"          // Matches if any of the selectors in the array match. All selectors must use the same index.
	SelectorNot         SelectorGroupOp = "$not"         // Matches if the given selector does not match.
	SelectorNor         SelectorGroupOp = "$nor"         // Matches if none of the selectors in the array match.
	SelectorElemMatch   SelectorGroupOp = "$elemMatch"   // Matches and returns all documents that contain an array field with at least one element that matches all the specified query criteria.
	SelectorAllMatch    SelectorGroupOp = "$allMatch"    // Matches and returns all documents that contain an array field with all its elements matching all the specified query criteria.
	SelectorKeyMapMatch SelectorGroupOp = "$keyMapMatch" // Matches and returns all documents that contain a map that contains at least one key that matches all the specified query criteria.
)

type SelectorOp

type SelectorOp string
const (
	SelectorOpLt     SelectorOp = "$lt"     // The field is less than the argument
	SelectorOpLte    SelectorOp = "$lte"    // The field is less than or equal to the argument.
	SelectorOpEq     SelectorOp = "$eq"     // The field is equal to the argument
	SelectorOpNe     SelectorOp = "$ne"     // The field is not equal to the argument.
	SelectorOpGte    SelectorOp = "$gte"    // The field is greater than or equal to the argument.
	SelectorOpGt     SelectorOp = "$gt"     // The field is greater than the to the argument.
	SelectorOpExists SelectorOp = "$exists" // Check whether the field exists or not, regardless of its value.
	SelectorOpType   SelectorOp = "$type"   // Check the document field’s type. Valid values are "null", "boolean", "number", "string", "array", and "object".
	SelectorOpIn     SelectorOp = "$in"     // The document field must exist in the list provided.
	SelectorOpNin    SelectorOp = "$nin"    // The document field not must exist in the list provided.
	SelectorOpSize   SelectorOp = "$size"   // Special condition to match the length of an array field in a document. Non-array fields cannot match this condition.
	SelectorOpMod    SelectorOp = "$mod"    // Divisor and Remainder are both positive or negative integers. Non-integer values result in a 404. Matches documents where field % Divisor == Remainder is true, and only when the document field is an integer.
	SelectorOpRegex  SelectorOp = "$regex"  // A regular expression pattern to match against the document field. Only matches when the field is a string value and matches the supplied regular expression. The matching algorithms are based on the Perl Compatible Regular Expression (PCRE) library. For more information about what is implemented, see the see the https://golang.org/pkg/regexp/

	SelectorAll SelectorOp = "$all" // Matches an array value if it contains all the elements of the argument array.
)

type SelectorQuery

type SelectorQuery interface {
	// Match returns true if the selector matched
	// the passed otherwise false
	Match(df DocumentField) (bool, error)
	String() string
}

SelectorQuery matches a document or doesn't

type SelectorValue

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

func (SelectorValue) ArrayLen

func (sv SelectorValue) ArrayLen() int

func (*SelectorValue) GeaterThen

func (sv *SelectorValue) GeaterThen(other *SelectorValue) bool

func (*SelectorValue) IsNumber

func (sv *SelectorValue) IsNumber() bool

func (*SelectorValue) LessThen

func (sv *SelectorValue) LessThen(other *SelectorValue) bool

func (*SelectorValue) Match

func (sv *SelectorValue) Match(other *SelectorValue) (bool, error)

func (*SelectorValue) Set

func (sv *SelectorValue) Set(v interface{})

func (*SelectorValue) Type

func (sv *SelectorValue) Type() string

func (SelectorValue) Values

func (sv SelectorValue) Values() []SelectorValue

type SelectorValueType

type SelectorValueType int

type Session

type Session struct {
	Name  string   `json:"name,omitempty"`
	Roles []string `json:"roles"`
}

func (Session) Authenticated

func (s Session) Authenticated() bool

func (Session) IsServerAdmin

func (s Session) IsServerAdmin() bool

func (*Session) Restore

func (s *Session) Restore(values map[interface{}]interface{})

func (Session) Store

func (s Session) Store(values map[interface{}]interface{})

type Sort

type Sort struct {
	Field string
	Order bool
}

func (Sort) Less

func (s Sort) Less(l, r *Document) bool

type SortList

type SortList []Sort

func (SortList) Less

func (sl SortList) Less(l, r *Document) bool

func (*SortList) UnmarshalJSON

func (sl *SortList) UnmarshalJSON([]byte) error

type SortQuery

type SortQuery interface {
	// Less returns true if l is lower then r
	Less(l, r *Document) bool
}

SortQuery allows sorting of documents

type Task

type Task struct {
	ID          uint64
	ActiveSince time.Time
	Action      TaskAction

	DesignDocFn string
	DBName      string

	UpdatedAt       time.Time
	ProcessingTotal int // total number of things to process
	Processed       int // number of things processed
}

func (Task) String

func (t Task) String() string

type TaskAction

type TaskAction int
const (
	ActionUpdateView TaskAction = iota
)

type User

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

func (*User) FromDocument

func (u *User) FromDocument(doc *Document) error

func (*User) GeneratePBKDF2

func (u *User) GeneratePBKDF2() error

GeneratePBKDF2 generates a pbkdf in a couchdb compatible fashion

func (User) Session

func (u User) Session() *Session

func (*User) VerifyPassword

func (u *User) VerifyPassword(password string) (bool, error)

Verify the PBKDF2 using a couchdb compatible way

type View

type View struct {
	Language string
	MapFn    string
	ReduceFn string
}

type VirtualHostConfiguration

type VirtualHostConfiguration struct {
	Name    string
	Rev     string
	Domains []string         `mapstructure:"domains" json:"domains"`
	Proxy   map[string]Proxy `mapstructure:"proxy" json:"proxy"`
	Static  string           `mapstructure:"static" json:"static"`
	FS      http.FileSystem
}

func (VirtualHostConfiguration) Open

func (c VirtualHostConfiguration) Open(name string) (http.File, error)

func (VirtualHostConfiguration) String

func (c VirtualHostConfiguration) String() string

Jump to

Keyboard shortcuts

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