Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

Commit

Permalink
Merge pull request #58 from dadleyy/chore/cleanup-unused
Browse files Browse the repository at this point in the history
chore(cleanup) removing un-used methods on generated store struct
  • Loading branch information
dadleyy committed Oct 31, 2017
2 parents ef69b7d + c9873e0 commit f6d46a5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 60 deletions.
5 changes: 3 additions & 2 deletions examples/library/models/book.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package models

import "fmt"
import "database/sql"

//go:generate marlowc -input book.go
Expand All @@ -17,6 +18,6 @@ type Book struct {
}

// GetPageContents is a dummy no-op function
func (b *Book) GetPageContents(page int) (string, error) {
return "", nil
func (b *Book) String() string {
return fmt.Sprintf("%s (%d pages)", b.Title, b.PageCount)
}
9 changes: 9 additions & 0 deletions examples/library/models/book_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,15 @@ func Test_Book(t *testing.T) {
g.Assert(results[1]).Equal(2)
})

g.It("returns source struct instances that support source method calls", func() {
results, e := store.FindBooks(&BookBlueprint{
ID: []int{1},
})
g.Assert(e).Equal(nil)
title := fmt.Sprintf("%s", results[0])
g.Assert(title).Equal("book-1 (10 pages)")
})

g.It("allows the consumer to select explicit book titles", func() {
results, e := store.SelectTitles(&BookBlueprint{
ID: []int{1, 2},
Expand Down
57 changes: 0 additions & 57 deletions marlow/features/store.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package features

import "io"
import "fmt"
import "net/url"
import "github.com/dadleyy/marlow/marlow/writing"
import "github.com/dadleyy/marlow/marlow/constants"
Expand All @@ -19,62 +18,6 @@ func writeStore(destination io.Writer, record url.Values, imports chan<- string)
return e
}

symbols := map[string]string{
"STATEMENT_PARAM": "_statement",
"ARGUMENTS_PARAM": "_args",
}

qParams := []writing.FuncParam{
{Symbol: symbols["STATEMENT_PARAM"], Type: "string"},
{Symbol: symbols["ARGUMENTS_PARAM"], Type: "...interface{}"},
}

qReturns := []string{"*sql.Rows", "error"}
eReturns := []string{"sql.Result", "error"}

e = out.WithMethod("q", storeName, qParams, qReturns, func(scope url.Values) error {
receiver := scope.Get("receiver")
condition := fmt.Sprintf("%s.DB == nil || %s.Ping() != nil", receiver, receiver)

e := out.WithIf(condition, func(url.Values) error {
out.Println("return nil, fmt.Errorf(\"not-connected\")")
return nil
})

if e != nil {
return e
}

out.Println("return %s.Query(%s, %s...)", receiver, symbols["STATEMENT_PARAM"], symbols["ARGUMENTS_PARAM"])
return nil
})

if e != nil {
return e
}

e = out.WithMethod("e", storeName, qParams, eReturns, func(scope url.Values) error {
receiver := scope.Get("receiver")
condition := fmt.Sprintf("%s.DB == nil || %s.Ping() != nil", receiver, receiver)

e := out.WithIf(condition, func(url.Values) error {
out.Println("return nil, fmt.Errorf(\"not-connected\")")
return nil
})

if e != nil {
return e
}

out.Println("return %s.Exec(%s, %s...)", receiver, symbols["STATEMENT_PARAM"], symbols["ARGUMENTS_PARAM"])
return nil
})

if e != nil {
return e
}

imports <- "fmt"
imports <- "database/sql"
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion marlow/features/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func Test_StoreGenerator(t *testing.T) {
g.It("injects fmt and sql packages into import stream", func() {
io.Copy(scaffold.output, scaffold.g())
scaffold.close()
g.Assert(scaffold.received["fmt"]).Equal(true)
g.Assert(len(scaffold.received)).Equal(1)
g.Assert(scaffold.received["database/sql"]).Equal(true)
})

Expand Down

0 comments on commit f6d46a5

Please sign in to comment.