Copyright | (c) digitally induced GmbH 2021 |
---|---|
Safe Haskell | None |
Synopsis
- paginate :: forall {k} controller (table :: Symbol) queryBuilderProvider (joinRegister :: k). (?context :: ControllerContext, ?modelContext :: ModelContext, ?theAction :: controller, KnownSymbol table, HasQueryBuilder queryBuilderProvider joinRegister) => queryBuilderProvider table -> IO (queryBuilderProvider table, Pagination)
- paginateWithOptions :: forall {k} controller (table :: Symbol) queryBuilderProvider (joinRegister :: k). (?context :: ControllerContext, ?modelContext :: ModelContext, ?theAction :: controller, KnownSymbol table, HasQueryBuilder queryBuilderProvider joinRegister) => Options -> queryBuilderProvider table -> IO (queryBuilderProvider table, Pagination)
- filterList :: forall {k} (name :: Symbol) (table :: Symbol) model queryBuilderProvider (joinRegister :: k). (?context :: ControllerContext, KnownSymbol name, HasField name model Text, model ~ GetModelByTableName table, KnownSymbol table, HasQueryBuilder queryBuilderProvider joinRegister, Table model) => Proxy name -> queryBuilderProvider table -> queryBuilderProvider table
- defaultPaginationOptions :: Options
- paginatedSqlQuery :: (FromRow model, ?context :: ControllerContext, ?modelContext :: ModelContext) => ByteString -> [Action] -> IO ([model], Pagination)
- paginatedSqlQueryWithOptions :: (FromRow model, ?context :: ControllerContext, ?modelContext :: ModelContext) => Options -> ByteString -> [Action] -> IO ([model], Pagination)
Documentation
paginate :: forall {k} controller (table :: Symbol) queryBuilderProvider (joinRegister :: k). (?context :: ControllerContext, ?modelContext :: ModelContext, ?theAction :: controller, KnownSymbol table, HasQueryBuilder queryBuilderProvider joinRegister) => queryBuilderProvider table -> IO (queryBuilderProvider table, Pagination) Source #
Paginate a query, with the following default options:
- Maximum items per page: 50. Each page will show at most 50 items.
- Selector window size: 5. The selector will show the current page, and 5 pages before and after it, if they exist.
This function should be used inside your controller action. It will do two things:
- Using the
page
(current page number to display) andmaxItems
(which overrides the set maximum items per page) request parameters, this applies the the needed limit and offset to display the correct page. For instance, page 3 with a maxItems of 50 would produce a limit of 50 and an offset of 100 to display results 100 through 150. - Returns a
Pagination
state which should be passed through to your view and then, in turn,renderPagination
.
Example:
action UsersAction = do (userQ, pagination) <- query @User |> orderBy #email |> paginate user <- userQ |> fetch render IndexView { .. }
paginateWithOptions :: forall {k} controller (table :: Symbol) queryBuilderProvider (joinRegister :: k). (?context :: ControllerContext, ?modelContext :: ModelContext, ?theAction :: controller, KnownSymbol table, HasQueryBuilder queryBuilderProvider joinRegister) => Options -> queryBuilderProvider table -> IO (queryBuilderProvider table, Pagination) Source #
Paginate with ability to override the default options for maximum items per page and selector window size.
This function should be used inside your controller action. It will do two things:
- Using the
page
(current page number to display) andmaxItems
(which overrides the set maximum items per page) request parameters, this applies the the needed limit and offset to display the correct page. For instance, page 3 with a maxItems of 50 would produce a limit of 50 and an offset of 100 to display results 100 through 150. - Returns a
Pagination
state which should be passed through to your view and then, in turn,renderPagination
.
Example:
action UsersAction = do (userQ, pagination) <- query @User |> orderBy #email |> paginateWithOptions (defaultPaginationOptions |> set #maxItems 10) user <- userQ |> fetch render IndexView { .. }
filterList :: forall {k} (name :: Symbol) (table :: Symbol) model queryBuilderProvider (joinRegister :: k). (?context :: ControllerContext, KnownSymbol name, HasField name model Text, model ~ GetModelByTableName table, KnownSymbol table, HasQueryBuilder queryBuilderProvider joinRegister, Table model) => Proxy name -> queryBuilderProvider table -> queryBuilderProvider table Source #
Reading from the filter
query parameter, filters a query according to the string entered in the
filter box by the user (if any), on a given text-based field. Will return any results containing the
string in a case-insensitive fashion.
Example:
action UsersAction = do (userQ, pagination) <- query @User |> orderBy #email |> paginate |> filterList #email user <- userQ |> fetch render IndexView { .. }
defaultPaginationOptions :: Options Source #
Default options for a pagination. Can be passed into paginateOptions
. The defaults are as follows:
- Maximum items per page: 50. Each page will show at most 50 items.
- Selector window size: 5. The selector will show the current page, and up to 5 pages before and after it, if they exist.
paginatedSqlQuery :: (FromRow model, ?context :: ControllerContext, ?modelContext :: ModelContext) => ByteString -> [Action] -> IO ([model], Pagination) Source #
Runs a raw sql query and adds pagination to it.
By default, the pagination uses the following options: 1. Maximum items per page: 50. Each page will show at most 50 items. 2. Selector window size: 5. The selector will show the current page, and 5 pages before and after it, if they exist.
This function should be used inside your controller action. It will do three things:
- Using the
page
(current page number to display) andmaxItems
(which overrides the set maximum items per page) request parameters, this applies the the needed limit and offset to display the correct page. For instance, page 3 with a maxItems of 50 would produce a limit of 50 and an offset of 100 to display results 100 through 150. - Returns a
Pagination
state which should be passed through to your view and then, in turn,renderPagination
. - Actually run the query and return the result.
Example:
(users, pagination) <- paginatedSqlQuery "SELECT id, firstname, lastname FROM users" ()
Take a look at IHP.QueryBuilder for a typesafe approach on building simple queries.
- AutoRefresh:* When using
paginatedSqlQuery
with AutoRefresh, you need to usetrackTableRead
to let AutoRefresh know that you have accessed a certain table. Otherwise AutoRefresh will not watch table of your custom sql query.
paginatedSqlQueryWithOptions :: (FromRow model, ?context :: ControllerContext, ?modelContext :: ModelContext) => Options -> ByteString -> [Action] -> IO ([model], Pagination) Source #
Runs a raw sql query and adds pagination to it.
This function accepts the same Options as paginateWithOptions
, but otherwise behaves like paginatedSqlQuery
.
Example:
(users, pagination) <- paginatedSqlQueryWithOptions (defaultPaginationOptions |> set #maxItems 10) "SELECT id, firstname, lastname FROM users" ()
Take a look at IHP.QueryBuilder for a typesafe approach on building simple queries.
- AutoRefresh:* When using
paginatedSqlQuery
with AutoRefresh, you need to usetrackTableRead
to let AutoRefresh know that you have accessed a certain table. Otherwise AutoRefresh will not watch table of your custom sql query.