项目作者: PxyUp

项目描述 :
Managing database workflow with easiest tools!
高级语言: Go
项目地址: git://github.com/PxyUp/go-databases.git
创建时间: 2019-07-01T19:04:37Z
项目社区:https://github.com/PxyUp/go-databases

开源协议:MIT License

下载


Databases Golang

codecov

This repository will have connectors for most popular databases

How to use

All instance it is singleton, you can multiple use them in another file, without any worries about connections counts

  1. go get github.com/PxyUp/go-databases
  1. import (
  2. "github.com/PxyUp/go-databases"
  3. )
  4. func main() {
  5. instance := go_databases.GetMongoConnector()
  6. err := instance.Connect(mongoString, mongoDbName)
  7. assert.Equal(t, err, nil)
  8. user := &user{
  9. "Test",
  10. }
  11. err = instance.InsertOne(collection, user)
  12. assert.Equal(t, err, nil)
  13. }

Mongo

  1. type MongoDbConnector interface {
  2. Connect(mongoUrl string, databaseName string) error
  3. Disconnect()
  4. InsertOne(collectionName string, entity interface{}) error
  5. UpdateOne(collectionName string, findPredicate bson.M, updatePredicate bson.M) error
  6. UpdateAll(collectionName string, findPredicate bson.M, updatePredicate bson.M) (*mgo.ChangeInfo, error)
  7. GetOne(collectionName string, findPredicate bson.M, structToDeserialize interface{}) error
  8. GetAll(collectionName string, findPredicate bson.M, structToDeserialize interface{}) error
  9. GetOneProject(collectionName string, findPredicate bson.M, projectFields bson.M, structToDeserialize interface{}) error
  10. GetAllProject(collectionName string, findPredicate bson.M, projectFields bson.M, structToDeserialize interface{}) error
  11. }