1.1.3 • Published 1 year ago

@kingbecats/evedb v1.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

EveDB

A Database using: Express, JSON files and Tables

  • ***Update: 1.1.1:
    • Fixed bug where path to save data doesn't create

Index

Install

It is simply the installation of the package, here it is shown with the bun installer, however with any package that has access to the npm API it is possible to install it.

bun add evedb

Server

Here there is nothing in general, just create a class for the server and initialize it, that's all, there is no need to do anything else.

//Example of index.ts

import { DatabaseServer } from "evedb";

const auth = "auth";

const server = new DatabaseServer({ port: 3000, path: "./src/Database", tables: "main", "test", auth, backup: { interval: 60 * 60000, report: true, }, });

server.start();

## Client
> _Here you create the main client to access the database wherever you are._
```ts
//Example of index.ts
import { DatabaseClient } from "evedb";

const auth = "auth";
const url = "localhost:3000/"

const client = new DatabaseClient(url, { auth });

Client Events

Here are all the events, is its name and the data you get, if it says Reference means that the data is what the function returns. Example:

client.on("error", (data) => {
   console.log(data);
/**
Logs:
{
  error: "Error message",
  code: 500,
}
*/
})

Client Methods

GetAll:

Description: This method retrieves all data from the database. It returns an object with the client

Has Event: Yes

Example:

await client.getAll()
/**
Returns: 
{
   client: [DatabaseClient];
   code: 200;
   url: "http://localhost:3000/";
   data: {
       tables: {
           "main": {...},
           "test": {...},
       };
       backups: {
           "1717978930687": {...}
       };
   };
}
*/

Go Back

GetTables:

Description: This method retrieves all tables in the database. It returns an object with the client

Has Event: Yes

Example:

await client.getTables()
/**
Returns: 
{
   client: [DatabaseClient];
   code: 200;
   url: "http://localhost:3000/";
   tables: [ "main", "test" ];
   data: {
       "main": {
           "foo": "bar"
       },
       "test": {
           "bar": "foo"
       },
   };
}
*/

Go Back

GetTable:

Description: This method retrieves all data from the given table. It returns an object with the name of the table and its contents.

Has Event: Yes

Example:

await client.getTable("main")
/**
Returns: 
{
   table: "main";
   data: {
       "foo": "bar";
   };
   success: true
}
*/

Go Back

DeleteTable:

Description: This method deletes all data in the given table. Returns an object with the name of the table and its empty contents.

Has Event: Yes

Example:

await client.deleteTable("main")
/**
Returns: 
{
   table: "main";
   data: { };
   success: true
}
*/

Go Back

GetBackups:

Description: This method retrieves all backups in the database. It returns an object with the client

Has Event: Yes

Example:

await client.getBackups()
/**
Returns: 
{
   client: [DatabaseClient];
   code: 200;
   url: "http://localhost:3000/";
   backups: [ "1717978930687" ];
   data: {
       "1717978930687": {
           "main": {
               "foo": "bar"
           },
           "test": {
               "bar": "foo"
           },
       }
   };
}
*/

Go Back

Backup:

Description: This method has several overloads. For this reason, each situation of use is described below

Has Event: Yes

Example List

Example Create:

await client.backup("create")
/**
Returns: 
{
   code: 200;
   message: "Backup was created successfully";
   id: "1717986166031";
   success: true
}
*/

Go to list

Example Get:

await client.backup("get", "1717986166031")
/**
Returns: 
{
   code: 200;
   id: "1717986166031";
   tables: {
       "main": {...},
       "test": {...}
   }
}
*/

await client.backup("get", "1717986166031", "main")
/**
Returns: 
{
   code: 200;
   id: "1717986166031";
   table: "main";
   data: {
       "foo": "bar"
   }
}
*/

Go to list

Example Restore:

In the second case, only one table is restored and not all of them.

await client.backup("restore", "1717986166031")
/**
Returns: 
{
   code: 200;
   message: "Restore from backup was successfully";
   success: true
}
*/

await client.backup("restore", "1717986166031", "main") /* Returns: { code: 200; message: "Restore from backup was successfully"; table: "main"; success: true } /

[Go to list](#example-list)
#### **Example Delete**:
> In the first case it deletes all backups, in the second only one, and in the third only one table from a single backup.
```ts 
await client.backup("delete")
/**
Returns: 
{
   code: 200;
   message: "All backups was deleted successfully";
   success: true
}

*/

