1.2.3 • Published 11 months ago

@esosdb/utils v1.2.3

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

@esosdb/utils

Description

Utils for esosdb

Do you want more details? Check Docs

Contents

Badges

NPM Downloads

Install

npm i @esosdb/utils

Setup

CommonJS

const { Database } = require("esosdb");
const { Schema, connect } = require("@esosdb/utils");
const db = new Database({
  path: "./esosdb/db.json", // this is default, can write the what you want
  space: 2, //shold be a number (default:0)
});
connect(db);
const { User } = require("./schemas/UserSchema.js"); //You must be import after connect() function

EsModule

import { Database } from "esosdb";
import { Schema, connect } from "@esosdb/utils";
const db = new Database({
  path: "./esosdb/db.json", // this is default, can write the what you want
  space: 2, //shold be a number (default:0)
});
connect(db);
import { User } from "./schemas/UserSchema.js"; //You must be import after connect() function

Examples

  • First example - create a schema
// ./schemas/UserSchema.js
let userProps = {
  name: { type: "string", required: true },
  age: { type: "number", required: true },
  //types are string|number|boolean|object|any[]|string[]|number[]
};

let User = new Schema("user", userProps, true);

module.exports = { User };

create

User.create(value,callback)

User.create({ name: "esos", age: 1 }, (cb) => {
  console.log(cb); //return {id:"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",name:"esos",age:1,updatedAt:1970-01-01T01:00:00.000Z,createdAt:1970-01-01T01:00:00.000Z}
});

findById

User.findById(id,callback)

User.findById(
  "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" /* it's created by automatically, you can create as manually, just add to Schema*/,
  (cb) => {
    console.log(cb); //return {id:"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",name:"esos",age:1,updatedAt:1970-01-01T01:00:00.000Z,createdAt:1970-01-01T01:00:00.000Z}
  }
);

findByElement

User.findByElement(element,callback)

User.findByElement({ name: "esos" }, (cb) => {
  console.log(cb); //return [{id:"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",name:"esos",age:1,updatedAt:1970-01-01T01:00:00.000Z,createdAt:1970-01-01T01:00:00.000Z}]
});

updateById

User.updateById(id,new values,callback)

User.updateById(
  "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  {
    name: "esosdb",
    age: 2,
  },
  (cb) => {
    console.log(cb); //return {id:"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",name:"esosdb",age:2,updatedAt:1970-01-01T01:00:00.000Z,createdAt:1970-01-01T01:00:00.000Z}
  }
);

deleteById

User.deleteById(id,callback)

User.deleteById("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", (cb) => {
  console.log(cb); //return true
});

esosdb

1.2.3

11 months ago

1.2.2

11 months ago

1.2.12

12 months ago

1.2.11

12 months ago

1.2.1

12 months ago

1.2.0

12 months ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago