# Yesod web framework/Model
### Model
#### Using in-memory mutable data (in the foundation datatype)

E.g. a visitor count. See ref.

#### The Database layer

* persistent is the name of the database access layer with templates for generating types for entities and keys as well as schema initialization.
There is first class support for PostgreSQL, SQLite, MongoDB, CouchDB and MySQL, with experimental support for Redis.
The Database layout is described in a template listing the entities, fields and constraints.
* For every entity listed, an integer key column "id" is generated with autoincrement and primary index attributes, with a type alias appending Id to the entity name
* For every entity listed, a record type named as the entity is generated were record fields names are composed prefixing the entity name to the field name like "personName". An EntityField type "PersonName" is also generated for foreign key referencing from other entities.
* There is an automatic database schema migration mechanism for DB schema updates, which, to succeed, requires, when adding columns to existent tables, to specify Default-column-value constraints with sql level notation.
* "At most one" cardinality has a special mechanism around the type Checkmark.
* Weak entities (childs in life constrained owner-child relationships) have no special support for cascade delete triggers, but there are functions to deleteCascade manually in the Database.Persist.Class module.

##### automatic table creation, schema update and table migration

    Modifications of the entities template produces an schema update with automatic table creation, and migration for the DBMS's that support "ALTER TABLE" SQL commands in a migrateAll procedure, generated from the template content. See "Migrations" in ref. to look for migration aware DBMS.
* Esqueleto: is a haskell combinators layer to generate correct relational queries to persistent.
Example for persistent rawSQL and Esqueleto queries.

### E-mail

The following packages are part of the yesod-platform:
* email-validate: Validating an email address.
* mime-mail: Compose and send MIME email messages.

### Facebook

* Useful glue functions between the fb library and Yesod.

## Development cycle

New Yesod apps are generated from the HaskellStack tool templates, replacing previous command "yesod init"
Stack based app. template names are prefixed by yesod as "yesod-{minimal | postgres | sqlite | mysql | mongo | ...}"
* Since HaskellStack uses the stackage repo by default, extra packages from the hackage repo should be referred in the "stack.yaml" extra-deps section.
* You may customize packages to a local subfolder. They must be referred in the "stack.yaml" packages section.

### The "Yesod helper" tool

* The yesod helper tool
** yesod devel run from the project site, recompiles and restarts the project at every file tree modification.
** yesod add-handler adds a new handler and module to the project, adding an import clause for the handler in the "Application" module.

### Deploying with Keter: A web app server monitor and reverse proxy server

See refs.
Keter is a process as a service that handles deployment and restart of Yesod web app servers, and, per web app, database creation for PostgreSQL.
The console command yesod keter packs the web app. as a keter bundle for uploading to a keter folder named "incoming".
Keter monitors the "incoming" folder and unpacks the app. to a temporary one, then assigns the web app a port to listen to, and starts it.
Initially it worked with Nginx as reverse proxy (keter version 0.1*), adding virtual server entries to its configuration and making Nginx reload it, but now Keter itself provides its own reverse proxy functionality, removing Nginx dependency and acting as the main web server.
Old documentation (Nginx based).

## Integration with JavaScript generated from functional languages

See ref.

## References

* ↑ "Book - Initializing data in the foundation datatype". Yesodweb.com. Retrieved 2014-05-26.
* 1 2 3 "book - Persistent". Yesodweb.com. Retrieved 2012-10-23.
* ↑ "Yesod-persistent package". Hackage.haskell.org. Retrieved 2012-10-23.
* ↑ "Yesod-persistent docs". github.com. Retrieved 2018-10-16.
* ↑ "Yesod-persistent entity syntax". github.com. Retrieved 2018-10-16.
* ↑ "Redundant migrations for fields' default values". GitHub.com. Retrieved 2012-12-04.
* ↑ ""At most one" cardinality enforcement in persistent with type Checkmark". Hackage.haskell.org. Retrieved 2018-10-16.
* ↑ "How can I create a foreign key constraint using Yesod/Persistent?". stackoverflow.com. Retrieved 2018-10-16.
* ↑ "esqueleto package". Hackage.haskell.org. Retrieved 2012-10-23.
* ↑ "Query example at". Stackoverflow.com. 2012-09-19. Retrieved 2012-10-23.
* ↑ "The yesod package". Hackage.haskell.org. Retrieved 2019-06-26.
* ↑ "The email-validate package". Hackage.haskell.org. Retrieved 2012-10-26.
* ↑ "The mime-mail package". Hackage.haskell.org. Retrieved 2012-10-26.
* ↑ "The yesod-fb package". Hackage.haskell.org. Retrieved 2012-10-26.
* ↑ Haskell Stack - How to install
* ↑ The yesod-bin pkg with the helper tool (with instructions for use with the stack tool)
* ↑ "book - Deploying your Webapp". Yesodweb.com. Retrieved 2012-10-23.
* ↑ Readme.Md. "Yesod keter readme". GitHub. Retrieved 2012-10-23.
* ↑ "The keter package". Hackage.haskell.org. Retrieved 2012-10-23.
* ↑ "Keter updates". Yesodweb.com. 2012-10-25. Retrieved 2012-10-25.
* ↑ "Keter: Web App Deployment". Yesodweb.com. 2012-05-11. Retrieved 2012-10-23.
* ↑ "Keter: It's Alive!". Yesodweb.com. 2012-05-17. Retrieved 2012-10-23.
* ↑ "Javascript Options". github.com. Retrieved 2014-03-12.
* ↑ "Yesod, AngularJS and Fay". yesodweb.com. 2012-10-30. Retrieved 2014-03-12.
* ↑ "HaskellWiki - The JavaScript Problem". haskell.org. Retrieved 2014-04-12.