Documentation ¶
Index ¶
- func NewDatabase(client *mongox.Client, dbname string) (db mongox.Database)
- type Database
- func (d *Database) Client() (client *mongox.Client)
- func (d *Database) Context() (ctx context.Context)
- func (d *Database) Count(target interface{}, filters ...interface{}) (result int64, err error)
- func (d *Database) DeleteArray(target interface{}, filters ...interface{}) (err error)
- func (d *Database) DeleteOne(target interface{}, filters ...interface{}) (err error)
- func (d *Database) GetCollectionOf(document interface{}) (collection *mongox.Collection)
- func (d *Database) IndexEnsure(cfg interface{}, document interface{}) (err error)
- func (d *Database) LoadArray(target interface{}, filters ...interface{}) (err error)
- func (d *Database) LoadOne(target interface{}, filters ...interface{}) (err error)
- func (d *Database) LoadStream(target interface{}, filters ...interface{}) (loader mongox.StreamLoader, err error)
- func (d *Database) Name() (name string)
- func (d *Database) New(ctx context.Context) (db mongox.Database)
- func (d *Database) SaveOne(source interface{}, filters ...interface{}) (err error)
- func (d *Database) UpdateOne(target interface{}, filters ...interface{}) (err error)
- type StreamLoader
- func (l *StreamLoader) Close() (err error)
- func (l *StreamLoader) Cursor() (cursor *mongox.Cursor)
- func (l *StreamLoader) DecodeMsg(i interface{}) (err error)
- func (l *StreamLoader) DecodeNextMsg(i interface{}) (err error)
- func (l *StreamLoader) Err() (err error)
- func (l *StreamLoader) Next() (err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database handler
func (*Database) Count ¶
Count function counts documents in the database by query target is used only to get collection by tag so it'd be better to use nil ptr here
func (*Database) DeleteArray ¶
DeleteArray removes documents list from a database by their ids
func (*Database) DeleteOne ¶
DeleteOne removes a document from a database and then returns it into target
func (*Database) GetCollectionOf ¶
func (d *Database) GetCollectionOf(document interface{}) (collection *mongox.Collection)
GetCollectionOf returns the collection object by the «collection» tag of the given document; the «collection» tag should exists, e.g.:
type Foobar struct { base.ObjectID `bson:",inline" json:",inline" collection:"foobars"` ...
Will panic if there is no «collection» tag
func (*Database) IndexEnsure ¶
IndexEnsure function ensures index in mongo collection of document
`index:""` -- https://docs.mongodb.com/manual/indexes/#create-an-index `index:"-"` -- (descending) `index:"-,+foo,+-bar"` -- https://docs.mongodb.com/manual/core/index-compound `index:"-,+foo,+-bar,unique"` -- https://docs.mongodb.com/manual/core/index-unique `index:"-,+foo,+-bar,unique,allowNull"` -- https://docs.mongodb.com/manual/core/index-partial `index:"-,unique,allowNull,expireAfter=86400"` -- https://docs.mongodb.com/manual/core/index-ttl `index:"-,unique,allowNull,expireAfter={{.Expire}}"` -- evaluate index as a golang template with `cfg` arguments
func (*Database) LoadStream ¶
func (d *Database) LoadStream(target interface{}, filters ...interface{}) (loader mongox.StreamLoader, err error)
LoadStream function loads documents one by one into a target channel
type StreamLoader ¶
type StreamLoader struct {
// contains filtered or unexported fields
}
StreamLoader is a controller for a database cursor
func (*StreamLoader) Close ¶
func (l *StreamLoader) Close() (err error)
Close stream loader and the underlying cursor
func (*StreamLoader) Cursor ¶
func (l *StreamLoader) Cursor() (cursor *mongox.Cursor)
Cursor returns the underlying cursor
func (*StreamLoader) DecodeMsg ¶ added in v2.0.10
func (l *StreamLoader) DecodeMsg(i interface{}) (err error)
DecodeMsg decodes the current cursor document into an interface
func (*StreamLoader) DecodeNextMsg ¶ added in v2.0.10
func (l *StreamLoader) DecodeNextMsg(i interface{}) (err error)
DecodeNextMsg decodes the next document to an interface or returns an error
func (*StreamLoader) Next ¶
func (l *StreamLoader) Next() (err error)
Next loads next documents but doesn't perform decoding