improve the example project #1

nurpax opened this Issue Aug 19, 2012 · 7 comments

3 participants

  • Add example uses of some simple queries to demonstrate query/execute functions.
  • How to use the currently logged in user

Also, need example to show when and how to create tables.


Good suggestion. So far I have used only local scripts for creating tables. I.e., having 01-schema.sql scripts which contain SQL statements for table creation. If the schema changes, one can create 02-schema.sql script that uses ALTERs to change from schema version 1 to 2, and so on. A restart of the Snap server will be required if the schema is modified.

Another approach would be to check database schema version on every query, and calling an upgrade/creation Haskell function to create tables as necessary. However, this has the cost of one extra query per request as one needs to query the database schema version.

Having the table creation & upgrade happen in Haskell code would be preferable from the example's POV. This way anyone who tries to run the example won't need to worry about running separate SQL queries on the command line just to get the example app to run.

@daapp Did you have any suggestions or preferences where and how you might take care of table creation?

@mightybyte Did you ever give this any thought in snaplet-postgresql-simple?


Migrations are tricky. snaplet-postgresql-simple is intended to be a simple wrapper around postgresql-simple, so I'll leave migration features to them.

EDIT: Actually, the new groundhog has some migration support that looks interesting.


@mightybyte Sorry for being vague in my question. I don't actually plan on baking any type of generic migration into snaplet-sqlite-simple (or into sqlite-simple).

I was fishing for tips in case you had an "obvious" place in the snaplet framework to hook stuff like DB table creation into. Now that I'm thinking about this again, perhaps a good place for this type of stuff would be in

-- | The application initializer.
app :: SnapletInit App App

Yes. snaplet-postgresql-simple has this.

@nurpax nurpax added a commit that referenced this issue Oct 3, 2012
@nurpax Add a few more features into the example project
- Execute database table creation on app initialization.  This creates
  a simple schema if the db tables do not already exist.

- Demonstrate how to access and use the logged in AuthUser to save
  data into user's own tables depending on who's logged in.

- Implement a form that the logged in user can use to save comments
  into his "comments list" (kind of like a naive todo list without a
  checkbox for marking todos completed :))

- Also demonstrates rendering a list of elements within a Heist

Routing is still messy.  '/' gets routed to the wrong handler.  So
when you run the app, browse to http://localhost:8000/index to see the
correct page.  Do the same after login too.

WIP for issue #1

@daapp You might find commit d53b8fd interesting..

@nurpax nurpax added a commit that referenced this issue Oct 4, 2012
@nurpax Server the root '/' URL correctly
Also rename the Model module to Db and import it qualified.  This is
done just to highlight which calls in the example call into the

Serve /static under /static path.

Work in progress for #1

This should be a lot better already in the latest in the snap-0.10 branch. Will be merged to master when snap-0.10 gets released.

@nurpax nurpax closed this Oct 18, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment