egorm

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2021 License: MIT Imports: 28 Imported by: 4

README

egorm 组件使用指南

简介

gorm 进行了轻量封装,并提供了以下功能:

  • 规范了标准配置格式,提供了统一的 Load().Build() 方法。
  • 支持自定义拦截器
  • 提供了默认的 Debug 拦截器,开启 Debug 后可输出 Request、Response 至终端。
  • 提供了默认的 Metric 拦截器,开启后可采集 Prometheus 指标数据
  • 提供了默认的 OpenTracing 拦截器,开启后可采集 Tracing Span 数据

快速上手

数据库使用样例可参考 example

Documentation

Index

Constants

View Source
const PackageName = "component.egorm"

PackageName ...

Variables

View Source
var (

	// ErrRecordNotFound returns a "record not found error". Occurs only when attempting to query the database with a struct; querying with a slice won't return this error
	ErrRecordNotFound = gorm.ErrRecordNotFound
	// ErrInvalidTransaction occurs when you are trying to `Commit` or `Rollback`
	ErrInvalidTransaction = gorm.ErrInvalidTransaction
)

Functions

func BuildQuery added in v0.2.1

func BuildQuery(conds Conds) (sql string, binds []interface{})

BuildQuery 根据conds构建sql和绑定的参数

func DefaultConfig

func DefaultConfig() *config

DefaultConfig 返回默认配置

Types

type Association

type Association = gorm.Association

Association ...

type Component

type Component = gorm.DB

Component ...

func WithContext added in v0.2.0

func WithContext(ctx context.Context, db *Component) *Component

WithContext ...

type Cond added in v0.2.1

type Cond struct {
	// Op MySQL中查询条件,如like,=,in
	Op string
	// Val 查询条件对应的值
	Val interface{}
}

Cond 为字段查询结构体

type Conds added in v0.2.1

type Conds map[string]interface{}

Conds 为Cond类型map,用于定义Where方法参数 map[field.name]interface{}

type Container

type Container struct {
	// contains filtered or unexported fields
}

Container ...

func DefaultContainer

func DefaultContainer() *Container

DefaultContainer ...

func Load

func Load(key string) *Container

Load ...

func (*Container) Build

func (c *Container) Build(options ...Option) *Component

Build 构建组件

type DB added in v0.2.0

type DB gorm.DB

DB ...

type Dialector added in v0.2.0

type Dialector = gorm.Dialector

Dialector ...

type Field

type Field = schema.Field

Field ...

type Handler

type Handler func(*gorm.DB)

Handler ...

type Interceptor

type Interceptor func(string, *dsn.DSN, string, *config, *elog.Component) func(next Handler) Handler

Interceptor ...

type Logger

type Logger = logger.Interface

Logger ...

type Model

type Model = gorm.Model

Model ...

type NamingStrategy added in v0.2.0

type NamingStrategy = schema.NamingStrategy

NamingStrategy ...

type Option

type Option func(c *Container)

Option 可选项

func WithDSNParser added in v0.2.0

func WithDSNParser(parser dsn.DSNParser) Option

WithDSNParser 设置自定义dsnParser

func WithInterceptor

func WithInterceptor(is ...Interceptor) Option

WithInterceptor 设置自定义拦截器

type Processor added in v0.2.0

type Processor interface {
	Get(name string) func(*gorm.DB)
	Replace(name string, handler func(*gorm.DB)) error
}

Processor ...

type Ups added in v0.2.1

type Ups = map[string]interface{}

Ups 为更新某一条记录时存放的变更数据集合 map[field.name]field.value

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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