https://github.com/dinoscapeprogramming/database-framework
A simple database using fs
https://github.com/dinoscapeprogramming/database-framework
Last synced: about 1 year ago
JSON representation
A simple database using fs
- Host: GitHub
- URL: https://github.com/dinoscapeprogramming/database-framework
- Owner: DinoscapeProgramming
- License: apache-2.0
- Created: 2022-02-13T10:38:54.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-03-02T18:32:25.000Z (over 4 years ago)
- Last Synced: 2025-02-12T17:28:30.338Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 93.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Database Template
A database template programmed with fs and using arrays
## Get started
First copy the file __database-template.js__ to your program. Then create a JSON file with ``` [] ``` as content or add this to your code:
```js
database.setup('./database.json')
```
Now you're ready to use this database framwork!
## Introduction
### Require the framework
```js
const database = require('./database-template.json');
```
### Add an element to a database
```js
database.add('./database.json', 'hello')
```
### Remove an element from a database
```js
database.remove('./database.json', 'world')
```
### Get an element from a database
```js
database.get('./database.json', 'how are you')
```
### Change an element from a database
```js
database.set('./database.json', 'world', 'guys')
```
### Change an element from a database by id
```js
database.set('./database.json', database.get('./database.json', 2), 'github')
```
### Has database an element
```js
database.has('./database.json', 'i am fine') // replies with true or false
```
### Clear a database
```js
database.clear('./database.json')
```
### Get a whole database
```js
database.all('./database.json', i am fine') // replies with an array
```
### Unsetup a database
```js
database.unsetup('./database.json')
```
## Example
```js
const database = require('./database-template.js');
const settings = {
file: './database.json'
}
database.setup(settings.file)
database.clear(settings.file)
database.add(settings.file, "Hello")
database.add(settings.file, "World")
database.add(settings.file, "!")
database.remove(settings.file, "World")
if (database.has(settings.file, "World") {
console.log("How are you?")
} else {
console.log("How are you all on the world?")
}
database.set(settings.file, "World", "You there")
console.log(database.all(settings.file))
database.unsetup(settings.file)
```