Categorygithub.com/kotlin2018/orm
modulepackage
0.1.1
Repository: https://github.com/kotlin2018/orm.git
Documentation: pkg.go.dev

# README

核心结构简介

与GoFrame/orm兼容,主要是修改了gf/database/gdb目录

GoFrame地址

github地址

  • DB interface是直接操作数据库的接口,里面定义了一系列操作数据库的方法。
type DB interface {
        Insert(table string, data interface{}, batch ...int) (sql.Result, error)
        InsertIgnore(table string, data interface{}, batch ...int) (sql.Result, error)
        Replace(table string, data interface{}, batch ...int) (sql.Result, error)
        Save(table string, data interface{}, batch ...int) (sql.Result, error)
        ...
} 
  • Core是数据库管理的基础结构。只实现了 DB接口的一部分方法,是所有SQL驱动的基类(父类)。

    各种数据库驱动要想操作数据,必须完全实现DB接口,但这必定会造成代码冗余。

    例如:

    Mysql驱动实现了 Insert()、InsertIgnore()、Replace()、Save()...

    Pgsql也实现了 Insert()、InsertIgnore()、Replace()、Save()...

    这部分公共的方法完全可以抽取出来,只让Core结构体实现,所有的数据库驱动只要继承(内嵌)Core结构体即可;

    这样各种数据库驱动就间接的实现了 Insert()、InsertIgnore()、Replace()、Save()...等放法。

type Core struct {
	DB     DB              // DB 接口对象。持有DB实例,使Model结构体具备操作数据库的能力。
    group  string          // 配置组的组名。
    debug  *gtype.Bool     // 为数据库启用debug模式,该模式可以在运行时更改。
    cache  *gcache.Cache   // 缓存管理器,仅缓存SQL结果。
    schema *gtype.String   // 当前对象对象的自定义架构,可以方便的在运行时切换数据库。
    logger *glog.Logger    // Logger.
    config *ConfigNode     // 当前配置节点
    ctx    context.Context // 仅链接操作的上下文。
}  
                 
  • Modelormdao (Data Access Object)数据库访问对象
type Model struct {
    db    DB       // 底层数据库接口。持有这个实例就具备了操作数据的能力。
    tx    *TX      // 底层事务管理接口。   
    ...
}

# Packages

No description provided by the author

# Functions

AddConfigNode adds one node configuration to configuration of given group.
AddDefaultConfigGroup adds multiple node configurations to configuration of default group.
AddDefaultConfigNode adds one node configuration to configuration of default group.
ConvertDataForTableRecord is a very important function, which does converting for any data that will be inserted into table as a record.
DataToMapDeep converts <value> to map type recursively.
FormatSqlWithArgs binds the arguments to the sql string and returns a complete sql string, just for debugging.
GetConfig retrieves and returns the configuration of given group.
GetDefaultGroup returns the { name of default configuration.
GetInsertOperationByOption returns proper insert option with given parameter <option>.
GetPrimaryKey retrieves and returns primary key field name from given struct.
GetPrimaryKeyCondition returns a new where condition by primary field name.
GetWhereConditionOfStruct returns the where condition sql and arguments by given struct pointer.
Instance returns an instance for DB operations.
IsConfigured checks and returns whether the database configured.
ListItemValues retrieves and returns the elements of all item struct/map with key <key>.
ListItemValuesUnique retrieves and returns the unique elements of all struct/map with key <key>.
New creates and returns an ORM object with global configurations.
Register registers custom database driver to gdb.
SetConfig sets the global configuration for package.
SetConfigGroup sets the configuration for given group.
SetDefaultGroup sets the group name for default configuration.

# Constants

Default group name.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

ErrNoRows is alias of sql.ErrNoRows.

# Structs

ConfigNode is configuration for one node.
Core is the base struct for database management.
Counter is the type for update count.
DriverMssql is the driver for SQL server database.
DriverMysql is the driver for mysql database.
DriverOracle is the driver for oracle database.
DriverPgsql is the driver for postgresql database.
DriverSqlite is the driver for sqlite database.
Model is the DAO for ORM.
Schema is a schema object from which it can then create a Model.
Sql is the sql recording struct.
SqlResult is execution result for sql operations.
Stmt is a prepared statement.
TableField is the struct for table field.
TX is the struct for transaction management.

# Interfaces

DB defines the interfaces for ORM operations.
Driver is the interface for integrating sql drivers into package gdb.
Link is a common database function wrapper interface.

# Type aliases

Config is the configuration management object.
ConfigGroup is a slice of configuration node for specified named group.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author