Skip to content

Commit 9d25775

Browse files
committed
Add support for external db adapters
1 parent 1b7401f commit 9d25775

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ See [`server-setup.md`](./server-setup.md) for instructions on acquiring a serve
2424

2525
> **Note**: You can pass any option to the `micro-analytics` command that you can pass to [`micro`](https://github.com/zeit/micro). As an example, to change the host you'd do `micro-analytics -H 127.0.0.1`
2626
27+
### Database adapters
28+
29+
micro-analytics supports custom database adapters. They can be configured with the environment
30+
variable `DB_ADAPTER`. Setting it to `redis` will make it require `micro-analytics-adapter-redis`.
31+
Leaving it unset will make micro-analytics use the builtin flat-file-db adapter.
32+
2733
## Usage
2834

2935
### Tracking views

src/db.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
const flatfile = require('flat-file-db')
22
const promise = require('promise')
33

4-
const adapter = require('./flat-file-adapter');
4+
let adapter
5+
6+
if (process.env.DB_ADAPTER) {
7+
adapter = require('micro-analytics-adapter-' + process.env.DB_ADAPTER)
8+
} else {
9+
adapter = require('./flat-file-adapter')
10+
}
511

612
module.exports = {
713
get: adapter.get,

0 commit comments

Comments
 (0)