Skip to content

Commit 7d09d2e

Browse files
committed
Docs wip
1 parent bd22ee5 commit 7d09d2e

2 files changed

Lines changed: 44 additions & 34 deletions

File tree

README.md

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,38 @@
22

33
Database-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

2938
To run the tutorial on your machine:
3039
1. 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+
7792
The 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

tutorial/tutorial/Main.hs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,13 @@ main = do
8686
info "Insert many" $
8787
insertMany [Person 25 "Alice" $ Just True, Person 25 "Bob" Nothing]
8888

89-
info "Insert many, returning" $
90-
returning $ insertMany [Person 26 "Charlie" Nothing, Person 26 "Dee" $ Just False]
89+
info "Insert many, returning"
90+
$ returning
91+
$ insertMany [Person 26 "Charlie" Nothing, Person 26 "Dee" $ Just False]
9192

92-
info "Insert many, returning age" $
93-
insertMany [Person 27 "Enid" Nothing, Person 27 "Flavio" Nothing] ==> field @"age"
93+
info "Insert many, returning age"
94+
$ insertMany [Person 27 "Enid" Nothing, Person 27 "Flavio" Nothing]
95+
==> field @"age"
9496

9597
info "Select all" $ selectAll @Person
9698

0 commit comments

Comments
 (0)