gongo

package module
v0.0.0-...-b9a69e3 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2019 License: MIT Imports: 15 Imported by: 0

README

gongo

A Golang mongoosejs-like ODM for MongoDB

Documentation

Index

Constants

View Source
const (
	StringType   = "String"
	IntType      = "Int"
	FloatType    = "Float"
	BoolType     = "Bool"
	MixedType    = "Mixed"
	ObjectIDType = "ObjectID"
)

Built-in types

Variables

This section is empty.

Functions

This section is empty.

Types

type Document

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

Document a mongodb document wrapper

func (*Document) Decode

func (c *Document) Decode(target interface{}) error

Decode decodes the document to an interface

func (*Document) Get

func (c *Document) Get(path string) (interface{}, error)

Get gets the current proposed change path

func (*Document) ID

func (c *Document) ID() interface{}

ID returns the object id

func (*Document) Save

func (c *Document) Save(timeout ...*int) error

Save saves a document

func (*Document) Set

func (c *Document) Set(path string, value interface{}) error

Set sets the current proposed change path

func (*Document) Validate

func (c *Document) Validate() error

Validate validates the document proposed changes

type DocumentList

type DocumentList []*Document

DocumentList a list of documents

func (*DocumentList) Decode

func (c *DocumentList) Decode(target interface{}) error

Decode decodes all of the documents in a document list to a target

type Gongo

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

Gongo main interface

func New

func New(opts ...*Options) *Gongo

New creates a new gongo instance

func (*Gongo) Connect

func (c *Gongo) Connect(connectionString string) error

Connect connects to mongodb, this should be performed after all schema and model setup has taken place

func (*Gongo) M

func (c *Gongo) M(name string) *Model

M gets a model from the registered models

func (*Gongo) Model

func (c *Gongo) Model(name string, schema *Schema, opts ...*ModelOptions) (*Model, error)

Model creates a new model and adds it to gongo

type Model

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

Model model

func (*Model) Collection

func (c *Model) Collection() *mongo.Collection

Collection returns the collection object

func (*Model) Create

func (c *Model) Create(document interface{}, timeout ...*int) (*Document, error)

Create creates and saves a document

func (*Model) Database

func (c *Model) Database() *mongo.Database

Database returns the database object

func (*Model) Find

func (c *Model) Find(filter interface{}, opts ...*options.FindOptions) (DocumentList, error)

Find finds documents

func (*Model) FindByID

func (c *Model) FindByID(id interface{}, opts ...*options.FindOneOptions) (*Document, error)

FindByID finds one document by id

func (*Model) FindByIDWithTimeout

func (c *Model) FindByIDWithTimeout(id interface{}, timeout *int, opts ...*options.FindOneOptions) (*Document, error)

FindByIDWithTimeout finds one document by id

func (*Model) FindOne

func (c *Model) FindOne(filter interface{}, opts ...*options.FindOneOptions) (*Document, error)

FindOne finds one document

func (*Model) FindOneAndDelete

func (c *Model) FindOneAndDelete(
	filter interface{},
	opts ...*options.FindOneAndDeleteOptions,
) (*Document, error)

FindOneAndDelete finds a document and deletes it

func (*Model) FindOneAndDeleteWithTimeout

func (c *Model) FindOneAndDeleteWithTimeout(
	filter interface{},
	timeout *int,
	opts ...*options.FindOneAndDeleteOptions,
) (*Document, error)

FindOneAndDeleteWithTimeout finds a document and deletes it

func (*Model) FindOneAndUpdate

func (c *Model) FindOneAndUpdate(
	filter interface{},
	update interface{},
	opts ...*options.FindOneAndUpdateOptions,
) (*Document, error)

FindOneAndUpdate finds a document and updates it

func (*Model) FindOneAndUpdateWithTimeout

func (c *Model) FindOneAndUpdateWithTimeout(
	filter interface{},
	update interface{},
	timeout *int,
	opts ...*options.FindOneAndUpdateOptions,
) (*Document, error)

