Skip to content

ahmed7091/leafjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LeafJS 🍃

python JavaScript Node.js

A modern, simple, object-oriented, experimental database, yet fast & easy-to-use.


Content 🍃


Overview 🧩

LeafJS is just LeafDB but using JavaScript node JS + Express JS


Features 🚀

  • Multi-language support: You can communicate with it using any langauge.

  • Available offline: You can communicate with it completely offline.

  • Flexible: LeafJS accepts any type of key & value, which makes it less prone to errors.


Getting Ready ⚡

To setup LeafJS build, you can clone it using git CLI tool by cloning the repo from github, and adding it's tools to your project.
  1. Go to your project path if you haven't:
cd path/to/project
  1. Clone the repo from github using git CLI:
git clone https://github.com/ahmed7091/leafjs.git
  1. go to the leafJS directory & start the server using npm:
cd leafjs
npm start
  1. Declare a port in your project:

python:

from leafjs.leaf import Leaf

leaf: Leaf = Leaf()
leaf.set_port(PORT)

JavaScript:

// ES module
import Leaf from "./leafjs/leaf.js";
// CommonJS
const Leafjs = require("./leafjs/leaf.js").default;

const leaf = new Leafdb();

leaf.setPort(PORT);

PORT is the port you specified in the terminal. The default port is 5000, but if you ever changed it, you Must declare it otherwise the compiler will fail to establish a connection.


Basic usage

Using Javascript

// as an ES module
import Leaf from "./leafjs/leaf.js";
// as a commonJS
const Leaf = require("./leafjs/leaf.js").default;

// Setup
const leaf = new Leaf();
leaf.setPort(3000);

// Using async function because most leaf methods are async
async function main() {
  await leaf.insert({
    "message": "Thanks for using our API.",
    "status_code": 200,
  });
  const data = await leaf.view(); // { "message": "Thanks for using out API.", "status code": 200 }

  const message = await leaf.view("message"); // "Thanks for using our API."

  await leaf.del("status_code"); // status_code field is no longer in the database

  await leaf.edit(
    "message",
    "LeafDB is a great database for experiments & learning."
  );

  const newData = await leaf.view();

  console.log("New data is: ", newData); // 'New data is: { "message": "LeafDB is a great database for experiments & learning." }'
}
main();

Using Python

from leafjs.leaf import Leaf

leaf: Leaf = Leaf()

leaf.set_port(5000)

# Adding some data
leaf.insert({
    "product": "Laptop",
    "price": 899.99,
    "sold": False,
    "tax": "8%"
})

# Viewing all data
data: dict = leaf.view() # {"product": "Laptop", price: 899.99, "sold": False, "tax": "8%"}

# Viewing specific data
product = leaf.view("product")
print(product) # 'Laptop'

leaf.edit("sold", True)

leaf.delete("tax")

new_data: dict = leaf.view()

print("New data: ", new_data) # 'New data: {"product": "Laptop", "price": 899.99, "sold": True}'

LeafDB tools

Here is a table of the functions available in LeafDB tools to use (naming convension changes depending on the language):

name method type usage
setport none sync Sets the dafault port to send requests to
view GET async returns data value if given, else returns all the database.
insert POST async inserts the provided dict/object to the database.
delete DELETE async Deletes the field with the provided key
edit PUT asnyc Changes key's value to value
geturl none sync Returns the current URL of the API

Note: delete method is del in JavaScript to avoid conflicts with the keyword delete

About

A faster, more reliable & stable version of LeafDB, by using JavaScript Node JS + Express JS instead of Python FastAPI

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors