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

How to remove the anotation and the extra functions ,remaining only clean struct? #8

Open
fwhezfwhez opened this issue Nov 2, 2018 · 1 comment

Comments

@fwhezfwhez
Copy link

fwhezfwhez commented Nov 2, 2018

In the guide case I get:

// Class represents public.class
type Class struct {
	ID   int             // id
	Age  sql.NullInt64   // age
	Name sql.NullString  // name
	Sal  sql.NullFloat64 // sal
}
// Create inserts the Class to the database.
func (r *Class) Create(db Queryer) error {
	err := db.QueryRow(
		`INSERT INTO class (age, name, sal) VALUES ($1, $2, $3) RETURNING id`,
		&r.Age, &r.Name, &r.Sal).Scan(&r.ID)
	if err != nil {
		return errors.Wrap(err, "failed to insert class")
	}
	return nil
}

// GetClassByPk select the Class from the database.
func GetClassByPk(db Queryer, pk0 int) (*Class, error) {
	var r Class
	err := db.QueryRow(
		`SELECT id, age, name, sal FROM class WHERE id = $1`,
		pk0).Scan(&r.ID, &r.Age, &r.Name, &r.Sal)
	if err != nil {
		return nil, errors.Wrap(err, "failed to select class")
	}
	return &r, nil
}

But I only want

type Class struct {
	ID   int             
	Age  sql.NullInt64   
	Name sql.NullString  
	Sal  sql.NullFloat64 
}
@fwhezfwhez
Copy link
Author

By the way , db_types 'character varying' didn't work.
I config like

[string]
db_types = ["character", "character varying", "text", "money", "uuid", "varchar"]
notnull_go_type = "string"
nullable_go_type = "string"

But got

...
	F103            interface{}
...

The field 'F103' in postgres is charactor varying

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

1 participant