Parcourir la source

Create custom name mapping with TableName interface or struct tags.

Frederic G. MARAND il y a 9 ans
Parent
commit
ddb7ef5985
1 fichiers modifiés avec 12 ajouts et 0 suppressions
  1. 12 0
      main.go

+ 12 - 0
main.go

@@ -29,6 +29,18 @@ import (
 	"github.com/go-xorm/core"
 )
 
+type Foo struct {
+	Baz string `xorm:`
+}
+
+// Implement the TableName interface to generate a fully custom table name for
+// a struct type.
+//
+// @see xorm.TableName interface.
+func (f Foo) TableName() string {
+	return "foobar";
+}
+
 func check(err error) {
 	if err != nil {
 		fmt.Println(err.Error())