Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/demonicious/jql
Module used for Creating, Managing, Writing and Reading JSON Files and use them as a Database
https://github.com/demonicious/jql
database database-management db json sql
Last synced: 6 days ago
JSON representation
Module used for Creating, Managing, Writing and Reading JSON Files and use them as a Database
- Host: GitHub
- URL: https://github.com/demonicious/jql
- Owner: Demonicious
- License: mit
- Created: 2019-05-17T23:48:43.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-05-19T23:43:04.000Z (over 5 years ago)
- Last Synced: 2023-10-15T16:06:52.377Z (about 1 year ago)
- Topics: database, database-management, db, json, sql
- Language: JavaScript
- Homepage:
- Size: 22.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Ever wanted to use JSON as a database in an SQL-Like Environment ? Yeah me neither but still this is a thing..
## 1.) Installation using NPM
```
npm install --save demon-jql
```## 2.) Basic Usage
```javascript
const { Database } = require("demon-jql");
const db = new Database("newDatabase", "./newDatabase"); // Name and Path
```## 3.) Creating a Table
```javascript
let foodColumns = [
{
"type": "text",
"name": "foodName"
},
{
"type": "text",
"name": "originCountry"
}
]db.createTable("food", foodColumns);
// Expected Return:- bool : true
```## 4.) Inserting Data into Table
```javascript
let data = [
{
"name": "Pizza",
"originCountry": "Italy",
},
{
"name": "Lahmacun",
"originCountry": "Turkey"
}
]db
.write("food", data)
.run();// Expected Return:- bool : true
```## 5.) Reading Data from Table.
```javascript
db
.select("food", "*") // Select Everything
.run();// Expected Return: Object : { "0": { "name": "Pizza", "originCountry": "Italy" }, "1": { "name": "Lahmacun", "originCountry": "Turkey" }, "success": true }
// The Return object has a property of "success" which is either True/False based on if data was retrieveddb
.select("food", ["name"]) // If Selecting Columns Specifically, They need to be placed in a StringArray[] (even for individual columns) e.g ["name", "originCountry"]
.where({"originCountry": "Turkey"}) // Where Method takes in a Object as parameter.
.run();// Expected Return:- Object : { "0" : {"name": "Pizza" }, "success": true }
```## 6.) Updating Pre-existing Data.
```javascript
// Warning: Using .update() without .where() will Update the entire table.db
.update("food", {"name": "Kebab"}) // Update method takes in the Table name and Object as parameters.
.where({"originCountry": "Turkey"})
.run();// Expected Return:- bool : true
```## 7.) Using Auto Increments
```javascript
db.createTable("users", [
{
"type": "number",
"name": "id"
},
{
"type": "text",
"name": "username"
}
])// Expected Return:- bool : true
// If writing a Single row, It still needs to be placed inside an Array[]
db.write("users", [
{
"id": db.nextID(),
"name": "Demonicious"
}
]).run();// Expected Return:- bool : true
```## 8.) An Example
```javascript
const { Database } = require("demon-jql");
const db = new Database("db2", "./db2");// Creating a New Table
// .run() method isn't used here.
db.createTable("someTable", [
{
"type": "number",
"name": "id"
},
{
"type": "text",
"name": "name"
}
]);// Filling the table with Data
db.write("someTable", [
{
"id": db.nextID(),
"name": "Demonicious1"
},
{
"id": db.nextID(),
"name": "Demonicious2"
},
{
"id": db.nextID(),
"name": "Demonicious3"
},
{
"id": db.nextID(),
"name": "Demonicious4"
},
{
"id": db.nextID(),
"name": "Demonicious5"
},
{
"id": db.nextID(),
"name": "Demonicious6"
}
]).run();// Updating a Row
// .where() is optional but without it, it will rewwrite the entire table.
db.update("someTable", {
"name": "DemoniciousSIX"
}).where({
"id": "5"
}).run();// Removing a Row
db.removeRow("someTable").where({
"id":"4"
}).run();// Retrieving single column
// .where() is optional in Select
var data = db.select("someTable", [
"name"
]).where({
"id": "5"
}).run();if (data.success) {
console.log("Name Fetched From Table:", data[0]["name"]);
}// Retrieving Multiple Columns
data = db.select("someTable", [
"id",
"name"
]).where({
"id": "5"
}).run();if (data.success) {
console.log(data);
}// Retrieving Everything
var data = db.select("someTable", "*").where({
"id": "5"
}).run();if (data.success) {
console.log(data);
}// Removing a Table Entirely
// .run() isn't used here.
// I removed this table just to show it can be done.
db.removeTable("someTable");// Just a simple test method()
db.test()
// Returns True if DB is working, otherwise False
```I plan to Make a lot of Optimizations and add more features (making it more sql-like)