-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yangyile
committed
Dec 8, 2024
1 parent
a5b96cf
commit 72321b8
Showing
3 changed files
with
50 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package gormcnm | ||
|
||
func New[T any](name string) ColumnName[T] { | ||
return ColumnName[T](name) | ||
} | ||
|
||
func Cnm[T any](v T, name string) ColumnName[T] { | ||
return ColumnName[T](name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package gormcnm | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNew(t *testing.T) { | ||
columnName := New[string]("name") | ||
|
||
qs, value := columnName.Eq("abc") | ||
t.Log(qs, value) | ||
|
||
require.Equal(t, "name=?", qs) | ||
require.Equal(t, "abc", value) | ||
} | ||
|
||
func TestCnm(t *testing.T) { | ||
type Example struct { | ||
Name string `gorm:"column:name;primary_key;type:varchar(100);"` | ||
} | ||
|
||
res := Example{} | ||
columnName := Cnm(res.Name, "name") | ||
|
||
qs, value := columnName.Eq("abc") | ||
t.Log(qs, value) | ||
|
||
require.Equal(t, "name=?", qs) | ||
require.Equal(t, "abc", value) | ||
} |