Create comprehensive documentation for future Claude Code instances working in this repository, including: - Development commands for testing, building, and code quality - Core architecture overview of the SQL query builder system - Directory structure and component explanations - Testing patterns and conventions - Key dependencies and their purposes 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
62 lines
1.3 KiB
Go
62 lines
1.3 KiB
Go
package schema
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"sync"
|
|
|
|
"git.fsdpf.net/go/db"
|
|
)
|
|
|
|
type Schema interface {
|
|
// 判断表是否存在
|
|
TableExists(table string) (bool, error)
|
|
// 字段列
|
|
GetColumnListing(table string) ([]string, error)
|
|
// 创建表
|
|
CompileCreate(bp *Blueprint) []string
|
|
// 添加字段
|
|
CompileAdd(bp *Blueprint) []string
|
|
// 修改字段
|
|
CompileChange(bp *Blueprint) []string
|
|
// 删除表
|
|
CompileDrop(bp *Blueprint) []string
|
|
// 删除表, 先判断再删除
|
|
CompileDropIfExists(bp *Blueprint) []string
|
|
// 删除表, 删除列
|
|
CompileDropColumn(bp *Blueprint) []string
|
|
// 表重命名
|
|
CompileRename(bp *Blueprint) []string
|
|
// 修改表备注
|
|
CompileModifyComment(bp *Blueprint) []string
|
|
// 生成SQL
|
|
GenerateSQL(sql string, args ...any) string
|
|
}
|
|
|
|
var (
|
|
dialects = make(map[string]func(db *db.Database) Schema)
|
|
dialectsMu sync.RWMutex
|
|
)
|
|
|
|
func RegisterDialect(name string, sc func(db *db.Database) Schema) {
|
|
dialectsMu.Lock()
|
|
defer dialectsMu.Unlock()
|
|
lowerName := strings.ToLower(name)
|
|
dialects[lowerName] = sc
|
|
}
|
|
|
|
func DeregisterDialect(name string) {
|
|
dialectsMu.Lock()
|
|
defer dialectsMu.Unlock()
|
|
delete(dialects, strings.ToLower(name))
|
|
}
|
|
|
|
func GetSchemaDialect(db *db.Database) Schema {
|
|
name := strings.ToLower(db.Dialect())
|
|
if d, ok := dialects[name]; ok {
|
|
return d(db)
|
|
}
|
|
|
|
panic(fmt.Sprintf("Unsupported driver: %s", name))
|
|
}
|