Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

PxyUp/go-databases

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

go get github.com/PxyUp/go-databases
import (
	"github.com/PxyUp/go-databases"
)

func main() {
    instance := go_databases.GetMongoConnector()
    err := instance.Connect(mongoString, mongoDbName)
    assert.Equal(t, err, nil)
    user := &user{
        "Test",
    }
    err = instance.InsertOne(collection, user)
    assert.Equal(t, err, nil)
}

Mongo

type MongoDbConnector interface {
	Connect(mongoUrl string, databaseName string) error
	Disconnect()
	InsertOne(collectionName string, entity interface{}) error
	UpdateOne(collectionName string, findPredicate bson.M, updatePredicate bson.M) error
	UpdateAll(collectionName string, findPredicate bson.M, updatePredicate bson.M) (*mgo.ChangeInfo, error)
	GetOne(collectionName string, findPredicate bson.M, structToDeserialize interface{}) error
	GetAll(collectionName string, findPredicate bson.M, structToDeserialize interface{}) error
	GetOneProject(collectionName string, findPredicate bson.M, projectFields bson.M, structToDeserialize interface{}) error
	GetAllProject(collectionName string, findPredicate bson.M, projectFields bson.M, structToDeserialize interface{}) error
}