1.1.6 • Published 6 years ago

xdatabase v1.1.6

Weekly downloads
2
License
ISC
Repository
github
Last release
6 years ago

XDB

X Database, nodeJS Database

Documentation

General

Database Setup

The database is a maluable object. It is located where defined by the setDB() function. Please use the setDB function before using any of the database's functions, exception will cause errors.

Database Structure

The database structure is as follows:

  • database name (defined with setDB)
    • template name
      • id.json (id of object of template) (contains object data)
      • id.json...
      • base.json (base data of template)
    • template name...
      • id.json (id of object of template) (contains object data)
      • id.json...
      • base.json (base data of template)

IDs

All IDs in XDB start at 0 in accordance to almost all languages. The ids increment by 1 every new object/template.

Object Data

All data stored in objects is stored under object.data, all returned objects by xdb functions will require .data 'ing to get their preset data. This is due to the requirement of important system data baeing stored seperatly under: _type, _id, etc....

Errors/Bugs

Please report any on this repository.

Setups

setDB ( dbLocation )

Default Argument: "./db"

Example: xdb.setDB("./mydb")

Return Value: none

Sets default database location. Required to use database, exception of function will case errors. Place this function after the require, or before any other database functions.

resetDB ( )

Return Value: true/false (success/failure)

Example: xdb.resetDB()

Resets and removes database, destroying directory. Use function with precaution and only as a fail safe. Operation is not reverseable and cannot be undone or recovered.

Templates

addTemplate ( name )

Return Value: none

Creates a template under (name). Does not delete existing template, however it may update the id. Generally speaking creating the same template twice is not a issue.

getTemplate ( name )

Return Value: false/template (failure/found)

Attempts to return object that is defined. If the object doesn't exist, it will return false.

getAllTemplates ( )

Return Value: array

Attempts to return all existing templates. If none it will return an empty array.

deleteTemplate ( name )

Return Value: true/false (success/failure)

Attempts to delete specified template (name). If the template doesn't exist it will return false.

Objects

addObject ( type, data )

Return Value: object/false (success/failure)

Example: xdb.addObject("car", {name: "jimmy", brand: "mercedes"})

Adds an object with the specified type and with the specified data.

getOBject ( type, data )

Return Value: object/false (found/failure)

Example: xdb.getObject("car", {brand: "porche", age: 3})

Checks through template and attempts to match data argument with existing objects.

InputActual DataOutput
{name: "bob}{name: "bob"}true (returns object)
{age: 3}{name: "bob", age: 3}true (returns object)
{name: "jimmy"}{name: "bob", age: 3}false (returns false)

The function will search through each object of the template until it finds a match and if not returns false.

getObjects ( type, data )

Return Value: Array

Example: xdb.getObjects("car", {brand: "porche", age: 3})

Checks through template and attempts to match data argument with existing objects, returns all that match.

InputActual DataOutput
{name: "bob}{name: "bob"}true (returns object)
{age: 3}{name: "bob", age: 3}true (returns object)
{name: "jimmy"}{name: "bob", age: 3}false (returns false)

The function will search through each object of the template until it finds all matches, and if not it returns an empty array.

getObjectByID ( type, id )

Return Value: object/false (found/failure)

Exmaple: xdb.getObjectByID("car", 0)

Return searched object or returns false on failure.

getAllObjects ( type )

Return Value: Array

Example: xdb.getAllObjects("car")

Returns all objects under template that is defined (type).

deleteObject ( type, data )

Return Value: true/false (success/failure)

Returns true or false dependent on whether the deletion was succsessful. The delete function will search for a matching item in the database, however the object still remains and can be called upon by its id. However its data will only contain {deleted: true}.

InputActual DataOutput
{name: "bob}{name: "bob"}true (deletes object)
{age: 3}{name: "bob", age: 3}true (deletes object)
{name: "jimmy"}{name: "bob", age: 3}false (goes to next object)

deleteObjects ( type, data )

Return Value: true/false (success/failure)

Returns true or false dependent on whether the deletion was succsessful. The delete function will remove all the items that match the specifed conditions, however the object still remains and can be called upon by its id. However its data will only contain {deleted: true}.

InputActual DataOutput
{name: "bob}{name: "bob"}true (deletes object)
{age: 3}{name: "bob", age: 3}true (deletes object)
{name: "jimmy"}{name: "bob", age: 3}false (goes to next object)

deleteObjectByID ( type, id )

Return Value: true/false (success/failure)

If an object is found with the specified ID it will be deleted. However the object still remains and can be called upon by its id. However its data will only contain {deleted: true}.

deleteAllObjects ( type )

Return Value: true/false (success/failure)

Deletes all objects of the specified template (type). However the objects still remain and can be called upon by their ids. However their data will only contain {deleted: true}.

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago