docs: Add CLAUDE.md with codebase guidance
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>
This commit is contained in:
@@ -3,11 +3,11 @@ package mysql
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"git.fsdpf.net/go/db/v2"
|
||||
"git.fsdpf.net/go/db/v2/dialect/mysql"
|
||||
"git.fsdpf.net/go/db/v2/internal/sb"
|
||||
"git.fsdpf.net/go/db/v2/schema"
|
||||
"git.fsdpf.net/go/db/v2/sqlgen"
|
||||
"git.fsdpf.net/go/db"
|
||||
"git.fsdpf.net/go/db/dialect/mysql"
|
||||
"git.fsdpf.net/go/db/internal/sb"
|
||||
"git.fsdpf.net/go/db/schema"
|
||||
"git.fsdpf.net/go/db/sqlgen"
|
||||
)
|
||||
|
||||
type Mysql struct {
|
||||
@@ -16,6 +16,7 @@ type Mysql struct {
|
||||
}
|
||||
|
||||
var mysqlDefaultModifiers = []string{
|
||||
|
||||
"Unsigned", "Charset", "Collate", "VirtualAs", "StoredAs",
|
||||
"Nullable", "Default", "Increment", "Comment", "After", "First",
|
||||
}
|
||||
@@ -47,29 +48,33 @@ func (this Mysql) TableExists(table string) (bool, error) {
|
||||
// 创建表
|
||||
func (this Mysql) CompileCreate(bp *schema.Blueprint) []string {
|
||||
temporary := db.L("CREATE")
|
||||
if bp.IsTemporary() {
|
||||
if bp.Temporary {
|
||||
temporary = db.L("CREATE TEMPORARY")
|
||||
}
|
||||
columns := strings.Join(this.getAddedColumns(bp), ",\n")
|
||||
|
||||
sql := this.GenerateSQL("? TABLE ? (\n?\n)", temporary, db.T(bp.GetTable()), db.L(columns))
|
||||
|
||||
charset := bp.GetCharset()
|
||||
charset := bp.Charset
|
||||
if charset == "" {
|
||||
charset = "utf8mb4"
|
||||
}
|
||||
|
||||
collation := bp.GetCollation()
|
||||
collation := bp.Collation
|
||||
if collation == "" {
|
||||
collation = "utf8mb4_general_ci"
|
||||
}
|
||||
|
||||
sql += this.GenerateSQL(" default charset=? collate=?", charset, collation)
|
||||
|
||||
if engine := bp.GetEngine(); engine != "" {
|
||||
if engine := bp.Engine; engine != "" {
|
||||
sql += this.GenerateSQL(" engine=?", engine)
|
||||
}
|
||||
|
||||
if comment := bp.Comment; comment != "" {
|
||||
sql += this.GenerateSQL(" comment=?", comment)
|
||||
}
|
||||
|
||||
return []string{sql}
|
||||
}
|
||||
|
||||
@@ -121,13 +126,18 @@ func (this Mysql) CompileRename(bp *schema.Blueprint) []string {
|
||||
if len(commands) == 0 {
|
||||
panic("new table undefined")
|
||||
}
|
||||
toName = bp.GetCommands()[0].To
|
||||
toName = commands[0].To
|
||||
if toName == "" {
|
||||
panic("new table undefined")
|
||||
}
|
||||
return []string{this.GenerateSQL("RENAME TABLE ? TO ?", db.T(bp.GetTable()), db.T(toName))}
|
||||
}
|
||||
|
||||
// 修改表备注
|
||||
func (this Mysql) CompileModifyComment(bp *schema.Blueprint) []string {
|
||||
return []string{this.GenerateSQL("ALTER TABLE ? COMMENT = ?", db.T(bp.GetTable()), db.V(bp.Comment))}
|
||||
}
|
||||
|
||||
func (this Mysql) addModifiers(sql string, bp *schema.Blueprint, column *schema.ColumnDefinition) string {
|
||||
for _, modifier := range mysqlDefaultModifiers {
|
||||
sql += this.GetColumnModifier(modifier, bp, column)
|
||||
|
||||
Reference in New Issue
Block a user