diff --git a/cmd/goqueryset/goqueryset b/cmd/goqueryset/goqueryset new file mode 100755 index 0000000..8884de5 Binary files /dev/null and b/cmd/goqueryset/goqueryset differ diff --git a/go.mod b/go.mod index 9c47a12..7fd83ac 100644 --- a/go.mod +++ b/go.mod @@ -17,3 +17,5 @@ require ( golang.org/x/tools v0.0.0-20190226205152-f727befe758c gopkg.in/DATA-DOG/go-sqlmock.v1 v1.2.0 ) + +go 1.13 diff --git a/internal/queryset/generator/methodsbuilder.go b/internal/queryset/generator/methodsbuilder.go index 62b64a3..514be3e 100644 --- a/internal/queryset/generator/methodsbuilder.go +++ b/internal/queryset/generator/methodsbuilder.go @@ -40,12 +40,6 @@ func (b *methodsBuilder) getQuerySetMethodsForField(f field.Info) []methods.Meth basicTypeMethods = append(basicTypeMethods, inMethod, notInMethod) } - if f.IsString { - likeMethod := methods.NewBinaryFilterMethod(fctx.WithOperationName("like")) - notLikeMethod := methods.NewBinaryFilterMethod(fctx.WithOperationName("notlike")) - return append(basicTypeMethods, likeMethod, notLikeMethod) - } - numericMethods := []methods.Method{ methods.NewBinaryFilterMethod(fctx.WithOperationName("lt")), methods.NewBinaryFilterMethod(fctx.WithOperationName("gt")), @@ -53,6 +47,14 @@ func (b *methodsBuilder) getQuerySetMethodsForField(f field.Info) []methods.Meth methods.NewBinaryFilterMethod(fctx.WithOperationName("gte")), } + if f.IsString { + likeMethod := methods.NewBinaryFilterMethod(fctx.WithOperationName("like")) + notLikeMethod := methods.NewBinaryFilterMethod(fctx.WithOperationName("notlike")) + + methods := append(basicTypeMethods, likeMethod, notLikeMethod) + return append(methods, numericMethods...) + } + if f.IsNumeric { return append(basicTypeMethods, numericMethods...) } diff --git a/internal/queryset/generator/test/autogenerated_models.go b/internal/queryset/generator/test/autogenerated_models.go index 017b3e1..7ebcfb4 100644 --- a/internal/queryset/generator/test/autogenerated_models.go +++ b/internal/queryset/generator/test/autogenerated_models.go @@ -240,6 +240,18 @@ func (qs BlogQuerySet) NameEq(name string) BlogQuerySet { return qs.w(qs.db.Where("myname = ?", name)) } +// NameGt is an autogenerated method +// nolint: dupl +func (qs BlogQuerySet) NameGt(name string) BlogQuerySet { + return qs.w(qs.db.Where("myname > ?", name)) +} + +// NameGte is an autogenerated method +// nolint: dupl +func (qs BlogQuerySet) NameGte(name string) BlogQuerySet { + return qs.w(qs.db.Where("myname >= ?", name)) +} + // NameIn is an autogenerated method // nolint: dupl func (qs BlogQuerySet) NameIn(name ...string) BlogQuerySet { @@ -256,6 +268,18 @@ func (qs BlogQuerySet) NameLike(name string) BlogQuerySet { return qs.w(qs.db.Where("myname LIKE ?", name)) } +// NameLt is an autogenerated method +// nolint: dupl +func (qs BlogQuerySet) NameLt(name string) BlogQuerySet { + return qs.w(qs.db.Where("myname < ?", name)) +} + +// NameLte is an autogenerated method +// nolint: dupl +func (qs BlogQuerySet) NameLte(name string) BlogQuerySet { + return qs.w(qs.db.Where("myname <= ?", name)) +} + // NameNe is an autogenerated method // nolint: dupl func (qs BlogQuerySet) NameNe(name string) BlogQuerySet { @@ -687,6 +711,18 @@ func (qs CheckReservedKeywordsQuerySet) TypeEq(typeValue string) CheckReservedKe return qs.w(qs.db.Where("type = ?", typeValue)) } +// TypeGt is an autogenerated method +// nolint: dupl +func (qs CheckReservedKeywordsQuerySet) TypeGt(typeValue string) CheckReservedKeywordsQuerySet { + return qs.w(qs.db.Where("type > ?", typeValue)) +} + +// TypeGte is an autogenerated method +// nolint: dupl +func (qs CheckReservedKeywordsQuerySet) TypeGte(typeValue string) CheckReservedKeywordsQuerySet { + return qs.w(qs.db.Where("type >= ?", typeValue)) +} + // TypeIn is an autogenerated method // nolint: dupl func (qs CheckReservedKeywordsQuerySet) TypeIn(typeValue ...string) CheckReservedKeywordsQuerySet { @@ -703,6 +739,18 @@ func (qs CheckReservedKeywordsQuerySet) TypeLike(typeValue string) CheckReserved return qs.w(qs.db.Where("type LIKE ?", typeValue)) } +// TypeLt is an autogenerated method +// nolint: dupl +func (qs CheckReservedKeywordsQuerySet) TypeLt(typeValue string) CheckReservedKeywordsQuerySet { + return qs.w(qs.db.Where("type < ?", typeValue)) +} + +// TypeLte is an autogenerated method +// nolint: dupl +func (qs CheckReservedKeywordsQuerySet) TypeLte(typeValue string) CheckReservedKeywordsQuerySet { + return qs.w(qs.db.Where("type <= ?", typeValue)) +} + // TypeNe is an autogenerated method // nolint: dupl func (qs CheckReservedKeywordsQuerySet) TypeNe(typeValue string) CheckReservedKeywordsQuerySet { @@ -1152,6 +1200,18 @@ func (qs PostQuerySet) StrEq(str tmp.StringDef) PostQuerySet { return qs.w(qs.db.Where("str = ?", str)) } +// StrGt is an autogenerated method +// nolint: dupl +func (qs PostQuerySet) StrGt(str tmp.StringDef) PostQuerySet { + return qs.w(qs.db.Where("str > ?", str)) +} + +// StrGte is an autogenerated method +// nolint: dupl +func (qs PostQuerySet) StrGte(str tmp.StringDef) PostQuerySet { + return qs.w(qs.db.Where("str >= ?", str)) +} + // StrIn is an autogenerated method // nolint: dupl func (qs PostQuerySet) StrIn(str ...tmp.StringDef) PostQuerySet { @@ -1168,6 +1228,18 @@ func (qs PostQuerySet) StrLike(str tmp.StringDef) PostQuerySet { return qs.w(qs.db.Where("str LIKE ?", str)) } +// StrLt is an autogenerated method +// nolint: dupl +func (qs PostQuerySet) StrLt(str tmp.StringDef) PostQuerySet { + return qs.w(qs.db.Where("str < ?", str)) +} + +// StrLte is an autogenerated method +// nolint: dupl +func (qs PostQuerySet) StrLte(str tmp.StringDef) PostQuerySet { + return qs.w(qs.db.Where("str <= ?", str)) +} + // StrNe is an autogenerated method // nolint: dupl func (qs PostQuerySet) StrNe(str tmp.StringDef) PostQuerySet { @@ -1196,6 +1268,18 @@ func (qs PostQuerySet) TitleEq(title string) PostQuerySet { return qs.w(qs.db.Where("title = ?", title)) } +// TitleGt is an autogenerated method +// nolint: dupl +func (qs PostQuerySet) TitleGt(title string) PostQuerySet { + return qs.w(qs.db.Where("title > ?", title)) +} + +// TitleGte is an autogenerated method +// nolint: dupl +func (qs PostQuerySet) TitleGte(title string) PostQuerySet { + return qs.w(qs.db.Where("title >= ?", title)) +} + // TitleIn is an autogenerated method // nolint: dupl func (qs PostQuerySet) TitleIn(title ...string) PostQuerySet { @@ -1224,6 +1308,18 @@ func (qs PostQuerySet) TitleLike(title string) PostQuerySet { return qs.w(qs.db.Where("title LIKE ?", title)) } +// TitleLt is an autogenerated method +// nolint: dupl +func (qs PostQuerySet) TitleLt(title string) PostQuerySet { + return qs.w(qs.db.Where("title < ?", title)) +} + +// TitleLte is an autogenerated method +// nolint: dupl +func (qs PostQuerySet) TitleLte(title string) PostQuerySet { + return qs.w(qs.db.Where("title <= ?", title)) +} + // TitleNe is an autogenerated method // nolint: dupl func (qs PostQuerySet) TitleNe(title string) PostQuerySet { @@ -1580,6 +1676,18 @@ func (qs UserQuerySet) EmailEq(email string) UserQuerySet { return qs.w(qs.db.Where("email = ?", email)) } +// EmailGt is an autogenerated method +// nolint: dupl +func (qs UserQuerySet) EmailGt(email string) UserQuerySet { + return qs.w(qs.db.Where("email > ?", email)) +} + +// EmailGte is an autogenerated method +// nolint: dupl +func (qs UserQuerySet) EmailGte(email string) UserQuerySet { + return qs.w(qs.db.Where("email >= ?", email)) +} + // EmailIn is an autogenerated method // nolint: dupl func (qs UserQuerySet) EmailIn(email ...string) UserQuerySet { @@ -1596,6 +1704,18 @@ func (qs UserQuerySet) EmailLike(email string) UserQuerySet { return qs.w(qs.db.Where("email LIKE ?", email)) } +// EmailLt is an autogenerated method +// nolint: dupl +func (qs UserQuerySet) EmailLt(email string) UserQuerySet { + return qs.w(qs.db.Where("email < ?", email)) +} + +// EmailLte is an autogenerated method +// nolint: dupl +func (qs UserQuerySet) EmailLte(email string) UserQuerySet { + return qs.w(qs.db.Where("email <= ?", email)) +} + // EmailNe is an autogenerated method // nolint: dupl func (qs UserQuerySet) EmailNe(email string) UserQuerySet { @@ -1698,6 +1818,18 @@ func (qs UserQuerySet) NameEq(name string) UserQuerySet { return qs.w(qs.db.Where("name = ?", name)) } +// NameGt is an autogenerated method +// nolint: dupl +func (qs UserQuerySet) NameGt(name string) UserQuerySet { + return qs.w(qs.db.Where("name > ?", name)) +} + +// NameGte is an autogenerated method +// nolint: dupl +func (qs UserQuerySet) NameGte(name string) UserQuerySet { + return qs.w(qs.db.Where("name >= ?", name)) +} + // NameIn is an autogenerated method // nolint: dupl func (qs UserQuerySet) NameIn(name ...string) UserQuerySet { @@ -1714,6 +1846,18 @@ func (qs UserQuerySet) NameLike(name string) UserQuerySet { return qs.w(qs.db.Where("name LIKE ?", name)) } +// NameLt is an autogenerated method +// nolint: dupl +func (qs UserQuerySet) NameLt(name string) UserQuerySet { + return qs.w(qs.db.Where("name < ?", name)) +} + +// NameLte is an autogenerated method +// nolint: dupl +func (qs UserQuerySet) NameLte(name string) UserQuerySet { + return qs.w(qs.db.Where("name <= ?", name)) +} + // NameNe is an autogenerated method // nolint: dupl func (qs UserQuerySet) NameNe(name string) UserQuerySet { @@ -1838,6 +1982,18 @@ func (qs UserQuerySet) SurnameEq(surname string) UserQuerySet { return qs.w(qs.db.Where("user_surname = ?", surname)) } +// SurnameGt is an autogenerated method +// nolint: dupl +func (qs UserQuerySet) SurnameGt(surname string) UserQuerySet { + return qs.w(qs.db.Where("user_surname > ?", surname)) +} + +// SurnameGte is an autogenerated method +// nolint: dupl +func (qs UserQuerySet) SurnameGte(surname string) UserQuerySet { + return qs.w(qs.db.Where("user_surname >= ?", surname)) +} + // SurnameIn is an autogenerated method // nolint: dupl func (qs UserQuerySet) SurnameIn(surname ...string) UserQuerySet { @@ -1866,6 +2022,18 @@ func (qs UserQuerySet) SurnameLike(surname string) UserQuerySet { return qs.w(qs.db.Where("user_surname LIKE ?", surname)) } +// SurnameLt is an autogenerated method +// nolint: dupl +func (qs UserQuerySet) SurnameLt(surname string) UserQuerySet { + return qs.w(qs.db.Where("user_surname < ?", surname)) +} + +// SurnameLte is an autogenerated method +// nolint: dupl +func (qs UserQuerySet) SurnameLte(surname string) UserQuerySet { + return qs.w(qs.db.Where("user_surname <= ?", surname)) +} + // SurnameNe is an autogenerated method // nolint: dupl func (qs UserQuerySet) SurnameNe(surname string) UserQuerySet { diff --git a/internal/queryset/generator/test/pkgimport/autogenerated_models.go b/internal/queryset/generator/test/pkgimport/autogenerated_models.go index 8cb1eb8..4c22e18 100644 --- a/internal/queryset/generator/test/pkgimport/autogenerated_models.go +++ b/internal/queryset/generator/test/pkgimport/autogenerated_models.go @@ -117,6 +117,18 @@ func (qs ExampleQuerySet) Currency2Eq(currency2 forex.Currency2) ExampleQuerySet return qs.w(qs.db.Where("currency2 = ?", currency2)) } +// Currency2Gt is an autogenerated method +// nolint: dupl +func (qs ExampleQuerySet) Currency2Gt(currency2 forex.Currency2) ExampleQuerySet { + return qs.w(qs.db.Where("currency2 > ?", currency2)) +} + +// Currency2Gte is an autogenerated method +// nolint: dupl +func (qs ExampleQuerySet) Currency2Gte(currency2 forex.Currency2) ExampleQuerySet { + return qs.w(qs.db.Where("currency2 >= ?", currency2)) +} + // Currency2In is an autogenerated method // nolint: dupl func (qs ExampleQuerySet) Currency2In(currency2 ...forex.Currency2) ExampleQuerySet { @@ -133,6 +145,18 @@ func (qs ExampleQuerySet) Currency2Like(currency2 forex.Currency2) ExampleQueryS return qs.w(qs.db.Where("currency2 LIKE ?", currency2)) } +// Currency2Lt is an autogenerated method +// nolint: dupl +func (qs ExampleQuerySet) Currency2Lt(currency2 forex.Currency2) ExampleQuerySet { + return qs.w(qs.db.Where("currency2 < ?", currency2)) +} + +// Currency2Lte is an autogenerated method +// nolint: dupl +func (qs ExampleQuerySet) Currency2Lte(currency2 forex.Currency2) ExampleQuerySet { + return qs.w(qs.db.Where("currency2 <= ?", currency2)) +} + // Currency2Ne is an autogenerated method // nolint: dupl func (qs ExampleQuerySet) Currency2Ne(currency2 forex.Currency2) ExampleQuerySet { @@ -161,6 +185,18 @@ func (qs ExampleQuerySet) Currency3Eq(currency3 forex.Currency3) ExampleQuerySet return qs.w(qs.db.Where("currency3 = ?", currency3)) } +// Currency3Gt is an autogenerated method +// nolint: dupl +func (qs ExampleQuerySet) Currency3Gt(currency3 forex.Currency3) ExampleQuerySet { + return qs.w(qs.db.Where("currency3 > ?", currency3)) +} + +// Currency3Gte is an autogenerated method +// nolint: dupl +func (qs ExampleQuerySet) Currency3Gte(currency3 forex.Currency3) ExampleQuerySet { + return qs.w(qs.db.Where("currency3 >= ?", currency3)) +} + // Currency3In is an autogenerated method // nolint: dupl func (qs ExampleQuerySet) Currency3In(currency3 ...forex.Currency3) ExampleQuerySet { @@ -177,6 +213,18 @@ func (qs ExampleQuerySet) Currency3Like(currency3 forex.Currency3) ExampleQueryS return qs.w(qs.db.Where("currency3 LIKE ?", currency3)) } +// Currency3Lt is an autogenerated method +// nolint: dupl +func (qs ExampleQuerySet) Currency3Lt(currency3 forex.Currency3) ExampleQuerySet { + return qs.w(qs.db.Where("currency3 < ?", currency3)) +} + +// Currency3Lte is an autogenerated method +// nolint: dupl +func (qs ExampleQuerySet) Currency3Lte(currency3 forex.Currency3) ExampleQuerySet { + return qs.w(qs.db.Where("currency3 <= ?", currency3)) +} + // Currency3Ne is an autogenerated method // nolint: dupl func (qs ExampleQuerySet) Currency3Ne(currency3 forex.Currency3) ExampleQuerySet {