411 REFERENCE · Wikibooks
Yesod web framework/Model
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
Model
Using in-memory mutable data (in the foundation datatype)
E.g. a visitor count. See ref.http://www.yesodweb.com/book/initializing-foundation-data Book - Initializing data in the foundation datatype Yesodweb.com 2014-05-26
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.http://www.yesodweb.com/book/persistent book - Persistent Yesodweb.com 2012-10-23http://hackage.haskell.org/package/yesod-persistent Yesod-persistent package Hackage.haskell.org 2012-10-23https://github.com/yesodweb/persistent/tree/master/docs Yesod-persistent docs github.com 2018-10-16
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.https://github.com/yesodweb/persistent/blob/master/docs/Persistent-entity-syntax.md Yesod-persistent entity syntax github.com 2018-10-16
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.https://github.com/yesodweb/yesod/issues/401 Redundant migrations for fields' default values GitHub.com 2012-12-04
"At most one" cardinality has a special mechanism around the type Checkmark.http://hackage.haskell.org/package/persistent/docs/Database-Persist-Types.html#t:Checkmark "At most one" cardinality enforcement in persistent with type Checkmark Hackage.haskell.org 2018-10-16
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.https://stackoverflow.com/questions/24369045/how-can-i-create-a-foreign-key-constraint-using-yesod-persistent/24379218#24379218 How can I create a foreign key constraint using Yesod/Persistent? stackoverflow.com 2018-10-16
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.
share [mkPersist sqlSettings,
mkMigrate "migrateAll" -- generates the migration procedure with the specified name
] [persist|
User -- table name and entity record type
-- implicit autoincrement column "id" as primary key, typed UserId
ident Text -- refers to db. table column "ident";
-- generates a record field prefixing the table name as "userIdent"
password Text Maybe -- Maybe indicates Nullable field
UniqueUser ident -- unique constraint with space sep. field sequence
Email -- table name and entity record type
-- implicit autoincrement column "id" as primary key, typed EmailId
email Text
user UserId -- foreign key by specifying other tables EntityField types
verkey Text Maybe
newlyAddedColumn Text "default='sometext'::character varying" -- sql level Default constraint
UniqueEmail email -- unique constraint
|]
Esqueleto: is a haskell combinators layer to generate correct relational queries to persistent.http://hackage.haskell.org/package/esqueleto esqueleto package Hackage.haskell.org 2012-10-23
Example for persistent rawSQL and Esqueleto queries.https://stackoverflow.com/questions/9047636/baffled-by-selectonemany-in-yesod/12483493#12483493 Query example at Stackoverflow.com 2012-09-19 2012-10-23
E-mail
The following packages are part of the yesod-platform:http://hackage.haskell.org/package/yesod The yesod package Hackage.haskell.org 2019-06-26
email-validate: Validating an email address.http://hackage.haskell.org/package/email-validate The email-validate package Hackage.haskell.org 2012-10-26
mime-mail: Compose and send MIME email messages.http://hackage.haskell.org/package/mime-mail The mime-mail package. Hackage.haskell.org 2012-10-26
Facebook
Useful glue functions between the fb library and Yesod.http://hackage.haskell.org/package/yesod-fb The yesod-fb package. Hackage.haskell.org 2012-10-26
Development cycle
New Yesod apps are generated from the HaskellStack toolHaskell Stack - How to install 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 The yesod-bin pkg with the helper tool (with instructions for use with the stack 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.http://www.yesodweb.com/book/deploying-your-webapp book - Deploying your Webapp Yesodweb.com 2012-10-23Readme.Md https://github.com/snoyberg/keter#readme Yesod keter readme GitHub 2012-10-23
http://hackage.haskell.org/package/keter The keter package Hackage.haskell.org 2012-10-23
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.http://www.yesodweb.com/blog/2012/10/keter-updates Keter updates Yesodweb.com 2012-10-25 2012-10-25
Old documentation (Nginx based).http://www.yesodweb.com/blog/2012/05/keter-app-deployment Keter: Web App Deployment Yesodweb.com 2012-05-11 2012-10-23http://www.yesodweb.com/blog/2012/05/keter-its-alive Keter: It's Alive! Yesodweb.com 2012-05-17 2012-10-23
Integration with JavaScript generated from functional languages
See ref.https://github.com/yesodweb/yesod/wiki/Javascript-Options Javascript Options github.com 2014-03-12http://www.yesodweb.com/blog/2012/10/yesod-fay-js Yesod, AngularJS and Fay yesodweb.com 2012-10-30 2014-03-12http://www.haskell.org/haskellwiki/The_JavaScript_Problem HaskellWiki - The JavaScript Problem haskell.org 2014-04-12
References
2