Documentation ¶
Index ¶
Constants ¶
View Source
const ( SEARCH = 1 // Filter response with LIKE query "search={search_phrase}" FILTER = 2 // Filter response by column name values "filter={column_name}:{value}" PAGINATE = 4 // Paginate response with page and page_size ORDER_BY = 8 // Order response by column name ALL = 15 // Equivalent to SEARCH|FILTER|PAGINATE|ORDER_BY )
Variables ¶
This section is empty.
Functions ¶
func FilterByQuery ¶
Filter DB request with query parameters. Note: Don't forget to initialize DB Model first, otherwise filter and search won't work Example:
db.Model(&UserModel).Scope(filter.FilterByQuery(ctx, filter.ALL)).Find(&users)
Or if only pagination and order is needed:
db.Model(&UserModel).Scope(filter.FilterByQuery(ctx, filter.PAGINATION|filter.ORDER_BY)).Find(&users)
And models should have appropriate`filter` tags:
type User struct { gorm.Model Username string `gorm:"uniqueIndex" filter:"param:login;searchable;filterable"` // `param` defines custom column name for the query param FullName string `filter:"searchable"` }
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.