-
Notifications
You must be signed in to change notification settings - Fork 0
/
rm.hbs
105 lines (83 loc) · 2.67 KB
/
rm.hbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
[![view on npm](https://img.shields.io/npm/v/@uttori/storage-provider-json-file.svg)](https://www.npmjs.org/package/@uttori/storage-provider-json-file)
[![npm module downloads](https://img.shields.io/npm/dt/@uttori/storage-provider-json-file.svg)](https://www.npmjs.org/package/@uttori/storage-provider-json-file)
[![Build Status](https://travis-ci.com/uttori/uttori-storage-provider-json-file.svg?branch=master)](https://travis-ci.com/uttori/uttori-storage-provider-json-file)
[![Coverage Status](https://coveralls.io/repos/uttori/uttori-storage-provider-json-file/badge.svg?branch=master)](https://coveralls.io/r/uttori/uttori-storage-provider-json-file?branch=master)
# Uttori Storage Provider - JSON File
Uttori Storage Provider using JSON files on disk.
This repo exports both a Uttori Plugin compliant `Plugin` class as well as the underlying `StorageProvider` class.
## Install
```bash
npm install --save @uttori/storage-provider-json-file
```
# Config
```js
{
contentDirectory: '',
historyDirectory: '',
extension: 'json',
spacesDocument: null,
spacesHistory: null,
updateTimestamps: true,
useHistory: true,
// Registration Events
events: {
add: ['storage-add'],
delete: ['storage-delete'],
get: ['storage-get'],
getHistory: ['storage-get-history'],
getRevision: ['storage-get-revision'],
getQuery: ['storage-query'],
update: ['storage-update'],
validateConfig: ['validate-config'],
},
}
```
* * *
# Example
```js
// When part of UttoriWiki:
import { Plugin as StorageProviderJSON } from '@uttori/storage-provider-json-file';
// When stand alone:
import StorageProvider from '@uttori/storage-provider-json-file';
const s = new StorageProvider({
contentDirectory: 'example/content',
historyDirectory: 'example/history',
extension: 'json',
spacesDocument: null,
spacesHistory: null,
});
await s.add({
title: 'Example Title',
slug: 'example-title',
content: '## Example Title',
html: '',
updateDate: 1459310452001,
createDate: 1459310452001,
tags: ['Example Tag'],
customData: {
keyA: 'value-a',
keyB: 'value-b',
keyC: 'value-c',
},
});
const results = await s.getQuery('SELECT tags FROM documents WHERE slug IS_NOT_NULL ORDER BY slug ASC LIMIT 1');
➜ results === [
{ tags: ['Example Tag'] },
]
const results = await s.getQuery('SELECT COUNT(*) FROM documents WHERE slug IS_NOT_NULL ORDER BY RANDOM ASC LIMIT -1');
➜ results === 1
```
# API Reference
{{>main}}
* * *
## Tests
To run the test suite, first install the dependencies, then run `npm test`:
```sh
npm install
npm test
DEBUG=Uttori* npm test
```
## Contributors
* [Matthew Callis](https://github.com/MatthewCallis)
## License
* [MIT](LICENSE)