morm

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2024 License: MIT Imports: 12 Imported by: 0

README

Morm

Morm is a powerful Object Document Mapper (ODM) for Golang, inspired by Mongoose, designed to be developer-friendly and feature-rich.

go report card test status MIT license Go.Dev reference

Overview

  • Full-Featured Object Document Mapper
  • Associations (Embedded Documents, References)
  • Hooks (Before/After Create/Save/Update/Delete/Find)
  • Eager loading with Populate
  • Transactions, Nested Transactions
  • Context Support, Prepared Statement Mode, DryRun Mode
  • Batch Insert, FindInBatches, Find To Map
  • MongoDB Query Builder, Upsert, Index Hints, NamedArg
  • Auto Migrations
  • Logger
  • Extendable, flexible plugin API: Database Resolver (Multiple Databases, Read/Write Splitting), Prometheus…
  • Every feature comes with tests
  • Developer Friendly

Getting Started

Contributing

You can help make Morm better, check out things you can do

Contributors

Thank you for contributing to Morm!

License

© Devsamahd, 2024

Released under the MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToUpdateStruct

func ToUpdateStruct(data interface{}) (primitive.M, error)

Types

type Collect

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

func (*Collect) Aggregate

func (c *Collect) Aggregate(pipeline interface{}, ctx ...context.Context) (*mongo.Cursor, error)

type CollectQueryBuilder

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

func Collection

func Collection(collectionName string, model interface{}) (*CollectQueryBuilder, error)

Collection creates a new Collect instance for the specified collection and model

func (*CollectQueryBuilder) Create

func (qb *CollectQueryBuilder) Create(model interface{}, ctx ...context.Context) (primitive.ObjectID, error)

Create inserts a new document into the specified collection

func (*CollectQueryBuilder) Delete

func (qb *CollectQueryBuilder) Delete(filter interface{}, ctx ...context.Context) error

Delete deletes a document from the specified collection based on the filter

func (*CollectQueryBuilder) DeleteMany

func (qb *CollectQueryBuilder) DeleteMany(filter interface{}, ctx ...context.Context) (int64, error)

DeleteMany deletes multiple documents from the specified collection based on the filter

func (*CollectQueryBuilder) Exec

func (qb *CollectQueryBuilder) Exec() (interface{}, error)

Execute executes the query and returns the result

func (*CollectQueryBuilder) Find

func (qb *CollectQueryBuilder) Find(filter ...interface{}) *CollectQueryBuilder

func (*CollectQueryBuilder) FindOne

func (qb *CollectQueryBuilder) FindOne(filter interface{}) *CollectQueryBuilder

func (*CollectQueryBuilder) FindOneAndRemove

func (qb *CollectQueryBuilder) FindOneAndRemove(filter interface{}, ctx ...context.Context) (interface{}, error)

FindOneAndRemove finds a single document in the specified collection based on the filter and removes it

func (*CollectQueryBuilder) FindOneAndUpdate

func (qb *CollectQueryBuilder) FindOneAndUpdate(filter interface{}, update interface{}, ctx ...context.Context) (interface{}, error)

func (*CollectQueryBuilder) Limit

Limit sets the maximum number of documents to return

func (*CollectQueryBuilder) Populate

func (qb *CollectQueryBuilder) Populate(fields []string) *CollectQueryBuilder

func (*CollectQueryBuilder) Projection

func (qb *CollectQueryBuilder) Projection(projection bson.D) *CollectQueryBuilder

Projection sets the projection for the query

func (*CollectQueryBuilder) Skip

Skip sets the number of documents to skip

func (*CollectQueryBuilder) Sort

Sort sets the sort order for the query

func (*CollectQueryBuilder) Update

func (qb *CollectQueryBuilder) Update(filter interface{}, update interface{}, ctx ...context.Context) error

Update updates multiple documents in the specified collection based on the filter and update parameters

func (*CollectQueryBuilder) UpdateOne

func (qb *CollectQueryBuilder) UpdateOne(filter interface{}, update interface{}) error

UpdateOne updates a single document in the specified collection based on the filter and update parameters\

func (*CollectQueryBuilder) Virtual

func (qb *CollectQueryBuilder) Virtual(fields []string, value interface{}, filter interface{}) (interface{}, error)

type Model

type Model struct {
	ID        primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
	CreatedAt time.Time          `bson:"createdAt"`
	UpdatedAt time.Time          `bson:"updatedAt"`
}

type MongoDB

type MongoDB struct {
	Client *mongo.Client
	DBName string
}
var MongoDBInstance *MongoDB

func Connect

func Connect(uri string, dbName string) (*MongoDB, error)

Connect establishes a connection to MongoDB and returns a MongoDB instance

type TestModel

type TestModel struct {
	Model      `bson:",inline"`
	Field1     string
	Field2     int
	TestModel2 *TestModel2
}

type TestModel2

type TestModel2 struct {
	Model  `bson:",inline"`
	Field3 string
	Field4 int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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