Skip to content

Commit

Permalink
Merge pull request #48 from davidjumani/add-orderby-for-all
Browse files Browse the repository at this point in the history
Adding OrderBy methods for all data types
  • Loading branch information
derElektrobesen authored Aug 1, 2019
2 parents 10c5399 + 2eb8cbd commit 9132023
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 61 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,19 @@ func NewUserQuerySet(db *gorm.DB) UserQuerySet
func (qs UserQuerySet) NameIn(name string, nameRest ...string) UserQuerySet {}
func (qs UserQuerySet) NameNotIn(name string, nameRest ...string) UserQuerySet {}
```
* `Order(Asc|Desc)By{FieldName}()`
```go
func (qs UserQuerySet) OrderDescByRating() UserQuerySet
```
* numeric types (`int`, `int64`, `uint` etc + `time.Time`):
* `{FieldName}(Lt|Lte|Gt|Gte)(arg {FieldType)`
```go
func (qs UserQuerySet) RatingGt(rating int) UserQuerySet
```
* `Order(Asc|Desc)By{FieldName}()`
* string types (`string`):
* `{FieldName}(Like/Notlike)(arg {FieldType)`
```go
func (qs UserQuerySet) OrderDescByRating() UserQuerySet
func (qs UserQuerySet) NameLike(name string) UserQuerySet
```
* pointer fields: `{FieldName}IsNull()`, `{FieldName}IsNotNull()`
```go
Expand Down
102 changes: 54 additions & 48 deletions examples/comparison/gorm4/autogenerated_gorm4.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions internal/queryset/generator/methodsbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ func (b *methodsBuilder) getQuerySetMethodsForField(f field.Info) []methods.Meth
basicTypeMethods := []methods.Method{
methods.NewBinaryFilterMethod(fctx.WithOperationName("eq")),
methods.NewBinaryFilterMethod(fctx.WithOperationName("ne")),
methods.NewOrderAscByMethod(fctx),
methods.NewOrderDescByMethod(fctx),
}

if !f.IsTime {
Expand All @@ -49,8 +51,6 @@ func (b *methodsBuilder) getQuerySetMethodsForField(f field.Info) []methods.Meth
methods.NewBinaryFilterMethod(fctx.WithOperationName("gt")),
methods.NewBinaryFilterMethod(fctx.WithOperationName("lte")),
methods.NewBinaryFilterMethod(fctx.WithOperationName("gte")),
methods.NewOrderAscByMethod(fctx),
methods.NewOrderDescByMethod(fctx),
}

if f.IsNumeric {
Expand Down
84 changes: 84 additions & 0 deletions internal/queryset/generator/test/autogenerated_models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9132023

Please sign in to comment.