gen icon indicating copy to clipboard operation
gen copied to clipboard

Custom types

Open Kachit opened this issue 2 years ago • 2 comments

Your Question

Hello I want to create custom type (semver), but I don`t know how can I implement this

package types

import (
	"gorm.io/gen/field"
	"gorm.io/gorm/clause"
)

type Semver field.String

// Eq ...
func (s Semver) Eq(value string) Semver {
	return Semver{field.expr{e: clause.Expr{SQL: "semver_compare(?,'=',?)", Vars: []interface{}{s.RawExpr(), value}}}}
}

The document you expected this should be explained

Expected answer

Please tell me what`s wrong ? (it is posible)

Kachit avatar Jul 24 '23 18:07 Kachit

Any ideas ?

Kachit avatar Aug 21 '23 19:08 Kachit

The new type Semver will loss all methods from field.String, the embedded type may be your expected

JasonMing avatar Oct 27 '23 07:10 JasonMing