@kingbecats/evedb v1.1.3
EveDB
A Database using: Express, JSON files and Tables
- ***Update: 1.1.1:
- Fixed bug where path to save data doesn't create
Index
- EveDB - Index - Install - Server - Client - Client Events - Client Methods - Contact me
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, } */ })
- error -
{ code: number; message: string }
- getAll - Reference
- getTables - Reference
- getTable - Reference
- deleteTable - Reference
- getBackups - Reference
- backupCreate - Reference
- backupGet - Reference
- backupRestore - Reference
- backupDelete - Reference
- set - Reference
- get - Reference
- delete - Reference
- push - Reference
- remove - Reference
- shift - Reference
- pop - Reference
- unshift - Reference
- add - Reference
- sub - Reference
- multi - Reference
- divide - Reference
Client Methods
- GetAll
- GetTables
- GetTable
- DeleteTable
- GetBackups
- Backup
- Ping
- Exists
- Has
- Set
- Get
- Delete
- Push
- Remove
- Shift
- Pop
- UnShift
- Add
- Sub
- Multi
- Divive
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": {...} }; }; } */
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" }, }; } */
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 } */
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 } */
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" }, } }; } */
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 } */
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" } } */
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 } */
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 */
Exists:
Description: This method retrieves whether a table exists or not.
Has Event: No
Example:
await client.exists("main") /** Returns: true */
Has:
Description: This method retrieves if a certain key exists in a table.
Has Event: No
Example:
await client.has("foo", "main") /** Returns: true */
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 } */
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 } */
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 } */
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 } */
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 } */
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 } */
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 } */
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 } */
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 } */
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 } */
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 } */
Contact me