models

package
v0.0.0-...-487d569 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppDB

func AppDB() *gorm.DB

AppDB return the default connection of the application

func GormDB

func GormDB(connectionName string) *gorm.DB

GormDB return a Gorm connection by name

func InitModel

func InitModel()

InitModel this function is the mean to init the model global var and start connections

func MongoCol

func MongoCol(ctx context.Context, collectionName string) *mongo.Collection

func MongoColInConn

func MongoColInConn(connectionName string, collectionName string) *mongo.Collection

func MongoColInConnOnDatabase

func MongoColInConnOnDatabase(connectionName string, collectionName string, database string) *mongo.Collection

func MongoDb

func MongoDb(connectionName string) *mongo.Client

MongoDb return a MongoDB connection by name. If empty is empty so will try return the connection of MONGO_DB_CONNECTION env var

func NewModel

func NewModel()

NewModel set the model glabal var

func TestInsertPerson

func TestInsertPerson()

Types

type BaseModel

type BaseModel struct {
	DbConns map[string]interface{}

	//register your types here
	MysqlConn *gfmodel.MysqlConn
	MongoConn *gfmodel.MongoConn
}

BaseModel is a datastruct that handler the connections

var Model *BaseModel

Model is a global var that handler connections of application

func (*BaseModel) CloseModels

func (b *BaseModel) CloseModels()

type Person

type Person struct {
	ID        primitive.ObjectID `bson:"_id"`
	Name      string             `bson:"name"`
	CreatedAt time.Time          `bson:"created_at"`
	UpdatedAt time.Time          `bson:"updated_at"`
}

type Product

type Product struct {
	gorm.Model
	Code  string
	Price uint
}

func InitProduct

func InitProduct() *Product

func (*Product) TestDB

func (p *Product) TestDB()

Jump to

Keyboard shortcuts

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