Skip to content

Commit

Permalink
Fix the failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
iamralch committed Mar 6, 2021
1 parent 2842985 commit 47f6ef9
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 136 deletions.
55 changes: 10 additions & 45 deletions sqlmodel/fixture/repository.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,85 +7,50 @@ type Table1Repository struct {
Gateway *orm.Gateway
}

func (r *Table1Repository) SelectAll() ([]*model.Table1, error) {
return r.SelectAllContext(context.TODO())
}

func (r *Table1Repository) SelectAllContext(ctx context.Context) ([]*model.Table1, error) {
func (r *Table1Repository) SelectAll(ctx context.Context) ([]*model.Table1, error) {
records := []*model.Table1{}
routine := orm.Routine("select-all-table1")

if err := r.Gateway.SelectContext(ctx, &records, routine); err != nil {
if err := r.Gateway.All(ctx, &records, routine); err != nil {
return nil, err
}

return records, nil
}

func (r *Table1Repository) SelectByPK(id string) (*model.Table1, error) {
return r.SelectByPKContext(context.TODO(), id)
}

func (r *Table1Repository) SelectByPKContext(ctx context.Context, id string) (*model.Table1, error) {
func (r *Table1Repository) SelectByPK(ctx context.Context, id string) (*model.Table1, error) {
param := orm.Map{
"id": id,
}

routine := orm.Routine("select-table1-by-pk", param)
record := &model.Table1{}

if err := r.Gateway.SelectOneContext(ctx, record, routine); err != nil {
if err := r.Gateway.Only(ctx, record, routine); err != nil {
return nil, err
}

return record, nil
}

func (r *Table1Repository) SearchAll(query *orm.RQLQuery) ([]*model.Table1, error) {
return r.SearchAllContext(context.TODO(), query)
}

func (r *Table1Repository) SearchAllContext(ctx context.Context, query *orm.RQLQuery) ([]*model.Table1, error) {
records := []*model.Table1{}
routine := orm.RQL("table1", query)

if err := r.Gateway.SelectContext(ctx, &records, routine); err != nil {
return nil, err
}

return records, nil
}

func (r *Table1Repository) Insert(row *model.Table1) error {
return r.InsertContext(context.TODO(), row)
}

func (r *Table1Repository) InsertContext(ctx context.Context, row *model.Table1) error {
func (r *Table1Repository) Insert(ctx context.Context, row *model.Table1) error {
routine := orm.Routine("insert-table1", row)
_, err := r.Gateway.ExecContext(ctx, routine)
_, err := r.Gateway.Exec(ctx, routine)
return err
}

func (r *Table1Repository) UpdateByPK(row *model.Table1) error {
return r.UpdateByPKContext(context.TODO(), row)
}

func (r *Table1Repository) UpdateByPKContext(ctx context.Context, row *model.Table1) error {
func (r *Table1Repository) UpdateByPK(ctx context.Context, row *model.Table1) error {
routine := orm.Routine("update-table1-by-pk", row)
_, err := r.Gateway.ExecContext(ctx, routine)
_, err := r.Gateway.Exec(ctx, routine)
return err
}

func (r *Table1Repository) DeleteByPK(id string) error {
return r.DeleteByPKContext(context.TODO(), id)
}

func (r *Table1Repository) DeleteByPKContext(ctx context.Context, id string) error {
func (r *Table1Repository) DeleteByPK(ctx context.Context, id string) error {
param := orm.Map{
"id": id,
}

routine := orm.Routine("delete-table1-by-pk", param)
_, err := r.Gateway.ExecContext(ctx, routine)
_, err := r.Gateway.Exec(ctx, routine)
return err
}
5 changes: 3 additions & 2 deletions sqlmodel/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
"io/ioutil"
"strings"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/phogolabs/prana/sqlmodel"
"golang.org/x/tools/imports"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var _ = Describe("Codegen", func() {
Expand Down
6 changes: 4 additions & 2 deletions sqlmodel/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ var (
Type: "byte",
}
byteSliceDef = &TypeDef{
Type: "[]byte",
Type: "[]byte",
NullableType: "[]byte",
}
boolDef = &TypeDef{
Type: "bool",
Expand All @@ -70,7 +71,8 @@ var (
Type: "schema.UUID",
}
jsonDef = &TypeDef{
Type: "[]byte",
Type: "[]byte",
NullableType: "[]byte",
}
hstoreDef = &TypeDef{
Type: "hstore.Hstore",
Expand Down
Loading

0 comments on commit 47f6ef9

Please sign in to comment.