Skip to content

Simple and fast generation of strongly typed gorm parameters

License

Notifications You must be signed in to change notification settings

Ranxy/gormfields

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gormfields

Simple and fast generation of strongly typed gorm parameters.

Usage

Install

Run go install github.com/Ranxy/gormfields/gormfields@latest

Generate

First, add // gormfields:query to the structure to be generated, or use -all in the next command to provide the structure to be generated

Then, use the command gormfields [--all] [path-to-model],as in the example, using gormfields -all . /example/models.

example usage

var userOperator query.Operator[models.User]

userOperator.Find(ctx,
		db,
		models_fields.UserPhone(13412),
		models_fields.UserUserName("foo", query.Or()),
		userOperator.Limit(10),
		userOperator.Offset(20),
	)

Examples of errors

If we use a field from another table, we will get a compile error.

userOperator.Find(ctx,
		db,
		models_fields.UserPhone(13412),
		models_fields.RoleRoleInfo("foo", query.Or()),
		userOperator.Limit(10),
		userOperator.Offset(20),
	)

We will got a compile error like this

cannot use models_fields.RoleRoleInfo("foo", query.Or()) (value of type *models_fields.hRoleRoleInfo) as "github.com/Ranxy/gormfields/query".Field[models.User] value in argument to s.userOperator.Find: *models_fields.hRoleRoleInfo does not implement "github.com/Ranxy/gormfields/query".Field[models.User] (wrong type for method Table)
		have Table() models.Role
		want Table() models.User

Detailed examples can be found in the examples folder.

About

Simple and fast generation of strongly typed gorm parameters

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages