ggorm

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

README

数据库组件(mysql)

如何引用

  1. 代码
import (
    _ "github.com/GuoxinL/gcomponent/components/mysql-gorm"
)
  1. 配置文件(application.yaml)
components:
  mysql:
    dataSources:
      - name: test1
        url: 127.0.0.1:3306
        database: test1
        username: mysql
        password: mysql
        MaxIdleConns: 100
        MaxOpenConns: 10
        ConnMaxLifetime: 60
      - name: test
        url: 127.0.0.1:3306
        database: test
        username: root
        password: mysql
        MaxIdleConns: 100
        MaxOpenConns: 10
        ConnMaxLifetime: 60

如何使用

  1. func GetInstance(name string) *gorm.DB

注释:通过该方法获得gorm.DB对象 参数:name与配置文件中components.mysql.dataSources.name字段对应 返回值:*gorm.DB

Documentation

Overview

Package ggorm Created by guoxin in 2020/4/10 11:18 上午

Index

Constants

This section is empty.

Variables

View Source
var (
	DatabaseNotFound = errors.New(`database instance not found`)
)

Functions

func GetInstance

func GetInstance(name string) *gorm.DB

GetInstance 通过该方法获得*gorm.DB对象

func GetInstance0

func GetInstance0(name string) (*gorm.DB, error)

GetInstance0 通过该方法获得*gorm.DB对象

func New

func New(params ...interface{})

Types

type Configuration

type Configuration struct {
	// Make sure you only initialize it once
	core.InitializeLock

	DataSources []mysqlConfigEntity `json:"dataSources" mapstructure:"dataSources"`
}

func (*Configuration) Initialize

func (c *Configuration) Initialize(params ...interface{}) interface{}

Jump to

Keyboard shortcuts

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