await client.backup("delete", "1717986166031")
/**
Returns: 
{
   code: 200;
   id: "1717986166031";
   message: "Backup \"1717986166031\" was deleted successfully";
   success: true
}
*/

await client.backup("delete", "1717986166031", "main")
/**
Returns: 
{
   code: 200;
   id: "1717986166031";
   table: "main";
   message: "Table \"main\" was deleted successfully from backup \"1717986166031\"";
   success: true
}
*/

Go to list

Go Back>

Ping:

Description: This method retrieves the latency that the client has with the server in milliseconds.

Has Event: No

Example:

await client.ping()
/**
Returns: 
50
*/

Go Back

Exists:

Description: This method retrieves whether a table exists or not.

Has Event: No

Example:

await client.exists("main")
/**
Returns: 
true
*/

Go Back

Has:

Description: This method retrieves if a certain key exists in a table.

Has Event: No

Example:

await client.has("foo", "main")
/**
Returns: 
true
*/

Go Back

Set:

Description: This method sets a value to a specific key.

Has Event: Yes

Example:

await client.set("foo", "baar","main")
/**
Returns: 
{
   table: "main";
   data: {
       "foo": "baar"
   };
   success: true
}
*/

Go Back

Get:

Description: This method obtains a value from a particular key.

Has Event: Yes

Example:

await client.set("foo", "main")
/**
Returns: 
{
   table: "main";
   id: "foo"
   value: "baar"
   success: true
}
*/

Go Back

Delete:

Description: This method deletes a value from a particular key.

Has Event: Yes

Example:

await client.delete("foo", "main")
/**
Returns: 
{
   table: "main";
   data: {  }
   success: true
}
*/

Go Back

Push:

Description: This method pushes a value to a particular key

Has Event: Yes

Example:

await client.push("foo", "bar", "main")
/**
Returns: 
{
   table: "main";
   id: "foo"
   old: [  ]
   new: [ "bar" ]
   success: true
}
*/

Remove:

Description: This method removes a value to a particular key

Has Event: Yes

Example:

await client.remove("foo", "bar", "main")
/**
Returns: 
{
   table: "main";
   id: "foo"
   old: [ "bar" ]
   new: [  ]
   success: true
}
*/

Go Back

Shift:

Description: This method removes the first element of any array to a particular key.

Has Event: Yes

Example:

await client.shift("foo", "main")
/**
Returns: 
{
   table: "main";
   id: "foo"
   old: [ "bar" ]
   new: [  ]
   success: true
}
*/

Go Back

Pop:

Description: This method removes the last element of any array to a particular key.

Has Event: Yes

Example:

await client.pop("foo", "main")
/**
Returns: 
{
   table: "main";
   id: "foo"
   old: [ "bar", "bar2" ]
   new: [ "bar" ]
   success: true
}
*/

Go Back

UnShift:

Description: This method adds an element to the beginning of some array to a particular key.

Has Event: Yes

Example:

await client.unshift("foo", "bar0", "main")
/**
Returns: 
{
   table: "main";
   id: "foo"
   old: [ "bar", "bar2" ]
   new: [ "bar0", "bar", "bar2" ]
   success: true
}
*/

Go Back

Add:

Description: This method adds a given value to a given key.

Has Event: Yes

Example:

await client.add("money", 10, "main")
/**
Returns: 
{
   table: "main";
   id: "money"
   old: 0
   new: 10
   success: true
}
*/

Go Back

Sub:

Description: This method subtracts a given value from a given key.

Has Event: Yes

Example:

await client.sub("money", 2, "main")
/**
Returns: 
{
   table: "main";
   id: "money"
   old: 10
   new: 8
   success: true
}
*/

Go Back

Multiply:

Description: This method multiplies a given value to a particular key

Has Event: Yes

Example:

await client.multi("money", 2, "main")
/**
Returns: 
{
   table: "main";
   id: "money"
   old: 8
   new: 16
   success: true
}
*/

Go Back

Divide:

Description: This method divides a given value to a particular key

Has Event: Yes

Example:

await client.divide("money", 4, "main")
/**
Returns: 
{
   table: "main";
   id: "money"
   old: 16
   new: 4
   success: true
}
*/

Go Back

Contact me

1.1.3

1 year ago

1.1.21

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago