-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1f1e79b
commit 600474b
Showing
3 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters