wajox / mongol

mongoDB DBAL based on the official mongoDB Golang driver

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mongol

License: MIT Go Reference codecov Go workflow Go Report Card

Model Example

type ExampleModel struct {
	mongol.BaseDocument `bson:",inline"`
	// Default fields from BaseDocument
	//
	// ID        primitive.ObjectID `json:"id,omitempty" bson:"_id,omitempty"`
	// CreatedAt time.Time          `json:"created_at" bson:"created_at"`
	// UpdatedAt time.Time          `json:"updated_at" bson:"updated_at"`

	Title string `json:"title,omitempty" bson:"title,omitempty"`
}

Storage usage example

storage, connErr = NewBaseCollection(context.TODO(), mongoURI, mongoDBName, mongoCollectionName)

m := &ExampleModel{}

id, saveErr := storage.InsertOne(context.TODO(), m)

Fiilter example

newM := &ExampleModel{}

err := storage.GetOneByFilter(
	context.TODO(),
	NewFilterBuilder().EqualTo("_id", m.ID).GetQuery(),
	newM,
)

if err != nil {
	fmt.Printf("%#v", newM)
}

Run tests

make test-all
MONGODB_URI=mongodb://localhost:27017 go test -a -v ./...

About

mongoDB DBAL based on the official mongoDB Golang driver

License:MIT License


Languages

Language:Go 99.2%Language:Makefile 0.8%