22
33Database-agnostic interface to generically persisted data.
44
5- ## Introduction
5+ Easy way to go from idea to prototype for your Haskell backend.
6+
7+ Intended for:
8+ - quick demos/prototypes
9+ - internal dashboards
610
7- Explanation of the above:
8- - Database-agnostic: the typeclass is called ` MonadDb ` , and you must specify how
9- an instance can communicate with your database. We provide an example for
10- connecting to Postgres in the [ runnable tutorial] ( tutorial/tutorial/Main.hs ) .
11- - Generically persisted data: you can derive the necessary instances in one line
12- via ` Generics ` , to enable ` MonadDb ` to read/write instances of your data types
13- to/from your database.
11+ Not (yet) intended for:
12+ - public-facing production apps
13+ - apps requiring complex database queries
1414
15- A key intended feature of this library is that the typeclass ` MonadDb ` can be
16- used either server-side or client-side. Allowing your client application (e.g.
17- web app) to use the same functions to access your data as your server-side does.
15+ ## Introduction
1816
19- Another important intended feature is an optional ` servant ` server. Merely
20- provide an instance of ` MonadDb ` so the server knows how to communicate with
21- your database, then the server can act as a proxy to allow clients to read/write
22- to your database without having to write the usual server boilerplate.
17+ Explanation of the tagline:
18+ - Database-agnostic: this library exports a typeclass called ` MonadDb ` for
19+ communicating with a database of your choice, so you will need to write an
20+ ` instance MonadDb MyApp ` to specify how to communicate with your database. We
21+ provide an example for Postgres in the [ tutorial] ( tutorial/tutorial/Main.hs ) .
22+ - Generically persisted data: it is easy to derive all the necessary instances
23+ for your data types in one line. This will allow ` MonadDb ` to read/write
24+ instances of your data types to/from your database.
25+
26+ Two important features of this library:
27+ - ** Server for free** : merely provide an instance of ` MonadDb ` so the server
28+ knows how to communicate with your database. Avoid needing to write the usual
29+ server boilerplate!
30+ - ** Same code server-side and client-side** : your client application (e.g. web
31+ app) can use the same functions to access your data as your server-side does!
2332
2433## Quick Start
2534
26- The [ runnable tutorial] ( tutorial/tutorial/Main.hs ) is the recommended way of
27- becoming familiar with ` database-generic ` .
35+ The [ tutorial] ( tutorial/tutorial/Main.hs ) is the recommended way of becoming
36+ familiar with ` database-generic ` .
2837
2938To run the tutorial on your machine:
30391 . Clone this repo.
@@ -34,8 +43,8 @@ To run the tutorial on your machine:
3443
3544## Features
3645
37- Examples of the following features can be found in [ the
38- tutorial] ( tutorial/tutorial/Main.hs ) .
46+ Working examples of the following features can be found in the
47+ [ tutorial] ( tutorial/tutorial/Main.hs ) .
3948
4049| Feature | In Tutorial | Tested |
4150| ------------------------------------------| -------------| --------|
@@ -67,13 +76,19 @@ tutorial](tutorial/tutorial/Main.hs).
6776
6877## Documentation
6978
70- The following attempts to descibe how the library works, and the various type
71- classes involved. However it is recommended to begin by reading through the code
72- in the [ runnable tutorial] ( tutorial/tutorial/Main.hs ) , and only come back and
73- read this if you feel you need to.
79+ The following _ attempts_ to descibe how this library works. However it is
80+ recommended to read through the [ tutorial] ( tutorial/tutorial/Main.hs ) first, and
81+ only come back and read this if you feel you need to.
7482
7583### Necessary Instances
7684
85+ Since ` Person ` meets all of the critera, a few type classes will be
86+ automatically derived for ` Person ` via ` Generic ` :
87+ - ` HasDbColumns Person ` : names & types of database fields/columns
88+ - ` HasEntityName Person ` : a name for the database collection/table
89+ - ` FromDbValues Person ` : to convert from database values
90+ - ` ToDbValues Person ` : to convert to database values
91+
7792The easiest way to use a data type with this library is to:
7893- ensure the data type only has one constructor
7994- derive a ` Generic ` instance
@@ -88,13 +103,6 @@ data Person = Person { age :: !Int64, name :: !String, ownsDog :: !(Maybe Bool)
88103 deriving (Generic , PrimaryKey "name")
89104```
90105
91- Since `Person ` meets all of the critera, a few type classes will be
92- automatically derived for `Person ` via `Generic `:
93- - `HasDbColumns Person `: to provide a database schema
94- - `HasEntityName Person `: to provide a database schema
95- - `FromDbValues Person `: to convert from database values
96- - `ToDbValues Person `: to convert to database values
97-
98106### HasDbColumns
99107
100108`HasDbColumns ` is responsible for converting each field into a named field along
0 commit comments