Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdalton2 committed Jun 30, 2016
1 parent 1f1e79b commit 600474b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,46 @@
# DirtyDB

A JSON file reading and writing utility.

To get started, create a new instance of DirtyDB.

```javascript
const instance = new DirtyDB("path/to/db.json");
```

Let's say the JSON file looked something like this:
```javascript
{
"languages": [
"CoffeeScript",
"TypeScript",
"JavaScript"
],
"best": "JavaScript"
}
```

### Reading from a database

Now, you can read from the JSON file.

```javascript
let data = instance.read(); // the entirety of the JSON data will be returned.
```

Alternatively, you can read only a certain datum by passing its key as a parameter to the `read` function, like so:

```javascript
let data = instance.read("languages"); // this will return an array containing ["CoffeeScript", "TypeScript", "JavaScript"]
let data = instance.read("best"); // this will return a string containing "JavaScript"
```

### Writing to a database

You can write to a database with the `write` function.

```javascript
let customData = instance.read();
customData.languages.push("Dart");
instance.write(customData); // the JSON file is modified to include "Dart" in the "languages" array.
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dirtydb",
"version": "1.0.2",
"version": "1.0.3",
"description": "A JSON file reading and writing utility.",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const fs = require("fs");

describe("DirtyDB", function() {
fs.writeFileSync("test/test1.json", fs.readFileSync("test/test.json"));
let dirtyInstance = new DirtyDB("test/test1.json");
const dirtyInstance = new DirtyDB("test/test1.json");
let mc_local = 0;
let mc = 0;
dirtyInstance.onChange(function() {
Expand Down

0 comments on commit 600474b

Please sign in to comment.