16 lines
784 B
PowerShell
16 lines
784 B
PowerShell
# gen.ps1 - 极简版
|
|
& .\gentool.exe `
|
|
-dsn "root:gR9pV4tY7zR6qL3e@tcp(47.108.184.184:3306)/user_db?charset=utf8mb4&parseTime=True&loc=Local" `
|
|
-fieldSignable `
|
|
-outPath "./user_db/query"
|
|
|
|
Get-ChildItem ./user_db/model/*.gen.go | ForEach-Object {
|
|
$c = Get-Content $_.FullName -Raw -Encoding UTF8
|
|
if ($c -match '\bSn\s+int64\b' -and $c -notmatch 'BeforeCreate') {
|
|
$c -match 'type\s+(\w+)\s+struct' | Out-Null
|
|
$n = $matches[1]
|
|
$c = $c -replace '(?s)(import\s*\([^)]*)', "`$1`t`"common/utils`"`n"
|
|
$hook = "`n`n// auto sn`nfunc (m *$n) BeforeCreate(_ *gorm.DB) error {`n`tif m.Sn == 0 {`n`t`tm.Sn = utils.SnowflakeInstance().Generate().Int64()`n`t}`n`treturn nil`n}"
|
|
Set-Content $_.FullName ($c.TrimEnd() + $hook) -Encoding UTF8
|
|
}
|
|
} |