Persistent Blog Example- with Redis support!

May 31, 2010

GravatarMichael Snoyman

One of the typical examples applications given by web frameworks is the blog: it shows basic CRUD operations, templating a dispatch- in other words, Model, View and Controller. The current Yesod blog tutorial includes no persistence support, so one of the goals of persistent is to make it possible to have a very light-weight blog tutorial.

Well, it's not light-weight yet, but I've included the blog tutorial in the persistent repo. And here's the really cool part: there's a sqlite version and a Redis version!

Redis support is far from complete (and I mean far), but I think this is a very nice proof-of-concept. And to my knowledge, this might make Yesod the first web framework to have support for the new generation of NoSQL, key-value datastores.

New high-level syntax

I've also scrapped the ugly YAML-based syntax that I'd cobbled together for something which, in my opinion, in much nicer. I'd appreciate feedback on it. The basic idea is:

  • Any non-indented line should contain the name of the table. Table name must be capitalized.
  • All indented lines (ie, anything beginning with a space) are attribute lines, and are applied to the most recent table name.
  • An attribute line beginning with a lowercase defines a column. The first word is the column name, the second is the datatype of the column, and the remaining words are attributes of the column. For example, null means the field is nullable, Eq means the field can be filtered by equality, etc.
  • An attribute line beginning with an uppercase defines a unique key. The first word is the constructor name, and the following words are the column names in the unique key.

Here's the definition taken straight from the blog example:

Entry
    slug String
    date Day Desc
    title String
    content HtmlContent
    UniqueSlug slug

Here, we can sort in descending order by date, and the slug must be unique.

Comments

comments powered by Disqus

Archives