FindOneAndUpdateWithTimeout finds a document and updates it

func (*Model) FindOneWithTimeout

func (c *Model) FindOneWithTimeout(filter interface{}, timeout *int, opts ...*options.FindOneOptions) (*Document, error)

FindOneWithTimeout finds one document

func (*Model) FindWithTimeout

func (c *Model) FindWithTimeout(filter interface{}, timeout *int, opts ...*options.FindOptions) (DocumentList, error)

FindWithTimeout finds documents

func (*Model) Hydrate

func (c *Model) Hydrate(filter interface{}, timeout ...*int) (*Document, error)

Hydrate hydrates a model

func (*Model) InsertOne

func (c *Model) InsertOne(doc interface{}, opts ...*options.InsertOneOptions) (*Document, error)

InsertOne inserts one document

func (*Model) InsertOneWithTimeout

func (c *Model) InsertOneWithTimeout(doc interface{}, timeout *int, opts ...*options.InsertOneOptions) (*Document, error)

InsertOneWithTimeout inserts one document

func (*Model) New

func (c *Model) New(document interface{}) (*Document, error)

New creates a new instance of a model

type ModelOptions

type ModelOptions struct {
	DontPluralize bool
	DontSnakeCase bool
}

ModelOptions options for the model

type Options

type Options struct {
	FieldTag        string
	DefaultDatabase string
}

Options gongo options

type PostMiddleware

type PostMiddleware struct {
	Operation string
	Handler   PostMiddlewareFunc
	Async     bool
}

PostMiddleware a middleware

type PostMiddlewareFunc

type PostMiddlewareFunc func(document bson.M, err error) error

PostMiddlewareFunc middleware for post

type PreMiddleware

type PreMiddleware struct {
	Operation string
	Handler   PreMiddlewareFunc
	Async     bool
}

PreMiddleware a middleware

type PreMiddlewareFunc

type PreMiddlewareFunc func(documentOrQuery bson.M) error

PreMiddlewareFunc middleware for document

type Schema

type Schema struct {
	Fields   SchemaFieldMap
	Options  *SchemaOptions
	Virtuals *VirtualFieldMap
	// contains filtered or unexported fields
}

Schema a schema definition

func (*Schema) Post

func (c *Schema) Post(operation string, handler PostMiddlewareFunc, async ...*bool) *Schema

Post adds post middleware

func (*Schema) Pre

func (c *Schema) Pre(operation string, handler PreMiddlewareFunc, async ...*bool) *Schema

Pre adds pre middleware

func (*Schema) Virtual

func (c *Schema) Virtual(config *VirtualConfig) *Schema

Virtual adds a virtual field config

type SchemaField

type SchemaField struct {
	Type     interface{}
	Required bool
	Unique   bool
	Default  interface{}
	Validate *[]ValidatorFunc
	Meta     *map[string]interface{}
	// contains filtered or unexported fields
}

SchemaField a schema field definition

type SchemaFieldMap

type SchemaFieldMap map[string]*SchemaField

SchemaFieldMap a map of fields

type SchemaOptions

type SchemaOptions struct {
	ID *bool
}

SchemaOptions schema options

type ValidatorFunc

type ValidatorFunc func(value interface{}) error

ValidatorFunc a function that performs a validation

type VirtualConfig

type VirtualConfig struct {
	Name string
	Get  VirtualGetFunc
	Set  VirtualSetFunc
}

VirtualConfig defines the virtual config

type VirtualFieldMap

type VirtualFieldMap map[string]*VirtualConfig

VirtualFieldMap a map of virtual types

type VirtualGetFunc

type VirtualGetFunc func(doc bson.M) (interface{}, error)

VirtualGetFunc for resolving virtual

type VirtualSetFunc

type VirtualSetFunc func(value interface{}, doc bson.M) error

VirtualSetFunc for resolving virtual

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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