good morning!!!!

Skip to content
Snippets Groups Projects
Commit c676532f authored by José Carlos Nieto's avatar José Carlos Nieto
Browse files

Adding caching for Statement struct.

parent f5cd9042
No related branches found
No related tags found
No related merge requests found
package sqlgen package sqlgen
import (
"strconv"
)
type Statement struct { type Statement struct {
Type Type
Table Table
...@@ -29,8 +33,30 @@ type statement_s struct { ...@@ -29,8 +33,30 @@ type statement_s struct {
Where string Where string
} }
func (self Statement) Hash() string {
hash := `Statement(` +
strconv.Itoa(int(self.Type)) + `;` +
self.Table.Hash() + `;` +
self.Database.Hash() + `;` +
strconv.Itoa(int(self.Limit)) + `;` +
strconv.Itoa(int(self.Offset)) + `;` +
self.Columns.Hash() + `;` +
self.Values.Hash() + `;` +
self.ColumnValues.Hash() + `;` +
self.OrderBy.Hash() + `;` +
self.GroupBy.Hash() + `;` +
string(self.Extra) + `;` +
self.Where.Hash() +
`)`
return hash
}
func (self *Statement) Compile(layout *Template) (compiled string) { func (self *Statement) Compile(layout *Template) (compiled string) {
if c, ok := layout.Read(self); ok {
return c
}
data := statement_s{ data := statement_s{
Table: self.Table.Compile(layout), Table: self.Table.Compile(layout),
Database: self.Database.Compile(layout), Database: self.Database.Compile(layout),
...@@ -62,9 +88,9 @@ func (self *Statement) Compile(layout *Template) (compiled string) { ...@@ -62,9 +88,9 @@ func (self *Statement) Compile(layout *Template) (compiled string) {
compiled = mustParse(layout.UpdateLayout, data) compiled = mustParse(layout.UpdateLayout, data)
case SqlInsert: case SqlInsert:
compiled = mustParse(layout.InsertLayout, data) compiled = mustParse(layout.InsertLayout, data)
default:
compiled = ""
} }
layout.Write(self, compiled)
return compiled return compiled
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment