Skip to content

Commit 6304965

Browse files
committed
Merge branch 'santalla/devel'
2 parents 6325e2e + a18a8ef commit 6304965

File tree

4 files changed

+264
-1
lines changed

4 files changed

+264
-1
lines changed

generator/cli/kallax/cmd/gen.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"gopkg.in/src-d/go-kallax.v1/generator"
88
cli "gopkg.in/urfave/cli.v1"
9+
"os"
910
)
1011

1112
var Generate = cli.Command{
@@ -44,6 +45,13 @@ func generateAction(c *cli.Context) error {
4445
return fmt.Errorf("kallax: Input path should be a directory %s", input)
4546
}
4647

48+
var foundPrevious bool
49+
if _, err = os.Stat(output); err == nil {
50+
foundPrevious = true
51+
fmt.Fprintf(os.Stderr, "NOTE: Previous generated file `%s` found, renaming to `%s`\n", output, output+".old")
52+
err = os.Rename(output, output+".old")
53+
}
54+
4755
p := generator.NewProcessor(input, excluded)
4856
pkg, err := p.Do()
4957
if err != nil {
@@ -56,5 +64,10 @@ func generateAction(c *cli.Context) error {
5664
return err
5765
}
5866

67+
if foundPrevious {
68+
fmt.Fprintf(os.Stderr, "NOTE: Generation succeded, removing `%s`\n", output+".old")
69+
os.Remove(output + ".old")
70+
}
71+
5972
return nil
6073
}

generator/templates/model.tgo

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,16 @@ func (s *{{.StoreName}}) DebugWith(logger kallax.LoggerFunc) *{{.StoreName}} {
118118
return &{{.StoreName}}{s.Store.DebugWith(logger)}
119119
}
120120

121+
// DisableCacher turns off prepared statements, which can be useful in some scenarios.
122+
func (s *{{.StoreName}}) DisableCacher() *{{.StoreName}} {
123+
return &{{.StoreName}}{s.Store.DisableCacher()}
124+
}
125+
126+
// DisableCacher turns on prepared statements. This is the default.
127+
func (s *{{.StoreName}}) EnableCacher() *{{.StoreName}} {
128+
return &{{.StoreName}}{s.Store.EnableCacher()}
129+
}
130+
121131
{{if .HasNonInverses}}
122132
func (s *{{.StoreName}}) relationshipRecords(record *{{.Name}}) []modelSaveFunc {
123133
var result []modelSaveFunc

store.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func (s *Store) DebugWith(logger LoggerFunc) *Store {
159159
}).init()
160160
}
161161

162-
// DisableCacher turns off prepared statements.
162+
// DisableCacher turns off prepared statements, which can be useful in some scenarios.
163163
func (s *Store) DisableCacher() *Store {
164164
return (&Store{
165165
db: s.db,

0 commit comments

Comments
 (0)