Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lowercase replace in strings? #57

Open
nsemikov opened this issue Jun 19, 2019 · 6 comments
Open

Lowercase replace in strings? #57

nsemikov opened this issue Jun 19, 2019 · 6 comments

Comments

@nsemikov
Copy link

template

package xmpl

import (
	"github.com/jmoiron/sqlx"
)

type Types []Type

func GetTypes(db *sqlx.DB) (Types, error) {
	result := Types{}
	err := db.Select(&result, "SELECT * FROM table;")
	return result, err
}

generated with

//go:generate genny -in=$GOFILE -out=gen-$GOFILE gen "Type=Operation table=operation"

will replace table by Operation, but not operation:

// This file was automatically generated by genny.
// Any changes will be lost if this file is regenerated.
// see https://github.com/cheekybits/genny

package operation

import "github.com/jmoiron/sqlx"

type Operations []Operation

func GetOperations(db *sqlx.DB) (Operations, error) {
	result := Operations{}
	err := db.Select(&result, "SELECT * FROM Operation;")
	return result, err
}
@zhl11b
Copy link

zhl11b commented Oct 29, 2019

this is a bug,I hava same situation.

@gitmonster
Copy link

same here. has anyone a solution?

@zhiqiangxu
Copy link

zhiqiangxu commented Feb 21, 2020

@stdatiks @zhl11b @gitmonster https://github.com/zhiqiangxu/gg can do such jobs with more accurate control:

cat source.go:

package xmpl

import (
	"github.com/jmoiron/sqlx"
)

type Type interface{}

type Types []Type

const Table = "table"

func GetTypes(db *sqlx.DB) (Types, error) {
	result := Types{}
	err := db.Select(&result, "SELECT * FROM " + Table + ";")
	return result, err
}

Then gg -i source.go -t Type=Operation -c Table='"operation"' -d GetTypes=GetOperations will output:

package xmpl

import (
	"github.com/jmoiron/sqlx"
)

type Types []Operation

const Table = "operation"

func GetOperations(db *sqlx.DB) (Types, error) {
	result := Types{}
	err := db.Select(&result, "SELECT * FROM "+Table+";")
	return result, err
}

@nsemikov
Copy link
Author

@zhiqiangxu no, thanks

@rmccrystal
Copy link

Running into the same issue. I tried something like this:

//go:generate genny -in=$GOFILE -out=gen-$GOFILE -tag=generate gen "Model=Student,Event,Location model=student,event,location"

but it made functions for every combination.

@rmccrystal
Copy link

One workaround I can think of is having a generate tag for each type, for instance:

//go:generate genny -in=$GOFILE -out=student-gen.go -tag=generate gen "Model=Student model=student"
//go:generate genny -in=$GOFILE -out=event-gen.go -tag=generate gen "Model=Event model=event"
//go:generate genny -in=$GOFILE -out=location-gen.go -tag=generate gen "Model=Location model=location"

but something cleaner might be nice. Considering this project hasn't been updated in a while and go2 is coming soon, this is probably never going to be fixed :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants