ORM = Object-Relational Mapper, though for Haskell it’s really more of a Type-Relational Mapper.
Assuming that you have a databaseConnection set up in Config/App.hs and that you have a database, the ORM can be run by:
After the script runs, you should have a number of files in App/Models. Assuming that you have Page and Comment tables:
In general you can ignore the /Bases/* files. To add additional functionality to the Page model, add functions to App/Models/Page.hs (do not add them to any /Bases/* files because the ORM will overwrite the changes). To use a Page, import App.Models.Page, though you’ll probably want to qualify the import to avoid naming conflicts:
import qualified App.Models.Page as Page
import qualified App.Models.Comment as Comment
dummy = do p <- Page.find “some page”
Comment.deleteWhere “pageId = ?” [toSql $ _id p]
Database tables and columns are directly converted as Types and functions, so the ORM will automatically capitalize table names so that they are valid type names and will automatically lowercase column names so that they are valid as functions. As an example, these tables and columns will be mapped to types as follows:
|Database||—>||Haskell Types And Functions|
|page [table]||Page [type]|
|Comment [table]||Comment [type]|
Bits to notice:
In Ruby On Rails, it’s standard to have a column named “id” as the primary key on tables. It’s a nice convention, but “id” is already a function name in Haskell. So the convention in Turbinado is to name the “id” column “_id”.
Following are conventions for Turbinado databases: