Model edit

Using in-memory mutable data (in the foundation datatype) edit

E.g. a visitor count. See ref.[1]

The Database layer edit

  • persistent is the name of the database access layer with templates for generating types for entities and keys as well as schema initialization.[2][3][4]

There is first class support for PostgreSQL, SQLite, MongoDB, CouchDB and MySQL, with experimental support for Redis.[2]

The Database layout is described in a template listing the entities, fields and constraints.[5]

  • 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.[6]
  • "At most one" cardinality has a special mechanism around the type Checkmark.[7]
  • 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.[8]
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.[2] 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.[9]

Example for persistent rawSQL and Esqueleto queries.[10]

E-mail edit

The following packages are part of the yesod-platform:[11]

  • email-validate: Validating an email address.[12]
  • mime-mail: Compose and send MIME email messages.[13]

Facebook edit

  • Useful glue functions between the fb library and Yesod.[14]

Development cycle edit

New Yesod apps are generated from the HaskellStack tool[15] 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 edit

  • The yesod helper tool [16]
    • 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 edit

See refs.[17][18] [19]

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.[20]

Old documentation (Nginx based).[21][22]

Integration with JavaScript generated from functional languages edit

See ref.[23][24][25]

References edit

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