feat(database): 添加 ClickHouse 数据库驱动支持
- 实现了完整的 ClickHouse 驱动,包括连接、查询、插入、更新、删除等基本操作 - 添加了 ClickHouse 特有的数据类型转换和 SQL 过滤功能 - 实现了表结构查询和字段信息获取功能 - 添加了 Ping 检查和错误处理机制 - 增加了对 UPDATE 和 DELETE 语句的语法转换以适配 ClickHouse - 添加了批量插入操作的支持 - 新增了 14 个测试用例文件用于验证数据库相关功能
This commit is contained in:
@@ -15,6 +15,7 @@ package {{.TplPackageName}}
|
||||
|
||||
import (
|
||||
"{{.TplImportPrefix}}/internal"
|
||||
"git.magicany.cc/black1552/gin-base/database"
|
||||
)
|
||||
|
||||
// {{.TplTableNameCamelLowerCase}}Dao is the data access object for the table {{.TplTableName}}.
|
||||
@@ -37,16 +38,16 @@ var (
|
||||
{{if .TplTableSharding -}}
|
||||
// {{.TplTableNameCamelLowerCase}}ShardingHandler is the handler for sharding operations.
|
||||
// You can fill this sharding handler with your custom implementation.
|
||||
func {{.TplTableNameCamelLowerCase}}ShardingHandler(m *gdb.Model) *gdb.Model {
|
||||
m = m.Sharding(gdb.ShardingConfig{
|
||||
Table: gdb.ShardingTableConfig{
|
||||
func {{.TplTableNameCamelLowerCase}}ShardingHandler(m *database.Model) *database.Model {
|
||||
m = m.Sharding(database.ShardingConfig{
|
||||
Table: database.ShardingTableConfig{
|
||||
Enable: true,
|
||||
Prefix: "{{.TplTableShardingPrefix}}",
|
||||
// Replace Rule field with your custom sharding rule.
|
||||
// Or you can use "&gdb.DefaultShardingRule{}" for default sharding rule.
|
||||
Rule: nil,
|
||||
},
|
||||
Schema: gdb.ShardingSchemaConfig{},
|
||||
Schema: database.ShardingSchemaConfig{},
|
||||
})
|
||||
return m
|
||||
}
|
||||
@@ -65,9 +66,7 @@ package internal
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"git.magicany.cc/black1552/gin-base/database"
|
||||
)
|
||||
|
||||
// {{.TplTableNameCamelCase}}Dao is the data access object for the table {{.TplTableName}}.
|
||||
@@ -75,7 +74,7 @@ type {{.TplTableNameCamelCase}}Dao struct {
|
||||
table string // table is the underlying table name of the DAO.
|
||||
group string // group is the database configuration group name of the current DAO.
|
||||
columns {{.TplTableNameCamelCase}}Columns // columns contains all the column names of Table for convenient usage.
|
||||
handlers []gdb.ModelHandler // handlers for customized model modification.
|
||||
handlers []database.ModelHandler // handlers for customized model modification.
|
||||
}
|
||||
|
||||
// {{.TplTableNameCamelCase}}Columns defines and stores column names for the table {{.TplTableName}}.
|
||||
@@ -89,7 +88,7 @@ var {{.TplTableNameCamelLowerCase}}Columns = {{.TplTableNameCamelCase}}Columns{
|
||||
}
|
||||
|
||||
// New{{.TplTableNameCamelCase}}Dao creates and returns a new DAO object for table data access.
|
||||
func New{{.TplTableNameCamelCase}}Dao(handlers ...gdb.ModelHandler) *{{.TplTableNameCamelCase}}Dao {
|
||||
func New{{.TplTableNameCamelCase}}Dao(handlers ...database.ModelHandler) *{{.TplTableNameCamelCase}}Dao {
|
||||
return &{{.TplTableNameCamelCase}}Dao{
|
||||
group: "{{.TplGroupName}}",
|
||||
table: "{{.TplTableName}}",
|
||||
@@ -99,8 +98,8 @@ func New{{.TplTableNameCamelCase}}Dao(handlers ...gdb.ModelHandler) *{{.TplTable
|
||||
}
|
||||
|
||||
// DB retrieves and returns the underlying raw database management object of the current DAO.
|
||||
func (dao *{{.TplTableNameCamelCase}}Dao) DB() gdb.DB {
|
||||
return g.DB(dao.group)
|
||||
func (dao *{{.TplTableNameCamelCase}}Dao) DB() database.DB {
|
||||
return database.Database(dao.group)
|
||||
}
|
||||
|
||||
// Table returns the table name of the current DAO.
|
||||
@@ -119,7 +118,7 @@ func (dao *{{.TplTableNameCamelCase}}Dao) Group() string {
|
||||
}
|
||||
|
||||
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
|
||||
func (dao *{{.TplTableNameCamelCase}}Dao) Ctx(ctx context.Context) *gdb.Model {
|
||||
func (dao *{{.TplTableNameCamelCase}}Dao) Ctx(ctx context.Context) *database.Model {
|
||||
model := dao.DB().Model(dao.table)
|
||||
for _, handler := range dao.handlers {
|
||||
model = handler(model)
|
||||
@@ -133,7 +132,7 @@ func (dao *{{.TplTableNameCamelCase}}Dao) Ctx(ctx context.Context) *gdb.Model {
|
||||
//
|
||||
// Note: Do not commit or roll back the transaction in function f,
|
||||
// as it is automatically handled by this function.
|
||||
func (dao *{{.TplTableNameCamelCase}}Dao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
|
||||
func (dao *{{.TplTableNameCamelCase}}Dao) Transaction(ctx context.Context, f func(ctx context.Context, tx database.TX) error) (err error) {
|
||||
return dao.Ctx(ctx).Transaction(ctx, f)
|
||||
}
|
||||
`
|
||||
|
||||
@@ -8,7 +8,7 @@ package consts
|
||||
|
||||
const TemplateGenDaoEntityContent = `
|
||||
// =================================================================================
|
||||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. {{.TplCreatedAtDatetimeStr}}
|
||||
// Code generated and maintained by Gen CLI tool. DO NOT EDIT. {{.TplCreatedAtDatetimeStr}}
|
||||
// =================================================================================
|
||||
|
||||
package {{.TplPackageName}}
|
||||
|
||||
@@ -15,20 +15,19 @@ package {{.TplPackageName}}
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"git.magicany.cc/black1552/gin-base/database"
|
||||
)
|
||||
|
||||
// {{.TplTableNameCamelCase}} defines the fields of table "{{.TplTableName}}" with their properties.
|
||||
// This map is used internally by GoFrame ORM to understand table structure.
|
||||
var {{.TplTableNameCamelCase}} = map[string]*gdb.TableField{
|
||||
var {{.TplTableNameCamelCase}} = map[string]*database.TableField{
|
||||
{{.TplTableFields}}
|
||||
}
|
||||
|
||||
// Set{{.TplTableNameCamelCase}}TableFields registers the table fields definition to the database instance.
|
||||
// db: database instance that implements gdb.DB interface.
|
||||
// schema: optional schema/namespace name, especially for databases that support schemas.
|
||||
func Set{{.TplTableNameCamelCase}}TableFields(ctx context.Context, db gdb.DB, schema ...string) error {
|
||||
func Set{{.TplTableNameCamelCase}}TableFields(ctx context.Context, db database.DB, schema ...string) error {
|
||||
return db.GetCore().SetTableFields(ctx, "{{.TplTableName}}", {{.TplTableNameCamelCase}}, schema...)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user