Merge pull request #5257 from flycash/develop

closes 5254: %COL% should be a common placeholder
This commit is contained in:
Ming Deng 2023-06-20 17:54:03 +08:00 committed by GitHub
commit 2dbd5d2f90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 3 deletions

View File

@ -1,8 +1,9 @@
# developing
- [httplib: fix unstable unit test which use the httplib.org](https://github.com/beego/beego/pull/5232)
- [remove adapter package](https://github.com/beego/beego/pull/5239)
- [rft: remove adapter package](https://github.com/beego/beego/pull/5239)
- [feat: add write-delete cache mode](https://github.com/beego/beego/pull/5242)
- [fix 5255: Check the rows.Err() if rows.Next() is false](https://github.com/beego/beego/pull/5256)
- [orm: missing handling %COL% placeholder](https://github.com/beego/beego/pull/5257)
## ORM refactoring
- [introducing internal/models pkg](https://github.com/beego/beego/pull/5238)

View File

@ -33,6 +33,11 @@ func getColumnTyp(al *alias, fi *models.FieldInfo) (col string) {
fieldType := fi.FieldType
fieldSize := fi.Size
defer func() {
// handling the placeholder, including %COL%
col = strings.ReplaceAll(col, "%COL%", fi.Column)
}()
checkColumn:
switch fieldType {
case TypeBooleanField:

View File

@ -0,0 +1,37 @@
package orm
import (
"github.com/beego/beego/v2/client/orm/internal/models"
"github.com/stretchr/testify/assert"
"testing"
)
func Test_getColumnTyp(t *testing.T) {
testCases := []struct {
name string
fi *models.FieldInfo
al *alias
wantCol string
}{
{
// https://github.com/beego/beego/issues/5254
name: "issue 5254",
fi: &models.FieldInfo{
FieldType: TypePositiveIntegerField,
Column: "my_col",
},
al: &alias{
DbBaser: newdbBasePostgres(),
},
wantCol: `bigint CHECK("my_col" >= 0)`,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
col := getColumnTyp(tc.al, tc.fi)
assert.Equal(t, tc.wantCol, col)
})
}
}

View File

@ -39,12 +39,12 @@ func serverStaticRouter(ctx *context.Context) {
return
}
forbidden, filePath, fileInfo, err := lookupFile(ctx)
fbd, filePath, fileInfo, err := lookupFile(ctx)
if err == errNotStaticRequest {
return
}
if forbidden {
if fbd {
exception("403", ctx)
return
}