Repository: ovn-org/libovsdb
Pull request #156 (2021-06-10 18:42:56)

modelgen: Separate API for data and template
This changes the API for Modelgen such that:

1. We call to get a `*template.Template` which can be modified with further calls to `Parse`
2. We call to `GetXTemplateData` to get the data for that template
3. It places Enum expansion inside it's own template


coveralls: ## Pull Request Test Coverage Report for [Build 926161046](https://coveralls.io/builds/40488785)

* **48** of **63**   **(76.19%)**  changed or added relevant lines in **2** files are covered.
* **14** unchanged lines in **1** file lost coverage.
* Overall coverage increased (+**0.06%**) to **72.373%**

---

|  Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
| :-----|--------------|--------|---: |
| [modelgen/dbmodel.go](https://coveralls.io/builds/40488785/source?filename=modelgen%2Fdbmodel.go#L16) | 0 | 15 | 0.0%
<!-- | **Total:** | **48** | **63** | **76.19%** | -->

|  Files with Coverage Reduction | New Missed Lines | % |
| :-----|--------------|--: |
| [modelgen/dbmodel.go](https://coveralls.io/builds/40488785/source?filename=modelgen%2Fdbmodel.go#L29) | 14 | 0% |
<!-- | **Total:** | **14** |  | -->

|  Totals | [![Coverage Status](https://coveralls.io/builds/40488785/badge)](https://coveralls.io/builds/40488785) |
| :-- | --: |
| Change from base [Build 925628912](https://coveralls.io/builds/40481229): |  0.06% |
| Covered Lines: | 2824 |
| Relevant Lines: | 3902 |

---
##### 💛  - [Coveralls](https://coveralls.io)


Patch:
diff --git a/README.md b/README.md
index 1472d2e..94e3988 100644
--- a/README.md
+++ b/README.md
@@ -16,10 +16,10 @@ It's used mainly for managing the configuration of Open vSwitch and OVN, but it
 The API to interact with OVSDB is based on tagged golang structs. We call it a Model. e.g:
 
     type MyLogicalSwitch struct {
-        UUID   string            `ovsdb:"_uuid"` // _uuid tag is mandatory
-        Name   string            `ovsdb:"name"`
-        Ports  []string          `ovsdb:"ports"`
-        Config map[string]string `ovsdb:"other_config"`
+        UUID   string            `ovs:"_uuid"` // _uuid tag is mandatory
+        Name   string            `ovs:"name"`
+        Ports  []string          `ovs:"ports"`
+        Config map[string]string `ovs:"other_config"`
     }
 
 A Open vSwitch Database is modeled using a DBModel which is a created by assigning table names to pointers to these structs:
diff --git a/client/doc.go b/client/doc.go
index 5abd146..8e2e14e 100644
--- a/client/doc.go
+++ b/client/doc.go
@@ -5,10 +5,10 @@ This package uses structs, that contain the 'ovs' field tag to determine which f
 which column in the database. We refer to pointers to this structs as Models. Example:
 
    type MyLogicalSwitch struct {
-   	UUID   string            `ovsdb:"_uuid"` // _uuid tag is mandatory
-   	Name   string            `ovsdb:"name"`
-   	Ports  []string          `ovsdb:"ports"`
-   	Config map[string]string `ovsdb:"other_config"`
+   	UUID   string            `ovs:"_uuid"` // _uuid tag is mandatory
+   	Name   string            `ovs:"name"`
+   	Ports  []string          `ovs:"ports"`
+   	Config map[string]string `ovs:"other_config"`
    }
 
 Based on these Models a Database Model (see DBModel type) is built to represent
diff --git a/cmd/modelgen/main.go b/cmd/modelgen/main.go
index 4b12815..12c5327 100644
--- a/cmd/modelgen/main.go
+++ b/cmd/modelgen/main.go
@@ -67,12 +67,14 @@ func main() {
 
 	gen := modelgen.NewGenerator(*dryRun)
 	for name, table := range dbSchema.Tables {
-		template, args := modelgen.NewTableTemplate(pkgName, name, &table)
-		if err := gen.Generate(modelgen.FileName(name), template, args); err != nil {
+		tmpl := modelgen.NewTableTemplate()
+		args := modelgen.GetTableTemplateData(pkgName, name, &table)
+		if err := gen.Generate(modelgen.FileName(name), tmpl, args); err != nil {
 			log.Fatal(err)
 		}
 	}
-	dbTemplate, dbArgs := modelgen.NewDBTemplate(pkgName, &dbSchema)
+	dbTemplate := modelgen.NewDBTemplate()
+	dbArgs := modelgen.GetDBTemplateData(pkgName, &dbSchema)
 	if err := gen.Generate("model.go", dbTemplate, dbArgs); err != nil {
 		log.Fatal(err)
 	}
diff --git a/cmd/stress/stress.go b/cmd/stress/stress.go
index 88459c6..4adcbf2 100644
--- a/cmd/stress/stress.go
+++ b/cmd/stress/stress.go
@@ -21,18 +21,18 @@ import (
 
 // ORMBridge is the simplified ORM model of the Bridge table
 type bridgeType struct {
-	UUID        string            `ovsdb:"_uuid"`
-	Name        string            `ovsdb:"name"`
-	OtherConfig map[string]string `ovsdb:"other_config"`
-	ExternalIds map[string]string `ovsdb:"external_ids"`
-	Ports       []string          `ovsdb:"ports"`
-	Status      map[string]string `ovsdb:"status"`
+	UUID        string            `ovs:"_uuid"`
+	Name        string            `ovs:"name"`
+	OtherConfig map[string]string `ovs:"other_config"`
+	ExternalIds map[string]string `ovs:"external_ids"`
+	Ports       []string          `ovs:"ports"`
+	Status      map[string]string `ovs:"status"`
 }
 
 // ORMovs is the simplified ORM model of the Bridge table
 type ovsType struct {
-	UUID    string   `ovsdb:"_uuid"`
-	Bridges []string `ovsdb:"bridges"`
+	UUID    string   `ovs:"_uuid"`
+	Bridges []string `ovs:"bridges"`
 }
 
 var (
diff --git a/mapper/info.go b/mapper/info.go
index a6fe57b..2e034e8 100644
--- a/mapper/info.go
+++ b/mapper/info.go
@@ -57,7 +57,7 @@ func (mi *MapperInfo) ColumnByPtr(fieldPtr interface{}) (string, error) {
 	objType := reflect.TypeOf(mi.obj).Elem()
 	for i := 0; i < objType.NumField(); i++ {
 		if objType.Field(i).Offset == offset {
-			column := objType.Field(i).Tag.Get("ovsdb")
+			column := objType.Field(i).Tag.Get("ovs")
 			if _, ok := mi.fields[column]; !ok {
 				return "", fmt.Errorf("field does not have orm column information")
 			}
@@ -115,7 +115,7 @@ func NewMapperInfo(table *ovsdb.TableSchema, obj interface{}) (*MapperInfo, erro
 	fields := make(map[string]string, objType.NumField())
 	for i := 0; i < objType.NumField(); i++ {
 		field := objType.Field(i)
-		colName := field.Tag.Get("ovsdb")
+		colName := field.Tag.Get("ovs")
 		if colName == "" {
 			// Untagged fields are ignored
 			continue
diff --git a/mapper/mapper.go b/mapper/mapper.go
index b49fe55..a68d37e 100644
--- a/mapper/mapper.go
+++ b/mapper/mapper.go
@@ -10,13 +10,13 @@ import (
 // Mapper offers functions to interact with libovsdb through user-provided native structs.
 // The way to specify what field of the struct goes
 // to what column in the database id through field a field tag.
-// The tag used is "ovsdb" and has the following structure
-// 'ovsdb:"${COLUMN_NAME}"'
+// The tag used is "ovs" and has the following structure
+// 'ovs:"${COLUMN_NAME}"'
 //	where COLUMN_NAME is the name of the column and must match the schema
 //
 //Example:
 //  type MyObj struct {
-//  	Name string `ovsdb:"name"`
+//  	Name string `ovs:"name"`
 //  }
 type Mapper struct {
 	Schema *ovsdb.DatabaseSchema
@@ -163,7 +163,7 @@ func (m Mapper) NewRow(tableName string, data interface{}, fields ...interface{}
 
 // NewEqualityCondition returns a list of equality conditions that match a given object
 // A list of valid columns that shall be used as a index can be provided.
-// If none are provided, we will try to use object's field that matches the '_uuid' ovsdb tag
+// If none are provided, we will try to use object's field that matches the '_uuid' ovs tag
 // If it does not exist or is null (""), then we will traverse all of the table indexes and
 // use the first index (list of simultaneously unique columnns) for which the provided mapper
 // object has valid data. The order in which they are traversed matches the order defined
diff --git a/model/model.go b/model/model.go
index 693ac25..5f75eaf 100644
--- a/model/model.go
+++ b/model/model.go
@@ -17,10 +17,10 @@ import (
 // The Model interface must be implemented by the pointer to such type
 // Example:
 //type MyLogicalRouter struct {
-//	UUID          string            `ovsdb:"_uuid"`
-//	Name          string            `ovsdb:"name"`
-//	ExternalIDs   map[string]string `ovsdb:"external_ids"`
-//	LoadBalancers []string          `ovsdb:"load_balancer"`
+//	UUID          string            `ovs:"_uuid"`
+//	Name          string            `ovs:"name"`
+//	ExternalIDs   map[string]string `ovs:"external_ids"`
+//	LoadBalancers []string          `ovs:"load_balancer"`
 //}
 type Model interface{}
 
@@ -100,7 +100,7 @@ func NewDBModel(name string, models map[string]Model) (*DBModel, error) {
 		}
 		hasUUID := false
 		for i := 0; i < modelType.Elem().NumField(); i++ {
-			if field := modelType.Elem().Field(i); field.Tag.Get("ovsdb") == "_uuid" &&
+			if field := modelType.Elem().Field(i); field.Tag.Get("ovs") == "_uuid" &&
 				field.Type.Kind() == reflect.String {
 				hasUUID = true
 			}
@@ -120,7 +120,7 @@ func NewDBModel(name string, models map[string]Model) (*DBModel, error) {
 func modelSetUUID(model Model, uuid string) error {
 	modelVal := reflect.ValueOf(model).Elem()
 	for i := 0; i < modelVal.NumField(); i++ {
-		if field := modelVal.Type().Field(i); field.Tag.Get("ovsdb") == "_uuid" &&
+		if field := modelVal.Type().Field(i); field.Tag.Get("ovs") == "_uuid" &&
 			field.Type.Kind() == reflect.String {
 			modelVal.Field(i).Set(reflect.ValueOf(uuid))
 			return nil
diff --git a/modelgen/dbmodel.go b/modelgen/dbmodel.go
index 3a94552..77a1ed8 100644
--- a/modelgen/dbmodel.go
+++ b/modelgen/dbmodel.go
@@ -13,7 +13,19 @@ import (
 // "preDBDefinitions"
 // "postDBDefinitions"
 // It is design to be used with a map[string] interface and some defined keys (see GetDBTemplateData)
-const BASE_DB_TEMPLATE = `{{ template "header" . }}
+func NewDBTemplate() *template.Template {
+	return template.Must(template.New("").Parse(`
+{{- define "header" }}
+// Code generated by "libovsdb.modelgen"
+// DO NOT EDIT.
+{{- end }}
+{{- define "preDBDefinitions" }}
+ import (
+	"github.com/ovn-org/libovsdb/model"
+)
+{{- end }}
+{{ define "postDBDefinitions" }}{{ end }}
+{{ template "header" . }}
 
 package {{ index . "PackageName" }}
 
@@ -28,17 +40,8 @@ func FullDatabaseModel() (*model.DBModel, error) {
 }
 
 {{ template "postDBDefinitions" . }}
-
-`
-
-// DEFAULT_PRE_DB_TEMPLATE is the default template for "preDBDefinitions"
-const DEFAULT_PRE_DB_TEMPLATE = `{{ define "preDBDefinitions" }} import (
-	"github.com/ovn-org/libovsdb/model"
-) {{ end }}
-`
-
-// DEFAULT_POST_DB_TEMPLATE is the default template for "postDBDefinitions"
-const DEFAULT_POST_DB_TEMPLATE = `{{ define "postDBDefinitions" }}{{ end }}`
+`))
+}
 
 //TableInfo represents the information of a table needed by the Model template
 type TableInfo struct {
@@ -71,26 +74,3 @@ func GetDBTemplateData(pkg string, schema *ovsdb.DatabaseSchema) map[string]inte
 	data["Tables"] = tables
 	return data
 }
-
-// NewDBTemplate returns a new DBTemplate and the DBTemplate data map
-// See BASE_DB_TEMPLATE to a detailed explanation of the possible ways this template can be expanded
-func NewDBTemplate(pkg string, db *ovsdb.DatabaseSchema) (*template.Template, map[string]interface{}) {
-	main, err := template.New("DB").Parse(BASE_DB_TEMPLATE)
-	if err != nil {
-		panic(err)
-	}
-	tmpl, err := main.Parse(DEFAULT_HEADER_TEMPLATE)
-	if err != nil {
-		panic(err)
-	}
-	tmpl, err = tmpl.Parse(DEFAULT_PRE_DB_TEMPLATE)
-	if err != nil {
-		panic(err)
-	}
-	_, err = tmpl.Parse(DEFAULT_POST_DB_TEMPLATE)
-	if err != nil {
-		panic(err)
-	}
-
-	return main, GetDBTemplateData(pkg, db)
-}
diff --git a/modelgen/table.go b/modelgen/table.go
index d0183c5..12e8ad8 100644
--- a/modelgen/table.go
+++ b/modelgen/table.go
@@ -9,7 +9,7 @@ import (
 	"github.com/ovn-org/libovsdb/ovsdb"
 )
 
-// BASE_TABLE_TEMPLATE is the base table template
+// NewTableTemplate returns a new table template
 // It includes the following other templates that can be overriden to customize the generated file
 // "header"
 // "preStructDefinitions"
@@ -18,10 +18,26 @@ import (
 // "extraTags"
 // "postStructDefinitions"
 // It is design to be used with a map[string] interface and some defined keys (see GetTableTemplateData)
-const BASE_TABLE_TEMPLATE = `{{ template "header" . }}
-
-package {{ index . "PackageName" }}
-
+func NewTableTemplate() *template.Template {
+	return template.Must(template.New("").Funcs(
+		template.FuncMap{
+			"printVal":  printVal,
+			"camelCase": camelCase,
+		},
+	).Parse(`
+{{- define "header" }}
+// Code generated by "libovsdb.modelgen"
+// DO NOT EDIT.
+{{- end }}
+{{ define "preStructDefinitions" }}{{ end }}
+{{- define "structComment" }}
+// {{ index . "StructName" }} defines an object in {{ index . "TableName" }} table
+{{- end }}
+{{ define "extraTags" }}{{ end }}
+{{ define "extraFields" }}{{ end }}
+{{ template "header" . }}
+{{ define "postStructDefinitions" }}{{ end }}
+{{ define "enums" }}
 {{ if index . "Enums" }}
 type (
 {{ range index . "Enums" }}
@@ -38,8 +54,10 @@ const (
 {{- end }}
 )
 {{ end }}
-
+{{ end }}
+package {{ index . "PackageName" }}
 {{ template "preStructDefinitions" }}
+{{ template "enums" . }}
 {{ template "structComment" . }}
 type {{ index . "StructName" }} struct {
 {{ range index . "Fields" }}	{{ .Name }}  {{ .Type }} ` + "`" + `{{ .Tag }}{{ template "extraTags" . }}` + "`" + `
@@ -48,27 +66,8 @@ type {{ index . "StructName" }} struct {
 }
 
 {{ template "postStructDefinitions" . }}
-`
-
-// DEFAULT_HEADER_TEMPLATE is the default template for "header"
-const DEFAULT_HEADER_TEMPLATE = `{{ define "header" }}// Code generated by "libovsdb.modelgen"
-// DO NOT EDIT.{{ end }}
-`
-
-// DEFAULT_PRE_TABLE_TEMPLATE is the default template for "preStructDefinitions"
-const DEFAULT_PRE_TABLE_TEMPLATE = `{{ define "preStructDefinitions" }}{{ end }}`
-
-// DEFAULT_COMMENT_TEMPLATE is the default template for "structComment"
-const DEFAULT_COMMENT_TEMPLATE = `{{ define "structComment" }}// {{ index . "StructName" }} defines an object in {{ index . "TableName" }} table {{ end }} `
-
-// DEFAULT_EXTRA_TAGS_TEMPLATE is the default template for "extraTags"
-const DEFAULT_EXTRA_TAGS_TEMPLATE = `{{ define "extraTags" }}{{ end }}`
-
-// DEFAULT_EXTRA_FIELDS_TEMPLATE is the default template for "extraFields"
-const DEFAULT_EXTRA_FIELDS_TEMPLATE = `{{ define "extraFields" }}{{ end }}`
-
-// DEFAULT_POST_TABLE_TEMPLATE is the default template for "postStructDefinitions"
-const DEFAULT_POST_TABLE_TEMPLATE = `{{ define "postStructDefinitions" }}{{ end }}`
+`))
+}
 
 // Enum represents the enum schema type
 type Enum struct {
@@ -132,44 +131,6 @@ func GetTableTemplateData(pkg, name string, table *ovsdb.TableSchema) map[string
 	return data
 }
 
-// NewTableTemplate returns a new TableTemplate and the TableTemplate data map
-// See BASE_TABLE_TEMPLATE to a detailed explanation of the possible ways this template can be expanded
-func NewTableTemplate(pkg string, name string, table *ovsdb.TableSchema) (*template.Template, map[string]interface{}) {
-	funcMap := template.FuncMap{
-		"printVal":  printVal,
-		"camelCase": camelCase,
-	}
-	main, err := template.New(name).Funcs(funcMap).Parse(BASE_TABLE_TEMPLATE)
-	if err != nil {
-		panic(err)
-	}
-	tmpl, err := main.Parse(DEFAULT_HEADER_TEMPLATE)
-	if err != nil {
-		panic(err)
-	}
-	tmpl, err = tmpl.Parse(DEFAULT_PRE_TABLE_TEMPLATE)
-	if err != nil {
-		panic(err)
-	}
-	tmpl, err = tmpl.Parse(DEFAULT_POST_TABLE_TEMPLATE)
-	if err != nil {
-		panic(err)
-	}
-	tmpl, err = tmpl.Parse(DEFAULT_COMMENT_TEMPLATE)
-	if err != nil {
-		panic(err)
-	}
-	tmpl, err = tmpl.Parse(DEFAULT_EXTRA_FIELDS_TEMPLATE)
-	if err != nil {
-		panic(err)
-	}
-	_, err = tmpl.Parse(DEFAULT_EXTRA_TAGS_TEMPLATE)
-	if err != nil {
-		panic(err)
-	}
-	return main, GetTableTemplateData(pkg, name, table)
-}
-
 // FieldName returns the name of a column field
 func FieldName(column string) string {
 	return camelCase(column)
@@ -234,7 +195,7 @@ func AtomicType(atype string) string {
 
 // Tag returns the Tag string of a column
 func Tag(column string) string {
-	return fmt.Sprintf("ovsdb:\"%s\"", column)
+	return fmt.Sprintf("ovs:\"%s\"", column)
 }
 
 // Filename returns the filename of a table


Test patch:
diff --git a/cache/cache_test.go b/cache/cache_test.go
index 138c2ca..5ae41fe 100644
--- a/cache/cache_test.go
+++ b/cache/cache_test.go
@@ -13,9 +13,9 @@ import (
 )
 
 type testModel struct {
-	UUID string `ovsdb:"_uuid"`
-	Foo  string `ovsdb:"foo"`
-	Bar  string `ovsdb:"bar"`
+	UUID string `ovs:"_uuid"`
+	Foo  string `ovs:"foo"`
+	Bar  string `ovs:"bar"`
 }
 
 func TestRowCache_Row(t *testing.T) {
diff --git a/client/api_test.go b/client/api_test.go
index d74b252..067f765 100644
--- a/client/api_test.go
+++ b/client/api_test.go
@@ -372,7 +372,7 @@ func TestConditionFromModel(t *testing.T) {
 		{
 			name: "wrong condition must fail",
 			model: &struct {
-				a string `ovsdb:"_uuid"`
+				a string `ovs:"_uuid"`
 			}{},
 			conds: []model.Condition{{Field: "foo"}},
 			err:   true,
diff --git a/client/api_test_model.go b/client/api_test_model.go
index 42b1566..1fa825e 100644
--- a/client/api_test_model.go
+++ b/client/api_test_model.go
@@ -111,16 +111,16 @@ var apiTestSchema = []byte(`{
     }`)
 
 type testLogicalSwitch struct {
-	UUID             string            `ovsdb:"_uuid"`
-	Ports            []string          `ovsdb:"ports"`
-	ExternalIds      map[string]string `ovsdb:"external_ids"`
-	Name             string            `ovsdb:"name"`
-	QosRules         []string          `ovsdb:"qos_rules"`
-	LoadBalancer     []string          `ovsdb:"load_balancer"`
-	DnsRecords       []string          `ovsdb:"dns_records"`
-	OtherConfig      map[string]string `ovsdb:"other_config"`
-	ForwardingGroups []string          `ovsdb:"forwarding_groups"`
-	Acls             []string          `ovsdb:"acls"`
+	UUID             string            `ovs:"_uuid"`
+	Ports            []string          `ovs:"ports"`
+	ExternalIds      map[string]string `ovs:"external_ids"`
+	Name             string            `ovs:"name"`
+	QosRules         []string          `ovs:"qos_rules"`
+	LoadBalancer     []string          `ovs:"load_balancer"`
+	DnsRecords       []string          `ovs:"dns_records"`
+	OtherConfig      map[string]string `ovs:"other_config"`
+	ForwardingGroups []string          `ovs:"forwarding_groups"`
+	Acls             []string          `ovs:"acls"`
 }
 
 // Table returns the table name. It's part of the Model interface
@@ -130,22 +130,22 @@ func (*testLogicalSwitch) Table() string {
 
 //LogicalSwitchPort struct defines an object in Logical_Switch_Port table
 type testLogicalSwitchPort struct {
-	UUID             string            `ovsdb:"_uuid"`
-	Up               []bool            `ovsdb:"up"`
-	Dhcpv4Options    []string          `ovsdb:"dhcpv4_options"`
-	Name             string            `ovsdb:"name"`
-	DynamicAddresses []string          `ovsdb:"dynamic_addresses"`
-	HaChassisGroup   []string          `ovsdb:"ha_chassis_group"`
-	Options          map[string]string `ovsdb:"options"`
-	Enabled          []bool            `ovsdb:"enabled"`
-	Addresses        []string          `ovsdb:"addresses"`
-	Dhcpv6Options    []string          `ovsdb:"dhcpv6_options"`
-	TagRequest       []int             `ovsdb:"tag_request"`
-	Tag              []int             `ovsdb:"tag"`
-	PortSecurity     []string          `ovsdb:"port_security"`
-	ExternalIds      map[string]string `ovsdb:"external_ids"`
-	Type             string            `ovsdb:"type"`
-	ParentName       []string          `ovsdb:"parent_name"`
+	UUID             string            `ovs:"_uuid"`
+	Up               []bool            `ovs:"up"`
+	Dhcpv4Options    []string          `ovs:"dhcpv4_options"`
+	Name             string            `ovs:"name"`
+	DynamicAddresses []string          `ovs:"dynamic_addresses"`
+	HaChassisGroup   []string          `ovs:"ha_chassis_group"`
+	Options          map[string]string `ovs:"options"`
+	Enabled          []bool            `ovs:"enabled"`
+	Addresses        []string          `ovs:"addresses"`
+	Dhcpv6Options    []string          `ovs:"dhcpv6_options"`
+	TagRequest       []int             `ovs:"tag_request"`
+	Tag              []int             `ovs:"tag"`
+	PortSecurity     []string          `ovs:"port_security"`
+	ExternalIds      map[string]string `ovs:"external_ids"`
+	Type             string            `ovs:"type"`
+	ParentName       []string          `ovs:"parent_name"`
 }
 
 // Table returns the table name. It's part of the Model interface
diff --git a/client/ovs_integration_test.go b/client/ovs_integration_test.go
index e81c076..f2241d5 100644
--- a/client/ovs_integration_test.go
+++ b/client/ovs_integration_test.go
@@ -20,18 +20,18 @@ const (
 
 // ORMBridge is the simplified ORM model of the Bridge table
 type bridgeType struct {
-	UUID        string            `ovsdb:"_uuid"`
-	Name        string            `ovsdb:"name"`
-	OtherConfig map[string]string `ovsdb:"other_config"`
-	ExternalIds map[string]string `ovsdb:"external_ids"`
-	Ports       []string          `ovsdb:"ports"`
-	Status      map[string]string `ovsdb:"status"`
+	UUID        string            `ovs:"_uuid"`
+	Name        string            `ovs:"name"`
+	OtherConfig map[string]string `ovs:"other_config"`
+	ExternalIds map[string]string `ovs:"external_ids"`
+	Ports       []string          `ovs:"ports"`
+	Status      map[string]string `ovs:"status"`
 }
 
 // ORMovs is the simplified ORM model of the Bridge table
 type ovsType struct {
-	UUID    string   `ovsdb:"_uuid"`
-	Bridges []string `ovsdb:"bridges"`
+	UUID    string   `ovs:"_uuid"`
+	Bridges []string `ovs:"bridges"`
 }
 
 var defDB, _ = model.NewDBModel("Open_vSwitch", map[string]model.Model{
diff --git a/mapper/info_test.go b/mapper/info_test.go
index 370855a..29f9111 100644
--- a/mapper/info_test.go
+++ b/mapper/info_test.go
@@ -74,10 +74,10 @@ func TestNewMapperInfo(t *testing.T) {
 
 func TestMapperInfoSet(t *testing.T) {
 	type obj struct {
-		Ostring string            `ovsdb:"aString"`
-		Oint    int               `ovsdb:"aInteger"`
-		Oset    []string          `ovsdb:"aSet"`
-		Omap    map[string]string `ovsdb:"aMap"`
+		Ostring string            `ovs:"aString"`
+		Oint    int               `ovs:"aInteger"`
+		Oset    []string          `ovs:"aSet"`
+		Omap    map[string]string `ovs:"aMap"`
 	}
 
 	type test struct {
@@ -160,10 +160,10 @@ func TestMapperInfoSet(t *testing.T) {
 
 func TestMapperInfoColByPtr(t *testing.T) {
 	type obj struct {
-		ostring string            `ovsdb:"aString"`
-		oint    int               `ovsdb:"aInteger"`
-		oset    []string          `ovsdb:"aSet"`
-		omap    map[string]string `ovsdb:"aMap"`
+		ostring string            `ovs:"aString"`
+		oint    int               `ovs:"aInteger"`
+		oset    []string          `ovs:"aSet"`
+		omap    map[string]string `ovs:"aMap"`
 	}
 	obj1 := obj{}
 
@@ -269,11 +269,11 @@ func TestOrmGetIndex(t *testing.T) {
 	assert.Nil(t, err)
 
 	type obj struct {
-		ID     string            `ovsdb:"_uuid"`
-		MyName string            `ovsdb:"name"`
-		Config map[string]string `ovsdb:"config"`
-		Comp1  string            `ovsdb:"composed_1"`
-		Comp2  string            `ovsdb:"composed_2"`
+		ID     string            `ovs:"_uuid"`
+		MyName string            `ovs:"name"`
+		Config map[string]string `ovs:"config"`
+		Comp1  string            `ovs:"composed_1"`
+		Comp2  string            `ovs:"composed_2"`
 	}
 	type test struct {
 		name     string
diff --git a/mapper/mapper_test.go b/mapper/mapper_test.go
index bb563b4..6afb04d 100644
--- a/mapper/mapper_test.go
+++ b/mapper/mapper_test.go
@@ -184,17 +184,17 @@ func getOvsTestRow(t *testing.T) ovsdb.Row {
 
 func TestMapperGetData(t *testing.T) {
 	type ormTestType struct {
-		AString             string            `ovsdb:"aString"`
-		ASet                []string          `ovsdb:"aSet"`
-		ASingleSet          []string          `ovsdb:"aSingleSet"`
-		AUUIDSet            []string          `ovsdb:"aUUIDSet"`
-		AUUID               string            `ovsdb:"aUUID"`
-		AIntSet             []int             `ovsdb:"aIntSet"`
-		AFloat              float64           `ovsdb:"aFloat"`
-		AFloatSet           []float64         `ovsdb:"aFloatSet"`
-		YetAnotherStringSet []string          `ovsdb:"aEmptySet"`
-		AEnum               string            `ovsdb:"aEnum"`
-		AMap                map[string]string `ovsdb:"aMap"`
+		AString             string            `ovs:"aString"`
+		ASet                []string          `ovs:"aSet"`
+		ASingleSet          []string          `ovs:"aSingleSet"`
+		AUUIDSet            []string          `ovs:"aUUIDSet"`
+		AUUID               string            `ovs:"aUUID"`
+		AIntSet             []int             `ovs:"aIntSet"`
+		AFloat              float64           `ovs:"aFloat"`
+		AFloatSet           []float64         `ovs:"aFloatSet"`
+		YetAnotherStringSet []string          `ovs:"aEmptySet"`
+		AEnum               string            `ovs:"aEnum"`
+		AMap                map[string]string `ovs:"aMap"`
 		NonTagged           string
 	}
 
@@ -247,7 +247,7 @@ func TestMapperNewRow(t *testing.T) {
 	}{{
 		name: "string",
 		objInput: &struct {
-			AString string `ovsdb:"aString"`
+			AString string `ovs:"aString"`
 		}{
 			AString: aString,
 		},
@@ -255,7 +255,7 @@ func TestMapperNewRow(t *testing.T) {
 	}, {
 		name: "set",
 		objInput: &struct {
-			SomeSet []string `ovsdb:"aSet"`
+			SomeSet []string `ovs:"aSet"`
 		}{
 			SomeSet: aSet,
 		},
@@ -263,7 +263,7 @@ func TestMapperNewRow(t *testing.T) {
 	}, {
 		name: "emptySet with no column specification",
 		objInput: &struct {
-			EmptySet []string `ovsdb:"aSet"`
+			EmptySet []string `ovs:"aSet"`
 		}{
 			EmptySet: []string{},
 		},
@@ -271,7 +271,7 @@ func TestMapperNewRow(t *testing.T) {
 	}, {
 		name: "UUID",
 		objInput: &struct {
-			MyUUID string `ovsdb:"aUUID"`
+			MyUUID string `ovs:"aUUID"`
 		}{
 			MyUUID: aUUID0,
 		},
@@ -279,7 +279,7 @@ func TestMapperNewRow(t *testing.T) {
 	}, {
 		name: "aUUIDSet",
 		objInput: &struct {
-			MyUUIDSet []string `ovsdb:"aUUIDSet"`
+			MyUUIDSet []string `ovs:"aUUIDSet"`
 		}{
 			MyUUIDSet: []string{aUUID0, aUUID1},
 		},
@@ -287,7 +287,7 @@ func TestMapperNewRow(t *testing.T) {
 	}, {
 		name: "aIntSet",
 		objInput: &struct {
-			MyIntSet []int `ovsdb:"aIntSet"`
+			MyIntSet []int `ovs:"aIntSet"`
 		}{
 			MyIntSet: []int{0, 42},
 		},
@@ -295,7 +295,7 @@ func TestMapperNewRow(t *testing.T) {
 	}, {
 		name: "aFloat",
 		objInput: &struct {
-			MyFloat float64 `ovsdb:"aFloat"`
+			MyFloat float64 `ovs:"aFloat"`
 		}{
 			MyFloat: 42.42,
 		},
@@ -303,7 +303,7 @@ func TestMapperNewRow(t *testing.T) {
 	}, {
 		name: "aFloatSet",
 		objInput: &struct {
-			MyFloatSet []float64 `ovsdb:"aFloatSet"`
+			MyFloatSet []float64 `ovs:"aFloatSet"`
 		}{
 			MyFloatSet: aFloatSet,
 		},
@@ -311,7 +311,7 @@ func TestMapperNewRow(t *testing.T) {
 	}, {
 		name: "Enum",
 		objInput: &struct {
-			MyEnum string `ovsdb:"aEnum"`
+			MyEnum string `ovs:"aEnum"`
 		}{
 			MyEnum: aEnum,
 		},
@@ -319,7 +319,7 @@ func TestMapperNewRow(t *testing.T) {
 	}, {
 		name: "untagged fields should not affect row",
 		objInput: &struct {
-			AString string `ovsdb:"aString"`
+			AString string `ovs:"aString"`
 			MyStuff map[string]string
 		}{
 			AString: aString,
@@ -329,7 +329,7 @@ func TestMapperNewRow(t *testing.T) {
 	}, {
 		name: "Maps",
 		objInput: &struct {
-			MyMap map[string]string `ovsdb:"aMap"`
+			MyMap map[string]string `ovs:"aMap"`
 		}{
 			MyMap: aMap,
 		},
@@ -357,10 +357,10 @@ func TestMapperNewRowFields(t *testing.T) {
 	}
 
 	type obj struct {
-		MyMap    map[string]string `ovsdb:"aMap"`
-		MySet    []string          `ovsdb:"aSet"`
-		MyString string            `ovsdb:"aString"`
-		MyFloat  float64           `ovsdb:"aFloat"`
+		MyMap    map[string]string `ovs:"aMap"`
+		MySet    []string          `ovs:"aSet"`
+		MyString string            `ovs:"aString"`
+		MyFloat  float64           `ovs:"aFloat"`
 	}
 	testObj := obj{}
 
@@ -476,11 +476,11 @@ func TestMapperCondition(t *testing.T) {
   }
 }`)
 	type testType struct {
-		ID     string            `ovsdb:"_uuid"`
-		MyName string            `ovsdb:"name"`
-		Config map[string]string `ovsdb:"config"`
-		Comp1  string            `ovsdb:"composed_1"`
-		Comp2  string            `ovsdb:"composed_2"`
+		ID     string            `ovs:"_uuid"`
+		MyName string            `ovs:"name"`
+		Config map[string]string `ovs:"config"`
+		Comp1  string            `ovs:"composed_1"`
+		Comp2  string            `ovs:"composed_2"`
 	}
 
 	var schema ovsdb.DatabaseSchema
@@ -645,13 +645,13 @@ func TestMapperEqualIndexes(t *testing.T) {
   }
 }`)
 	type testType struct {
-		ID     string            `ovsdb:"_uuid"`
-		MyName string            `ovsdb:"name"`
-		Config map[string]string `ovsdb:"config"`
-		Comp1  string            `ovsdb:"composed_1"`
-		Comp2  string            `ovsdb:"composed_2"`
-		Int1   int               `ovsdb:"int1"`
-		Int2   int               `ovsdb:"int2"`
+		ID     string            `ovs:"_uuid"`
+		MyName string            `ovs:"name"`
+		Config map[string]string `ovs:"config"`
+		Comp1  string            `ovs:"composed_1"`
+		Comp2  string            `ovs:"composed_2"`
+		Int1   int               `ovs:"int1"`
+		Int2   int               `ovs:"int2"`
 	}
 
 	var schema ovsdb.DatabaseSchema
@@ -904,12 +904,12 @@ func TestMapperMutation(t *testing.T) {
   }
 }`)
 	type testType struct {
-		UUID      string            `ovsdb:"_uuid"`
-		String    string            `ovsdb:"string"`
-		Set       []string          `ovsdb:"set"`
-		Map       map[string]string `ovsdb:"map"`
-		Int       int               `ovsdb:"int"`
-		UnMutable int               `ovsdb:"unmutable"`
+		UUID      string            `ovs:"_uuid"`
+		String    string            `ovs:"string"`
+		Set       []string          `ovs:"set"`
+		Map       map[string]string `ovs:"map"`
+		Int       int               `ovs:"int"`
+		UnMutable int               `ovs:"unmutable"`
 	}
 
 	var schema ovsdb.DatabaseSchema
diff --git a/model/model_test.go b/model/model_test.go
index 3f97bf8..9044e94 100644
--- a/model/model_test.go
+++ b/model/model_test.go
@@ -10,13 +10,13 @@ import (
 )
 
 type modelA struct {
-	UUID string `ovsdb:"_uuid"`
+	UUID string `ovs:"_uuid"`
 }
 
 type modelB struct {
-	UID string `ovsdb:"_uuid"`
-	Foo string `ovsdb:"bar"`
-	Bar string `ovsdb:"baz"`
+	UID string `ovs:"_uuid"`
+	Foo string `ovs:"bar"`
+	Bar string `ovs:"baz"`
 }
 
 type modelInvalid struct {
@@ -88,12 +88,12 @@ func TestSetUUID(t *testing.T) {
 func TestValidate(t *testing.T) {
 	model, err := NewDBModel("TestDB", map[string]Model{
 		"TestTable": &struct {
-			aUUID   string            `ovsdb:"_uuid"`
-			aString string            `ovsdb:"aString"`
-			aInt    int               `ovsdb:"aInt"`
-			aFloat  float64           `ovsdb:"aFloat"`
-			aSet    []string          `ovsdb:"aSet"`
-			aMap    map[string]string `ovsdb:"aMap"`
+			aUUID   string            `ovs:"_uuid"`
+			aString string            `ovs:"aString"`
+			aInt    int               `ovs:"aInt"`
+			aFloat  float64           `ovs:"aFloat"`
+			aSet    []string          `ovs:"aSet"`
+			aMap    map[string]string `ovs:"aMap"`
 		}{},
 	})
 	assert.Nil(t, err)
diff --git a/modelgen/table_test.go b/modelgen/table_test.go
index 278c7fd..e7ac3b0 100644
--- a/modelgen/table_test.go
+++ b/modelgen/table_test.go
@@ -8,6 +8,7 @@ import (
 
 	"github.com/ovn-org/libovsdb/ovsdb"
 	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
 )
 
 func TestNewTableTemplate(t *testing.T) {
@@ -66,12 +67,12 @@ const (
 
 // AtomicTable defines an object in atomicTable table
 type AtomicTable struct {
-	UUID      string                ` + "`" + `ovsdb:"_uuid"` + "`" + `
-	EventType AtomicTableEventType  ` + "`" + `ovsdb:"event_type"` + "`" + `
-	Float     float64               ` + "`" + `ovsdb:"float"` + "`" + `
-	Int       int                   ` + "`" + `ovsdb:"int"` + "`" + `
-	Protocol  []AtomicTableProtocol ` + "`" + `ovsdb:"protocol"` + "`" + `
-	Str       string                ` + "`" + `ovsdb:"str"` + "`" + `
+	UUID      string                ` + "`" + `ovs:"_uuid"` + "`" + `
+	EventType AtomicTableEventType  ` + "`" + `ovs:"event_type"` + "`" + `
+	Float     float64               ` + "`" + `ovs:"float"` + "`" + `
+	Int       int                   ` + "`" + `ovs:"int"` + "`" + `
+	Protocol  []AtomicTableProtocol ` + "`" + `ovs:"protocol"` + "`" + `
+	Str       string                ` + "`" + `ovs:"str"` + "`" + `
 }
 `,
 		},
@@ -104,12 +105,12 @@ const (
 
 // AtomicTable defines an object in atomicTable table
 type AtomicTable struct {
-	UUID      string                ` + "`" + `ovsdb:"_uuid"` + "`" + `
-	EventType AtomicTableEventType  ` + "`" + `ovsdb:"event_type"` + "`" + `
-	Float     float64               ` + "`" + `ovsdb:"float"` + "`" + `
-	Int       int                   ` + "`" + `ovsdb:"int"` + "`" + `
-	Protocol  []AtomicTableProtocol ` + "`" + `ovsdb:"protocol"` + "`" + `
-	Str       string                ` + "`" + `ovsdb:"str"` + "`" + `
+	UUID      string                ` + "`" + `ovs:"_uuid"` + "`" + `
+	EventType AtomicTableEventType  ` + "`" + `ovs:"event_type"` + "`" + `
+	Float     float64               ` + "`" + `ovs:"float"` + "`" + `
+	Int       int                   ` + "`" + `ovs:"int"` + "`" + `
+	Protocol  []AtomicTableProtocol ` + "`" + `ovs:"protocol"` + "`" + `
+	Str       string                ` + "`" + `ovs:"str"` + "`" + `
 
 	OtherUUID      string
 	OtherEventType AtomicTableEventType
@@ -153,12 +154,12 @@ const (
 
 // AtomicTable defines an object in atomicTable table
 type AtomicTable struct {
-	UUID      string                ` + "`" + `ovsdb:"_uuid"` + "`" + `
-	EventType AtomicTableEventType  ` + "`" + `ovsdb:"event_type"` + "`" + `
-	Float     float64               ` + "`" + `ovsdb:"float"` + "`" + `
-	Int       int                   ` + "`" + `ovsdb:"int"` + "`" + `
-	Protocol  []AtomicTableProtocol ` + "`" + `ovsdb:"protocol"` + "`" + `
-	Str       string                ` + "`" + `ovsdb:"str"` + "`" + `
+	UUID      string                ` + "`" + `ovs:"_uuid"` + "`" + `
+	EventType AtomicTableEventType  ` + "`" + `ovs:"event_type"` + "`" + `
+	Float     float64               ` + "`" + `ovs:"float"` + "`" + `
+	Int       int                   ` + "`" + `ovs:"int"` + "`" + `
+	Protocol  []AtomicTableProtocol ` + "`" + `ovs:"protocol"` + "`" + `
+	Str       string                ` + "`" + `ovs:"str"` + "`" + `
 }
 
 func TestFunc() string {
@@ -191,8 +192,9 @@ WRONG FORMAT
 	for _, tt := range test {
 		t.Run(fmt.Sprintf("Table Test: %s", tt.name), func(t *testing.T) {
 			fakeTable := "atomicTable"
+			tmpl := NewTableTemplate()
 			table := schema.Tables[fakeTable]
-			templ, data := NewTableTemplate(
+			data := GetTableTemplateData(
 				"test",
 				fakeTable,
 				&table,
@@ -201,16 +203,15 @@ WRONG FORMAT
 				assert.NotNil(t, err)
 			} else {
 				if tt.extend != nil {
-					tt.extend(templ, data)
+					tt.extend(tmpl, data)
 				}
-
 				for i := 0; i < 3; i++ {
 					g := NewGenerator(false)
-					b, err := g.Format(templ, data)
+					b, err := g.Format(tmpl, data)
 					if tt.formatErr {
 						assert.NotNil(t, err)
 					} else {
-						assert.Nil(t, err)
+						require.NoError(t, err)
 						assert.Equal(t, tt.expected, string(b))
 					}
 				}
@@ -277,8 +278,8 @@ func TestAtomicType(t *testing.T) {
 }
 
 func TestTag(t *testing.T) {
-	if s := Tag("Foo_Bar"); s != "ovsdb:\"Foo_Bar\"" {
-		t.Fatalf("got %s, wanted ovsdb:\"Foo_Bar\"", s)
+	if s := Tag("Foo_Bar"); s != "ovs:\"Foo_Bar\"" {
+		t.Fatalf("got %s, wanted ovs:\"Foo_Bar\"", s)
 	}
 }
 
@@ -331,7 +332,8 @@ func ExampleNewTableTemplate() {
 	var schema ovsdb.DatabaseSchema
 	_ = json.Unmarshal(schemaString, &schema)
 
-	base, data := NewTableTemplate("mypackage", "table1", schema.Table("table1"))
+	base := NewTableTemplate()
+	data := GetTableTemplateData("mypackage", "table1", schema.Table("table1"))
 
 	// Add a function at after the struct definition
 	// It can access the default data values plus any extra field that is added to data
diff --git a/server/server_integration_test.go b/server/server_integration_test.go
index 7fdec6d..d2644d4 100644
--- a/server/server_integration_test.go
+++ b/server/server_integration_test.go
@@ -20,18 +20,18 @@ import (
 
 // bridgeType is the simplified ORM model of the Bridge table
 type bridgeType struct {
-	UUID        string            `ovsdb:"_uuid"`
-	Name        string            `ovsdb:"name"`
-	OtherConfig map[string]string `ovsdb:"other_config"`
-	ExternalIds map[string]string `ovsdb:"external_ids"`
-	Ports       []string          `ovsdb:"ports"`
-	Status      map[string]string `ovsdb:"status"`
+	UUID        string            `ovs:"_uuid"`
+	Name        string            `ovs:"name"`
+	OtherConfig map[string]string `ovs:"other_config"`
+	ExternalIds map[string]string `ovs:"external_ids"`
+	Ports       []string          `ovs:"ports"`
+	Status      map[string]string `ovs:"status"`
 }
 
 // ovsType is the simplified ORM model of the Bridge table
 type ovsType struct {
-	UUID    string   `ovsdb:"_uuid"`
-	Bridges []string `ovsdb:"bridges"`
+	UUID    string   `ovs:"_uuid"`
+	Bridges []string `ovs:"bridges"`
 }
 
 func getSchema() (*ovsdb.DatabaseSchema, error) {