flex-db v3.0.2
flex-db version (3.0.2) documentation
a powerful, flexible and easy to use JSON database built just for node.js πͺ
npm i flex-db
why flex-db?
β’ πfast. β’ fully Synchronous functions & Asynchronous scripting with callbacks. β’ simple to learn and use π. β’ with flex-db you can store your files locally on your server or remotly .
example
const flexDb = require("flex-db")
let database = flexDb("database")
database.user = {
username:{
type:"string",
require:true,
},
email:{
type:"string",
require:true,
unique:true,
match:/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/},
}
const users = database().user
users.makeOne({
username:"jhon",
email:"jhon@example.com"
},(result)=>{
console.log(result)
})
database().getAll((result)=>{
console.log(result)
})
output
{ success: 'item made' }
{
users:[
{
username: 'jhon',
email: 'jhon@example.com',
id: 'dzVW4zOykzxaJNkAD7cQbOFNvG5D3jQctBWbjSwdUA2WnRvC8WbhRvgOIlB5ChKOKdE0CuYrzYb',
update: [Function], // only avadible localy
delete: [Function], // only avadible localy
}
]
}
flex-db santax { }
starting a database
const flexDb = require("flex-db")
// set base path
let databaseSchema = flexDb("path of database files")
making database objects
flex-db object configuration list :
databaseSchema.users = {
subItem:{
unique:true, // means it wont make duplicates in this subItem if true
require:true, // wont make an item without subItem if true
type:"string",//type is object type, types are "object"(for JSON) "string" (for normal string) "number" (for numbers)
defualt:"test",// defualt will set item automaticly if require also true
minSize:10,// if number number must be 10, if string or object subItem.length must be <= 10,
maxSize:10,// if number number must be 10, if string or object subItem.length must be >= 10,
size:10,// if number number must be 10, if string or object subItem.length must be 10,
match:/test/, // for strings, same as subItem.match(/test/)
lowerCase:true, // for strings, automaticly makes all subItems lowerCase if true
upperCase:false, // for strings, automaticly makes all subItems upperCase if true
}
}
for a fully open storage object you can just do
databaseSchema.users = true
you can also have a sub database object that is open
databaseSchema.users = {
name:true,
surname:true,
}
using a database
let database = databaseSchema()
database.users.makeOne({username:"JHON"})
console.log(database.users.getAll())
flex-db tools π¨
object tools list
β’ getAll (gets all objects across a database)β’ makeOne (for making objects inside a database)β’ updateOne (for updating objects inside a database)β’ upadteMult (for updating multiple objects across a database)β’ updateAll (for updating all objects across a database)β’ updateById (updates items in database by id)β’ deleteOne (for deleting objects across database)β’ deleteById (for deleteing object s by there id)β’ deleteMult (for deleting objects across a database)β’ deleteAll (for deleting all objects across a database)β’ findOne (for making objects across a database)β’ find (for finding an array of objects across a database)β’ findById (for finding object's by id)β’ searchOne (used to search for one object in a database or database object)β’ search (used to search for an array of objects in database or database object)β’ searchById (for searching objects across a database by id)
network tools list
β’ connect (for connecting to a database) β’ listen (for making database objects remotely available) β’ router (for making objects in a database work inside express server)
database tool list
β’ join (for joining flex-db database objects and databases) β’ slice (for slicing flex-db database objects)
PLEASE NOTE!!!flex-db functions are synchronouse, if you are using a non remote sub object await is not required for a return, if the object is joined or remote, await is required for a return, otherwise you can just use a callback function for more asynchronouse scripting.
flex-db object tools usage βοΈ
β’ all databases are joined by defualt. β’ flexdb.join only works with flexdb databases and sub objects. β’ please note! once objects are joined they are async functions that require await.
getAll
let items = database.subObject.getAll()
for(let item in items){
console.log(items[item])
}
all flexDb functions have a callback function so you can also use
database.subObject.getAll((items)=>{
for(let item in items){
console.log(items[item])
}
})
if you wish to getAll in an entire database you'd use something like this
let items = await database.getAll() // becuase it is a joined object
for(let item in items.subItem){
console.log(items[item])
}
items will return like this if you getAll in joined database
{subObject:[sub object data array]}
if you use a sub object your data will simply return a array
if you are using getAll for a joined object like this
const flexDb = require("flex-db")
let db1 = flexDb("db1")
db1.sub1 = true
db1.sub2 = true
let db2 = flexDb("db2")
db2.sub1 = true
db2.sub2 = true
let database = flexDb.join({
db1:db1(),
db2:db2()
})
database.getAll((result)=>{
console.log(result)
})
your output will be
{
db1: { sub1: [ [Object], [Object] ], sub2: [ [Object], [Object] ] },
db2: { sub1: [ [Object], [Object] ], sub2: [ [Object], [Object] ] }
}
makeOne +
let result = database.subObject.makeOne({
//NEW DATA HERE
})
all flexDb functions have a callback function so you can also use
database.subObject.makeOne({
//NEW DATA HERE
// you can not use id, as all objects have a unique id assigned automaticly
},(result)=>{
console.log(result)
})
result will return with error or success inside a JSON oject
{success:"item made"}
or
{error:"error message"}
handeling response message
if(result.success){
// item made
}else if(result.error){
// error
}
if you are using makeOne for a joined object like this
const flexDb = require("flex-db")
let db1 = flexDb("db1")
db1.sub1 = true
db1.sub2 = true
let db2 = flexDb("db2")
db2.sub1 = true
db2.sub2 = true
let database = flexDb.join({
db1:db1(),
db2:db2()
})
database.makeOne({randomdata:"blahblah"},(result)=>{
console.log(result)
})
your output will be
{
db1: { sub1: { success: 'item made' }, sub2: { success: 'item made' } },
db2: { sub1: { success: 'item made' }, sub2: { success: 'item made' } }
}
updateOne π
let result = database.subObject.updateOne({/*find data*/},{/*new data*/})
all flexDb functions have a callback function so you can also use
database.subObject.updateOne({/*find data*/},{/*new data*/},(result)=>{
console.log(result)
})
result will return a object with success or error
{
success:"item updated"
},
or if no object or error result will return
{
error:"error message"
},
if you are using updateOne for a joined object like this
const flexDb = require("flex-db")
let db1 = flexDb("db1")
db1.sub1 = true
db1.sub2 = true
let db2 = flexDb("db2")
db2.sub1 = true
db2.sub2 = true
let database = flexDb.join({
db1:db1(),
db2:db2()
})
database.updateOne({randomdata:"blahblah"},{randomdata:"test"},(result)=>{
console.log(result)
})
your output will be something like this
{
db1: { sub1:[Object], sub2: [Object] },
db2: { sub1: [Object], sub2: [Object] }
}
updateMult π
let result = database.subObject.updateMult({/*find data*/},{/*new data*/})
all flexDb functions have a callback function so you can also use
database.subObject.updateMult({/*find data*/},{/*new data*/},(result)=>{
console.log(result)
})
result will return a array
[
{
success:"item updated"
},
{
error:"item updated"
},
]
if you are using updateMult for a joined object like this
const flexDb = require("flex-db")
let db1 = flexDb("db1")
db1.sub1 = true
db1.sub2 = true
let db2 = flexDb("db2")
db2.sub1 = true
db2.sub2 = true
let database = flexDb.join({
db1:db1(),
db2:db2()
})
database.updateMult({randomdata:"blahblah"},{randomdata:"blublu"},(result)=>{
console.log(result)
})
your output will be something like this
{
db1: { sub1: [ [Object], [Object] ], sub2: [ [Object], [Object] ] },
db2: { sub1: [], sub2: [] }
}
updateAll π
let result = database.subObject.updateAll({/*new data*/})
all flexDb functions have a callback function so you can also use
database.subObject.updateAll({
/*new data*/
},(result)=>{
console.log(result)
})
result will return a array
[
{
success:"item updated"
},
{
error:"error message"
},
]
if you are using updateAll for a joined object like this
const flexDb = require("flex-db")
let db1 = flexDb("db1")
db1.sub1 = true
db1.sub2 = true
let db2 = flexDb("db2")
db2.sub1 = true
db2.sub2 = true
let database = flexDb.join({
db1:db1(),
db2:db2()
})
database.updateAll({randomdata:"blahblah"},(result)=>{
console.log(result)
})
your output will be something like this
{
db1: { sub1: [ [Object], [Object] ], sub2: [ [Object], [Object] ] },
db2: { sub1: [[Object], [Object] ], sub2: [[Object], [Object] ] }
}
updateById π
let result = database.subObject.updateById("id of object",{ /*new data*/ })
all flexDb functions have a callback function so you can also use
database.subObject.updateById("id of object",{ /*new data*/ },(result)=>{
console.log(result)
})
result will return a object with success or error
{
success:"item updated"
},
or if no object or error result will return
{
error:"error message"
},
if you are using updateById for a joined object like this
const flexDb = require("flex-db")
let db1 = flexDb("db1")
db1.sub1 = true
db1.sub2 = true
let db2 = flexDb("db2")
db2.sub1 = true
db2.sub2 = true
let database = flexDb.join({
db1:db1(),
db2:db2()
})
database.updateById("id of object",{ /*new data*/ },(result)=>{
console.log(result)
})
your output will be something like this
{
db1: { sub1:[Object] , sub2: [Object] },
db2: { sub1:[Object] , sub2: [Object] }
}
deleteOne β
let result = database.subObject.deleteOne({/*findOne data*/})
all flexDb functions have a callback function so you can also use
database.subObject.deleteOne({/*findOne data*/},(result)=>{
console.log(result)
})
{
success:"item removed"
},
or if no object or error result will return
{
error:"error message"
},
if you are using deleteOne for a joined object like this
const flexDb = require("flex-db")
let db1 = flexDb("db1")
db1.sub1 = true
db1.sub2 = true
let db2 = flexDb("db2")
db2.sub1 = true
db2.sub2 = true
let database = flexDb.join({
db1:db1(),
db2:db2()
})
database.deleteOne({randomdata:"blahblah"},(result)=>{
console.log(result)
})
your output will be something like this
{
db1: { sub1:[Object], sub2: [Object] },
db2: { sub1: undefined, sub2: undefined }
}
deleteMult β
let result = database.subObject.deleteMult({/*find data*/})
all flexDb functions have a callback function so you can also use
database.subObject.deleteMult({/*find data*/},(result)=>{
console.log(result)
})
result will return a array
[
{
success:"item removed"
},
{
success:"item removed"
},
]
if you are using find for a joined object like this
const flexDb = require("flex-db")
let db1 = flexDb("db1")
db1.sub1 = true
db1.sub2 = true
let db2 = flexDb("db2")
db2.sub1 = true
db2.sub2 = true
let database = flexDb.join({
db1:db1(),
db2:db2()
})
database.deleteMult({randomdata:"blahblah"},(result)=>{
console.log(result)
})
your output will be something like this
{
db1: { sub1: [ [Object], [Object] ], sub2: [ [Object], [Object] ] },
db2: { sub1: [ [Object], [Object] ], sub2: [ [Object], [Object] ] },
}
deleteAll β
let result = database.subObject.deleteAll()
all flexDb functions have a callback function so you can also use
database.subObject.deleteAll((result)=>{
console.log(result)
})
result will return a object
[
{
success:"item removed"
},
{
success:"item removed"
},
]
if you are using deleteAll for a joined object like this
const flexDb = require("flex-db")
let db1 = flexDb("db1")
db1.sub1 = true
db1.sub2 = true
let db2 = flexDb("db2")
db2.sub1 = true
db2.sub2 = true
let database = flexDb.join({
db1:db1(),
db2:db2()
})
database.deleteAll((result)=>{
console.log(result)
})
your output will be something like this
{
db1: { sub1: [Object], sub2: [Object] },
db2: { sub1: [Object], sub2: [Object] }
}
deleteById β
let result = database.subObject.deleteById("id of object")
all flexDb functions have a callback function so you can also use
database.subObject.deleteById("id of object",(result)=>{
console.log(result)
})
result will return a object
{
success:"item removed"
},
or if no object or error result will return
{
error:"error message"
},
if you are using deleteById for a joined object like this
const flexDb = require("flex-db")
let db1 = flexDb("db1")
db1.sub1 = true
db1.sub2 = true
let db2 = flexDb("db2")
db2.sub1 = true
db2.sub2 = true
let database = flexDb.join({
db1:db1(),
db2:db2()
})
database.deleteById("id of object",(result)=>{
console.log(result)
})
your output will be something like this
{
db1: { sub1: [Object], sub2: [Object] },
db2: { sub1: [Object], sub2: [Object] }
}
findOne π
let result = database.subObject.findOne({/*data*/})
all flexDb functions have a callback function so you can also use
database.subObject.findOne({
/*data*/
},(result)=>{
console.log(result)
})
result will return a object
{
/object data/
},
or if no result result will return undefined
undefined
if you are using findOne for a joined object like this
const flexDb = require("flex-db")
let db1 = flexDb("db1")
db1.sub1 = true
db1.sub2 = true
let db2 = flexDb("db2")
db2.sub1 = true
db2.sub2 = true
let database = flexDb.join({
db1:db1(),
db2:db2()
})
database.findOne({randomdata:"blahblah"},(result)=>{
console.log(result)
})
your output will be something like this
{
db1: { sub1:[Object], sub2: [Object] },
db2: { sub1: undefined, sub2: undefined }
}
find π
let result = database.subObject.find({/*data*/})
all flexDb functions have a callback function so you can also use
database.subObject.find({
/*data*/
},(result)=>{
console.log(result)
})
result will return a array
[
{
/object data/
},
]
or
[]
if you are using find for a joined object like this
const flexDb = require("flex-db")
let db1 = flexDb("db1")
db1.sub1 = true
db1.sub2 = true
let db2 = flexDb("db2")
db2.sub1 = true
db2.sub2 = true
let database = flexDb.join({
db1:db1(),
db2:db2()
})
database.find({randomdata:"blahblah"},(result)=>{
console.log(result)
})
your output will be something like this
{
db1: { sub1: [ [Object], [Object] ], sub2: [ [Object], [Object] ] },
db2: { sub1: [], sub2: [] }
}
findById π
let result = database.subObject.findById("id of object")
all flexDb functions have a callback function so you can also use
database.subObject.findById("id of object",(result)=>{
console.log(result)
})
result will return a object
{
/object data/
},
or if no result result will return undefined
undefined
if you are using findById for a joined object like this
const flexDb = require("flex-db")
let db1 = flexDb("db1")
db1.sub1 = true
db1.sub2 = true
let db2 = flexDb("db2")
db2.sub1 = true
db2.sub2 = true
let database = flexDb.join({
db1:db1(),
db2:db2()
})
database.findById("id of object",(result)=>{
console.log(result)
})
your output will be something like this
{
db1: { sub1:undefined, sub2: [Object] },
db2: { sub1: undefined, sub2: undefined }
}
searchOne π
let result = database.subObject.searchOne({/*data*/})
all flexDb functions have a callback function so you can also use
database.subObject.searchOne({
/*data*/
},(result)=>{
console.log(result)
})
result will return a object
{
/object data/
},
or if no result result will return undefined
undefined
if you are using searchOne for a joined object like this
const flexDb = require("flex-db")
let db1 = flexDb("db1")
db1.sub1 = true
db1.sub2 = true
let db2 = flexDb("db2")
db2.sub1 = true
db2.sub2 = true
let database = flexDb.join({
db1:db1(),
db2:db2()
})
database.searchOne({randomdata:"blA"},(result)=>{
console.log(result)
})
your output will be something like this
{
db1: { sub1:[Object], sub2: [Object] },
db2: { sub1: undefined, sub2: undefined }
}
search π
let result = database.subObject.search({/*data*/})
all flexDb functions have a callback function so you can also use
database.subObject.search({
/*data*/
},(result)=>{
console.log(result)
})
result will return a array
[
{
/object data/
},
]
or
[]
if you are using search for a joined object like this
const flexDb = require("flex-db")
let db1 = flexDb("db1")
db1.sub1 = true
db1.sub2 = true
let db2 = flexDb("db2")
db2.sub1 = true
db2.sub2 = true
let database = flexDb.join({
db1:db1(),
db2:db2()
})
database.search({randomdata:"bla"},(result)=>{
console.log(result)
})
your output will be something like this
{
db1: { sub1: [ [Object], [Object] ], sub2: [ [Object], [Object] ] },
db2: { sub1: [], sub2: [] }
}
searchById π
let result = database.subObject.searchById("id of object")
all flexDb functions have a callback function so you can also use
database.subObject.searchById("id of object",(result)=>{
console.log(result)
})
result will return a object
{
/object data/
},
or if no result result will return undefined
undefined
if you are using searchById for a joined object like this
const flexDb = require("flex-db")
let db1 = flexDb("db1")
db1.sub1 = true
db1.sub2 = true
let db2 = flexDb("db2")
db2.sub1 = true
db2.sub2 = true
let database = flexDb.join({
db1:db1(),
db2:db2()
})
database.searchById("id of object",(result)=>{
console.log(result)
})
your output will be something like this
{
db1: { sub1:undefined, sub2: [Object] },
db2: { sub1: undefined, sub2: undefined }
}
flex-db network tools usage α―€
β’ all databases are joined by defualt. β’ flexdb.join only works with flexdb databases and sub objects. β’ please note! once objects are joined they are async functions that require await.
listen α―€
β’ all database objects, even remote ones can be used as remote servers for flex-db connect. β’ server is built with express. β’ please note! once objects are joined or remote they are async functions that require await.
to use listen you must first make a database object
const flexDB = require("flex-db")
const database = flexDb("my database")
database.openDB = true
you can use listen on both joined objects and sub objects
database().listen(8080)
database().openDB.listen(8080)
listen santax α―€ { }
flex-db listen can be used in multiple ways
let server = database().listen(/*port*/,/*config*/,/*server callback function*/)
let server = database().listen(/*port*/,/*server callback function*/)
let server = database().listen(/*config port must now be in config*/,/*server callback function*/)
listen config options
https
https is used to encrypt database
database().listen(8080,{
https:{
key:"path to key file",
cert:"path to cert file"
}
})
key
a key is used as a password to the server functions
database().listen(8080,{
key:"P@$$W0RD"
})
whiteList
the whiteList option blocks all ip addresses that are not on the list
database().listen(8080,{
whiteList:[
"172.0.0.1",
]
})
blackList
a blackList is used to block ip addresses
database().listen(8080,{
blackList:[
"8.8.8.8"
]
})
port
port sets the server port number
database().listen({
port:8080
})
router α―€
β’ router can be used to embed a database listen on a express app, santax same as listen,config same as listen. β’ please note! remote functions are async functions that require await.
example
//make express app
const express = require("express")
const app = express()
// make flex-db database
const flexDb = require("flex-db")
let database = flexDb("database")
database.test = true
database.test2 = true
let db = database()
// to include make flex-db.js avadible on your server :
app.get("/flex-db.js",flexDb.browserScript)
// make some client side scripting
app.get("/",(req,res)=>{res.send(`
<script src="/flex-db.js"></script>
<script>
flexDb.connect("localhost:8080/database",async(db)=>{
console.log(await db.makeOne({name:"jhon"}))
console.log(await db.getAll())
console.log(await db.deleteMult({name:"jhon"}))
})
</script>
`)})
// use db.router to embed database intoo server
app.use("/database",db.router({whiteList:["127.0.0.1"]}))
// start app
app.listen(8080)
connect α―€
β’ connect is used to connect to a flex-db database that is listening. β’ please note! remote functions are async functions that require await.
flexDb.connect(url,{key:"server key"},async(database)=>{
console.log(await database.getAll())
})
connect santax α―€ { }
let flexDb = reqiure("flex-db")
flex-db connect can be used in multiple ways
let database = await flexDb.connect(/*url*/,/*config*/,/*server callback function*/)
let database = await flexDb.connect(/*url*/,/*server callback function*/)
using flex-db connect with web browser example
//make express app
const express = require("express")
const app = express()
// make flex-db database server
const flexDb = require("flex-db")
let database = flexDb("database")
database.test = true
database.test2 = true
let db = database()
db.listen(8081)
// to include make flex-db.js avadible on your server :
// make some client side scripting
app.get("/",(req,res)=>{res.send(`
<script src="/flex-db.js"></script>
<script>
flexDb.connect("http://localhost:8081/",async(db)=>{
console.log(await db.makeOne({name:"jhon"}))
console.log(await db.getAll())
console.log(await db.deleteMult({name:"jhon"}))
})
</script>
`)})
// start app
app.listen(8080)
remote databases can be joined with normal databases using flex-db join
flex-db database building tools ποΈ
β’ all databases are joined by defualt. β’ flexdb.join only works with flexdb databases and sub objects. β’ please note! once objects are joined they are async functions that require await.
join π
β’ all databases are joined by defualt. β’ flexdb.join only works with flexdb databases and sub objects. β’ please note! once objects are joined they are async functions that require await.
first, make a database
const flexDb = require("flex-db")
const databaseScema1 = flexDb("database1")
databaseScema1.bikes=true
let database1 = databaseScema1()
now make a second database
const databaseScema2 = flexDb("database2")
databaseScema2.cars=true
let database2 = databaseScema2()
now we are going to join the 2 databases so that we can use them at the same time
let joinedDB = flexDb.join({
db1:database,
db2:database2,
})
you can now do things like
console.log(await joinedDB.findOne({model:"Mazda"}))
console.log(await joinedDB.getAll())
flex-db join can also be used for just sub objects
let carsAndUsers = flexDb.join({
cars:database2.cars,
users:database1.users
})
carsAndUsers.search({username:"J"},(results)=>{
console.log(results)
})
slice π
flex-db slice can cut a item out of a database object
let databaseNoUsers = flexDb.slice(database,"users")
flex-db database structure examples
example 1
input
const flexDb = require("flex-db")
const database = flexDb("database")
database.openDB1 = true
database.openDB2 = true;
database.openDB3 = true;
database.openDB4 = true;
console.log(database())
output
{
'joined flex-db object': true,
makeOne: [AsyncFunction: makeOne],
updateOne: [AsyncFunction: updateOne],
updateMult: [AsyncFunction: updateMult],
updateAll: [AsyncFunction: updateAll],
updateById: [AsyncFunction: updateById],
deleteOne: [AsyncFunction: deleteOne],
deleteById: [AsyncFunction: deleteById],
deleteMult: [AsyncFunction: deleteMult],
deleteAll: [AsyncFunction: deleteAll],
findOne: [AsyncFunction: findOne],
find: [AsyncFunction: find],
findById: [AsyncFunction: findById],
searchOne: [AsyncFunction: searchOne],
search: [AsyncFunction: search],
searchById: [AsyncFunction: searchById],
getAll: [AsyncFunction: getAll],
listen: [Function],
openDB1: {
'basic flex-db object': true,
makeOne: [Function: makeOne],
updateOne: [Function: updateOne],
updateById: [Function: updateById],
updateMult: [Function: updateMult],
updateAll: [Function: updateAll],
getAll: [Function: getAll],
find: [Function: find],
findById: [Function: findById],
findOne: [Function: findOne],
search: [Function: search],
searchById: [Function: searchById],
searchOne: [Function: searchOne],
deleteById: [Function: deleteById],
deleteOne: [Function: deleteOne],
deleteMult: [Function: deleteMult],
deleteAll: [Function: deleteAll],
listen: [Function]
},
openDB2: {
'basic flex-db object': true,
makeOne: [Function: makeOne],
updateOne: [Function: updateOne],
updateById: [Function: updateById],
updateMult: [Function: updateMult],
updateAll: [Function: updateAll],
getAll: [Function: getAll],
find: [Function: find],
findById: [Function: findById],
findOne: [Function: findOne],
search: [Function: search],
searchById: [Function: searchById],
searchOne: [Function: searchOne],
deleteById: [Function: deleteById],
deleteOne: [Function: deleteOne],
deleteMult: [Function: deleteMult],
deleteAll: [Function: deleteAll],
listen: [Function]
},
openDB3: {
'basic flex-db object': true,
makeOne: [Function: makeOne],
updateOne: [Function: updateOne],
updateById: [Function: updateById],
updateMult: [Function: updateMult],
updateAll: [Function: updateAll],
getAll: [Function: getAll],
find: [Function: find],
findById: [Function: findById],
findOne: [Function: findOne],
search: [Function: search],
searchById: [Function: searchById],
searchOne: [Function: searchOne],
deleteById: [Function: deleteById],
deleteOne: [Function: deleteOne],
deleteMult: [Function: deleteMult],
deleteAll: [Function: deleteAll],
listen: [Function]
},
openDB4: {
'basic flex-db object': true,
makeOne: [Function: makeOne],
updateOne: [Function: updateOne],
updateById: [Function: updateById],
updateMult: [Function: updateMult],
updateAll: [Function: updateAll],
getAll: [Function: getAll],
find: [Function: find],
findById: [Function: findById],
findOne: [Function: findOne],
search: [Function: search],
searchById: [Function: searchById],
searchOne: [Function: searchOne],
deleteById: [Function: deleteById],
deleteOne: [Function: deleteOne],
deleteMult: [Function: deleteMult],
deleteAll: [Function: deleteAll],
listen: [Function]
}
}
example 2
input
const flexDb = require("flex-db")
const database = flexDb("database")
database.openDB1 = true
database.openDB2 = true;
const database2 = flexDb("database2")
database2.openDB1 = true
database2.openDB2 = true;
let joined_database = flexDb.join({
database:database(),
database2:database2()
})
console.log(joined_database)
output
{
'joined flex-db object': true,
makeOne: [AsyncFunction: makeOne],
updateOne: [AsyncFunction: updateOne],
updateMult: [AsyncFunction: updateMult],
updateAll: [AsyncFunction: updateAll],
updateById: [AsyncFunction: updateById],
deleteOne: [AsyncFunction: deleteOne],
deleteById: [AsyncFunction: deleteById],
deleteMult: [AsyncFunction: deleteMult],
deleteAll: [AsyncFunction: deleteAll],
findOne: [AsyncFunction: findOne],
find: [AsyncFunction: find],
findById: [AsyncFunction: findById],
searchOne: [AsyncFunction: searchOne],
search: [AsyncFunction: search],
searchById: [AsyncFunction: searchById],
getAll: [AsyncFunction: getAll],
listen: [Function],
database: {
'joined flex-db object': true,
makeOne: [AsyncFunction: makeOne],
updateOne: [AsyncFunction: updateOne],
updateMult: [AsyncFunction: updateMult],
updateAll: [AsyncFunction: updateAll],
updateById: [AsyncFunction: updateById],
deleteOne: [AsyncFunction: deleteOne],
deleteById: [AsyncFunction: deleteById],
deleteMult: [AsyncFunction: deleteMult],
deleteAll: [AsyncFunction: deleteAll],
findOne: [AsyncFunction: findOne],
find: [AsyncFunction: find],
findById: [AsyncFunction: findById],
searchOne: [AsyncFunction: searchOne],
search: [AsyncFunction: search],
searchById: [AsyncFunction: searchById],
getAll: [AsyncFunction: getAll],
listen: [Function],
openDB1: {
'basic flex-db object': true,
makeOne: [Function: makeOne],
updateOne: [Function: updateOne],
updateById: [Function: updateById],
updateMult: [Function: updateMult],
updateAll: [Function: updateAll],
getAll: [Function: getAll],
find: [Function: find],
findById: [Function: findById],
findOne: [Function: findOne],
search: [Function: search],
searchById: [Function: searchById],
searchOne: [Function: searchOne],
deleteById: [Function: deleteById],
deleteOne: [Function: deleteOne],
deleteMult: [Function: deleteMult],
deleteAll: [Function: deleteAll],
listen: [Function]
},
openDB2: {
'basic flex-db object': true,
makeOne: [Function: makeOne],
updateOne: [Function: updateOne],
updateById: [Function: updateById],
updateMult: [Function: updateMult],
updateAll: [Function: updateAll],
getAll: [Function: getAll],
find: [Function: find],
findById: [Function: findById],
findOne: [Function: findOne],
search: [Function: search],
searchById: [Function: searchById],
searchOne: [Function: searchOne],
deleteById: [Function: deleteById],
deleteOne: [Function: deleteOne],
deleteMult: [Function: deleteMult],
deleteAll: [Function: deleteAll],
listen: [Function]
}
},
database2: {
'joined flex-db object': true,
makeOne: [AsyncFunction: makeOne],
updateOne: [AsyncFunction: updateOne],
updateMult: [AsyncFunction: updateMult],
updateAll: [AsyncFunction: updateAll],
updateById: [AsyncFunction: updateById],
deleteOne: [AsyncFunction: deleteOne],
deleteById: [AsyncFunction: deleteById],
deleteMult: [AsyncFunction: deleteMult],
deleteAll: [AsyncFunction: deleteAll],
findOne: [AsyncFunction: findOne],
find: [AsyncFunction: find],
findById: [AsyncFunction: findById],
searchOne: [AsyncFunction: searchOne],
search: [AsyncFunction: search],
searchById: [AsyncFunction: searchById],
getAll: [AsyncFunction: getAll],
listen: [Function],
openDB1: {
'basic flex-db object': true,
makeOne: [Function: makeOne],
updateOne: [Function: updateOne],
updateById: [Function: updateById],
updateMult: [Function: updateMult],
updateAll: [Function: updateAll],
getAll: [Function: getAll],
find: [Function: find],
findById: [Function: findById],
findOne: [Function: findOne],
search: [Function: search],
searchById: [Function: searchById],
searchOne: [Function: searchOne],
deleteById: [Function: deleteById],
deleteOne: [Function: deleteOne],
deleteMult: [Function: deleteMult],
deleteAll: [Function: deleteAll],
listen: [Function]
},
openDB2: {
'basic flex-db object': true,
makeOne: [Function: makeOne],
updateOne: [Function: updateOne],
updateById: [Function: updateById],
updateMult: [Function: updateMult],
updateAll: [Function: updateAll],
getAll: [Function: getAll],
find: [Function: find],
findById: [Function: findById],
findOne: [Function: findOne],
search: [Function: search],
searchById: [Function: searchById],
searchOne: [Function: searchOne],
deleteById: [Function: deleteById],
deleteOne: [Function: deleteOne],
deleteMult: [Function: deleteMult],
deleteAll: [Function: deleteAll],
listen: [Function]
}
}
}
flex-db examples
β’ making a normal database 1
const flexDb = require("flex-db")
const database = flexDb("database")
database.openDB1 = true
database.openDB2 = true;
let _db = database()
β’ joining local and remote databases
const flexDb = require("flex-db")
const database = flexDb("database")
database.openDB1 = true
database.openDB2 = true;
database.openDB3 = true;
database.openDB4 = true;
const database2 = flexDb("database2")
database2.openDB1 = true
database2.openDB2 = true;
database2.openDB3 = true;
database2.openDB4 = true;
let connection = database2().listen(8080)
let main = async function(){
let joined_database = flexDb.join({
database:database(),
database2:await flexDb.connect(8080)
})
console.log(await joined_database.makeOne({name:"jhon"}))
console.log(await joined_database.getAll())
console.log(await joined_database.updateMult({name:"jhon"},{name:"sam"}))
console.log(await joined_database.database.updateOne({name:"sam"},{name:"Samis"}))
console.log(await joined_database.getAll())
console.log(await joined_database.deleteMult({name:"sam"}))
console.log(await joined_database.getAll())
}()
expected output :
{
database: {
openDB1: { success: 'item made' },
openDB2: { success: 'item made' },
openDB3: { success: 'item made' },
openDB4: { success: 'item made' }
},
database2: {
openDB1: { success: 'item made' },
openDB2: { success: 'item made' },
openDB3: { success: 'item made' },
openDB4: { success: 'item made' }
}
}
{
database: {
openDB1: [ [Object] ],
openDB2: [ [Object] ],
openDB3: [ [Object] ],
openDB4: [ [Object] ]
},
database2: {
openDB1: [ [Object] ],
openDB2: [ [Object] ],
openDB3: [ [Object] ],
openDB4: [ [Object] ]
}
}
{
database: {
openDB1: [ [Object] ],
openDB2: [ [Object] ],
openDB3: [ [Object] ],
openDB4: [ [Object] ]
},
database2: {
openDB1: [ [Object] ],
openDB2: [ [Object] ],
openDB3: [ [Object] ],
openDB4: [ [Object] ]
}
}
{
openDB1: { success: 'item updated' },
openDB2: { success: 'item updated' },
openDB3: { success: 'item updated' },
openDB4: { success: 'item updated' }
}
{
database: {
openDB1: [ [Object] ],
openDB2: [ [Object] ],
openDB3: [ [Object] ],
openDB4: [ [Object] ]
},
database2: {
openDB1: [ [Object] ],
openDB2: [ [Object] ],
openDB3: [ [Object] ],
openDB4: [ [Object] ]
}
}
{
database: { openDB1: [], openDB2: [], openDB3: [], openDB4: [] },
database2: {
openDB1: [ [Object] ],
openDB2: [ [Object] ],
openDB3: [ [Object] ],
openDB4: [ [Object] ]
}
}
{
database: {
openDB1: [ [Object] ],
openDB2: [ [Object] ],
openDB3: [ [Object] ],
openDB4: [ [Object] ]
},
database2: { openDB1: [], openDB2: [], openDB3: [], openDB4: [] }
}
β’ joining databases
const flexDb = require("flex-db")
const database = flexDb("database")
database.openDB1 = true
database.openDB2 = true;
database.openDB3 = true;
database.openDB4 = true;
const database2 = flexDb("database2")
database2.openDB1 = true
database2.openDB2 = true;
database2.openDB3 = true;
database2.openDB4 = true;
let joined_database = flexDb.join({
database:database(),
database2:database2()
})
let main = async function(){
console.log(await joined_database.makeOne({name:"jhon"}))
console.log(await joined_database.getAll())
console.log(await joined_database.updateMult({name:"jhon"},{name:"sam"}))
console.log(await joined_database.database.updateOne({name:"sam"},{name:"Samis"}))
console.log(await joined_database.getAll())
console.log(await joined_database.deleteMult({name:"sam"}))
console.log(await joined_database.getAll())
}()
expected output :
{
database: {
openDB1: { success: 'item made' },
openDB2: { success: 'item made' },
openDB3: { success: 'item made' },
openDB4: { success: 'item made' }
},
database2: {
openDB1: { success: 'item made' },
openDB2: { success: 'item made' },
openDB3: { success: 'item made' },
openDB4: { success: 'item made' }
}
}
{
database: {
openDB1: [ [Object] ],
openDB2: [ [Object] ],
openDB3: [ [Object] ],
openDB4: [ [Object] ]
},
database2: {
openDB1: [ [Object] ],
openDB2: [ [Object] ],
openDB3: [ [Object] ],
openDB4: [ [Object] ]
}
}
{
database: {
openDB1: [ [Object] ],
openDB2: [ [Object] ],
openDB3: [ [Object] ],
openDB4: [ [Object] ]
},
database2: {
openDB1: [ [Object] ],
openDB2: [ [Object] ],
openDB3: [ [Object] ],
openDB4: [ [Object] ]
}
}
{
openDB1: { success: 'item updated' },
openDB2: { success: 'item updated' },
openDB3: { success: 'item updated' },
openDB4: { success: 'item updated' }
}
{
database: {
openDB1: [ [Object] ],
openDB2: [ [Object] ],
openDB3: [ [Object] ],
openDB4: [ [Object] ]
},
database2: {
openDB1: [ [Object] ],
openDB2: [ [Object] ],
openDB3: [ [Object] ],
openDB4: [ [Object] ]
}
}
{
database: { openDB1: [], openDB2: [], openDB3: [], openDB4: [] },
database2: {
openDB1: [ [Object] ],
openDB2: [ [Object] ],
openDB3: [ [Object] ],
openDB4: [ [Object] ]
}
}
{
database: {
openDB1: [ [Object] ],
openDB2: [ [Object] ],
openDB3: [ [Object] ],
openDB4: [ [Object] ]
},
database2: { openDB1: [], openDB2: [], openDB3: [], openDB4: [] }
}
future updates for flex-db 3.0.3
β’ web browser connect script
β’ mongoose to flex-db object
β’ flex-db console control
auther : Damian Mostert
email : damianmostert86@gmail.com
if you wish to contrubute to the project, share ideas for improvement, share problems and sulutions to my project, please feel free to send me a email π .
dependencies β’ express (for flex-db listen and flex-db router)
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago