src/snorlogue/modelRoutes

Source   Edit  

Snorlogues main module. Provides all procs that add Snorlogue routes to a given Prologue instance.

Procs

proc addAdminRoutes(app: var Prologue; middlewares: seq[HandlerAsync] = @[];
                    urlPrefix: static string = "admin")
Adds an overview, a config/about and an "sql" route. The overview route provides an overview over all registered models The sql route provides a page to execute raw SQL and look at the results. This view supports DML SQL only. The config route provides an overview over some settings, as well as all registered routes of your prologue application. These routes will be available after the pattern urlPrefix/[overview | sql | config]/ Source   Edit  
proc addCrudRoutes[T: Model](app: Prologue; modelType: typedesc[T];
                             middlewares: seq[HandlerAsync] = @[];
                             urlPrefix: static string = "admin";
                             sortFields: seq[string] = @["id"];
                             sortDirection: SortDirection = SortDirection.ASC;
                             beforeCreateAction: ActionProc[T] = nil;
                             afterCreateAction: ActionProc[T] = nil;
                             beforeDeleteAction: ActionProc[T] = nil;
                             beforeUpdateAction: ActionProc[T] = nil;
                             afterUpdateAction: ActionProc[T] = nil)

Adds create, read, update and delete pages with middlewares for modelType. These pages have the URL pattern: <urlPrefix>/<modelType>/[create|delete|detail|list]/. The url uses the modelType in all lowercase. By specifying urlPrefix you can customize the start of these URLs.

The list of Model entries on the list page can be sorted according to the provided sortFields, which is "id" by default. You can sort them in ascending or descending order.

You can also provide event procs to execute before/after you create/update/delete an entry:

  • beforeCreateAction - Gets executed before creating a model. Note that the model will not have an id yet.
  • afterCreateAction - Gets executed after creating a model
  • beforeUpdateAction - Gets executed just before updating a model. Note that the model provided is the new model that will replace the old one.
  • afterUpdateAction - Gets executed just after updating a model. Note that the model provided is the new model that has replaced the old one.
  • beforeDeleteAction - Gets executed just before deleting a model
Source   Edit