20 lines
892 B
PowerShell
20 lines
892 B
PowerShell
# gen.ps1 - 支持参数版
|
|
param(
|
|
[Parameter(Mandatory=$true)]
|
|
[string]$dbName
|
|
)
|
|
& .\gentool.exe `
|
|
-dsn "root:gR9pV4tY7zR6qL3e@tcp(47.108.184.184:3306)/${dbName}?charset=utf8mb4&parseTime=True&loc=Local" `
|
|
-fieldSignable `
|
|
-outPath "./${dbName}/query"
|
|
|
|
Get-ChildItem ./${dbName}/model/*.gen.go | ForEach-Object {
|
|
$c = Get-Content $_.FullName -Raw -Encoding UTF8
|
|
if ($c -match '\bSn\s+string\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`"git.hlsq.asia/mmorpg/service-common/utils`"`n"
|
|
$hook = "`n`n// Auto sn`nfunc (m *$n) BeforeCreate(_ *gorm.DB) error {`n`tif m.Sn == `"`" {`n`t`tm.Sn = utils.SnowflakeInstance().Generate().String()`n`t}`n`treturn nil`n}"
|
|
Set-Content $_.FullName ($c.TrimEnd() + $hook) -Encoding UTF8
|
|
}
|
|
} |