Code Monkey home page Code Monkey logo

erenaydb's Introduction

ErenayDB

Download Download Download License

What's New In 0.0.7?

Added MySQL Adapter

Examples

(QuickDB) Moving Everything to ErenayDB

const db = require("erenaydb");
const quickdb = require("quick.db");

await db.move(quickdb)

(JsonDB) Moving Everything to MongoDB

const db = require("erenaydb");
db.setAdapter("mongo", {url: "YOUR_MONGO_URL"})
const JsonDB = require("../your_file.json");

db.moveToMongo(JsonDB)

Example

const db = require("erenaydb")

db.set("x.y.z", "abc") // abc

db.get("x") // {y: {z: "abc"}}
db.fetch("x") // {y: {z: "abc"}}
db.all() // {x: {y: {z: "abc"}}}

db.push("a", "hello") //  ["hello"]
db.push("a", "world") //  ["hello", "world"]
db.unpush("a", "hello") // ["world"]

db.push("b", {test: "erenaydb"}) // [{test: "erenaydb"}]
db.push("b", {test2: "erenaydb2"}) // [{test: "erenaydb"}, {test2: "erenaydb2"}]
db.delByPriority("b", 1) // [{test2: "erenaydb"}]
db.setByPriority("b", {newtest:"hey this is edited"}, 1) // [{newtest:"hey this is edited"}]

db.has("x") // true
db.delete("x") // true
db.deleteAll() // true

MySQL Support(BETA) (If you find any bugs/issues join my Discord)

const db = require("erenaydb");

db.setAdapter("mysql", {
  host: "localhost",
  port: "3306",
  user: "root",
  password: "password",
  database: "erenaydb_test"
});
db.connect().then(async() => {
  try {
    await db.add("x", 1);
    await db.add("y", 2);
    await db.add("z", 3);
    const result = await db.all();
    console.log(result);
    
    // Example custom SQL usage
    const customResult = await erenaydb.customSQL("SELECT * FROM ErenayDB WHERE id = ?", ["y"]);
    console.log(customResult);
  } catch (error) {
    console.error("Error while performing database operations:", error);
  }

  await erenaydb.disconnect();
});

RethinkDB Supporting!

const db = require("erenaydb")
db.setAdapter("rethink", 
{
    host: "localhost",
    port: 28015,
    db: "ErenayDB_Test",
    schema: "Schema Name" // Not required. You can define your own schema. Just name.
})

await db.set("x.y.z", "abc") // abc

await db.get("x") // {y: {z: "abc"}}
await db.fetch("x") // {y: {z: "abc"}}
await db.all().then((result) => console.log(result))  // {x: {y: {z: "abc"}}}

await db.push("a", "hello") //  ["hello"]
await db.push("a", "world") //  ["hello", "world"]
await db.unpush("a", "hello") // ["world"]

await db.push("b", {test: "erenaydb"}) // [{test: "erenaydb"}]
await db.push("b", {test2: "erenaydb2"}) // [{test: "erenaydb"}, {test2: "erenaydb2"}]
await db.delByPriority("b", 1) // [{test2: "erenaydb"}]
await db.setByPriority("b", {newtest:"hey this is edited"}, 1) // [{newtest:"hey this is edited"}]

await db.has("x") // true
await db.delete("x") // true
await db.deleteAll() // true

MongoDb! (If you find any bugs/issues join my Discord)

const db = require("erenaydb")
db.setAdapter("mongo", 
{
    url: "Your Mongo URL", 
    schema: "Schema Name" // Not required. You can define your own schema. Just name.
})

await db.set("x.y.z", "abc") // abc

await db.get("x") // {y: {z: "abc"}}
await db.fetch("x") // {y: {z: "abc"}}
await db.all() // {x: {y: {z: "abc"}}}

await db.push("a", "hello") //  ["hello"]
await db.push("a", "world") //  ["hello", "world"]
await db.unpush("a", "hello") // ["world"]

await db.push("b", {test: "erenaydb"}) // [{test: "erenaydb"}]
await db.push("b", {test2: "erenaydb2"}) // [{test: "erenaydb"}, {test2: "erenaydb2"}]
await db.delByPriority("b", 1) // [{test2: "erenaydb"}]
await db.setByPriority("b", {newtest:"hey this is edited"}, 1) // [{newtest:"hey this is edited"}]

await db.has("x") // true
await db.delete("x") // true
await db.deleteAll() // true

Example With Options

const db = require("erenaydb")
db.setReadable(true) // It makes readable your JSON DB file.
db.noBlankData(true) // If you delete anything from object and new object size is less than 1, automaticly removes that object.
db.setAdapter("yamldb") // It makes adapter as YAML adapter. Default adapter is JsonDB
db.setFolder("folder") // You can set database folder name
db.setFile("db") // You can set database file name
db.setCheckUpdates(true) // It warns you if any updates happens.

db.set("x.y.z", "abc") // abc

db.get("x") // {y: {z: "abc"}}
db.fetch("x") // {y: {z: "abc"}}
db.all() // {x: {y: {z: "abc"}}}

db.push("a", "hello") //  ["hello"]
db.push("a", "world") //  ["hello", "world"]
db.unpush("a", "hello") // ["world"]

db.push("b", {test: "erenaydb"}) // [{test: "erenaydb"}]
db.push("b", {test2: "erenaydb2"}) // [{test: "erenaydb"}, {test2: "erenaydb2"}]
db.delByPriority("b", 1) // [{test2: "erenaydb"}]
db.setByPriority("b", {newtest:"hey this is edited"}, 1) // [{newtest:"hey this is edited"}]

db.has("x") // true
db.delete("x") // true
db.deleteAll() // true

If you've any question, you can join to my Discord server: Click me!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.