2.3.9 • Published 2 years ago

peakdb v2.3.9

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Contents

About

Fast and advanced, document-based and key-value-based NoSQL database.

Features

  • NoSQL database
  • Can be run as it is installed
  • Can be used document-based and key-value-based
  • Customizable settings for collections
  • No need to use schema
  • Quick data reading and writing
  • Data can be kept in cache
  • Easy to find data
  • Automatically or manual backup

Latest Updates

v2.2.1 → v2.3.0

  • Updates for System:
    • <Collection>.Backup() changed. This function will now be used as createBackup().
    • <Collection>.LoadBackup() added. With this function, you can easily restore backups.
    • <Collection>.CreateBackup() returns changed. Now this function, if successful, will return the filename of the backed up collection on its return.
    • <CollectionOptions>.Auto_Backup changed. This option will now be used as auto_create_backup.
  • Updates for Key-Value-Based Collections:
    • <Collection>.Reduce() changed. This function will now be used as decrease().

v2.1.0 → v2.2.0

  • Updates for System:
    • Bugs fixed. Fixed some bugs in the system.
    • <CollectionOptions>.Indicate_Archived_At<[Boolean]> added. If this is enabled, will be automatically specified date when documents are archived.
    • <CollectionOptions>.Indicate_Archived_Timestamp<[Boolean]> added. If this is enabled, will be automatically specified timestamp when documents are archived.
    • <CollectionOptions>.Indicate_Unarchived_At<[Boolean]> added. If this is enabled, will be automatically specified date when documents are unarchived.
    • <CollectionOptions>.Indicate_Unarchived_Timestamp<[Boolean]> added. If this is enabled, will be automatically specified timestamp when documents are unarchived.
  • Updates for document-based Collections:
    • <Collection>.Archive() added. By archiving a document, you can have it ignored by the system.
    • <Collection>.Unarchive() added. You can extract the archived document from the archive.
    • <Collection>.Find(..., options) added. You can customize it with options to find.
    • <Collection>.Filter(..., options) added. You can customize it with options to filter.
    • <Collection>.Has(..., options) added. You can customize it with options to check.
    • <FindOptions>.Archived<[Boolean]> added. With this option you can specify whether to find archived documents or not.
    • <FilterOptions>.Archived<[Boolean]> added. With this option you can specify whether to filter archived documents or not.
    • <HasOptions>.Archived<[Boolean]> added. With this option you can specify whether to check archived documents or not.
  • Updates for Key-Value-Based Collections:
    • <Collection>.Find() added. You can find the data in the array.
    • <Collection>.Filter() added. You can filter the data in the array.

... see all

Installation

npm install peakdb

Documentation

Constructor

new Collection(options)

Create a collection where you can manage and store your data.

ParameterDefaultDescription
optionsObjectCollection options.
options.nameStringName of collection.
options.typeStringIMPORTANT Type of the collection, which cannot be changed again later.Valid values: DOCUMENT_BASED, KEY_VALUE_BASED
options.id_length32Number DOCUMENT-BASED COLLECTIONSThis determines the length of unique identities given to documents.
options.indicate_created_atfalseBoolean DOCUMENT-BASED COLLECTIONSWhether to specify the creation date of documents.
options.indicate_created_timestampfalseBoolean DOCUMENT-BASED COLLECTIONSWhether to specify the creation timestamp of documents.
options.indicate_edited_atfalseBoolean DOCUMENT-BASED COLLECTIONSWhether to specify the edited date of documents.
options.indicate_edited_timestampfalseBoolean DOCUMENT-BASED COLLECTIONSWhether to specify the edited timestamp of documents.
options.indicate_archived_atfalseBoolean DOCUMENT-BASED COLLECTIONSWhether to specify the archived at of documents.
options.indicate_archived_timestampfalseBoolean DOCUMENT-BASED COLLECTIONSWhether to specify the archived timestamp of documents.
options.indicate_unarchived_atfalseBoolean DOCUMENT-BASED COLLECTIONSWhether to specify the unarchived at of documents.
options.indicate_unarchived_timestampfalseBoolean DOCUMENT-BASED COLLECTIONSWhether to specify the unarchived timestamp of documents.
options.save_timeout1NumberThis specifies how many seconds after a document is inserted, the collection will be saved. This way it limits the successive saving of the collection when many data are inserted in succession, so the system is not slowed down. Data loss may occur if the system is turned off after repeatedly entering data. When the document is added 5 times in a row, the collection is saved so that the data does not remain unsaved for a long time. This can be edited with the 'save_directly_after' option.
options.save_directly_after5NumberThis specifies that after how many documents have been inserted, the collection will be saved without the save timeout.
options.cache_retention_time10NumberIf this value is -1, the cache is kept indefinitely This specifies how many minutes the cache will be retained if caching is enabled. If there is no activity in the collection, the cache is cleared, thus preventing RAM loss.
options.backup_retention_time3NumberIf this value is -1, backups will never be deleted This determines after how many days the backups will be deleted.
options.cachingfalseBooleanIMPORTANT If this is enabled, the data is kept in the cache. In this case, the data is processed quickly, but the size of the collection is the loss of RAM. Is not preferred for large collections.
options.auto_create_backupfalseBooleanIf this is enabled, this collection will create automatic backups.
options.detailed_debugger_logsfalseBooleanIf this is enabled, it will print more events in the collection to the console.
options.activate_destroy_functionfalseBooleanIMPORTANT If this is enabled, the <Collection>.Destroy() function becomes operable. This command serves to destroy your collection completely. It is a dangerous command.

Example:

const example_collection = new PeakDB.Collection({
  "name": "EXAMPLE_COLLECTION",
  "type": "DOCUMENT_BASED",
  
  /*
    For document-based collections
  */
  "id_length": 32,
  "indicate_created_at": false,
  "indicate_created_timestamp": true,
  "indicate_updated_at": false,
  "indicate_updated_timestamp": true,
  "indicate_archived_at": false,
  "indicate_archived_timestamp": true,
  "indicate_unarchived_at": false,
  "indicate_unarchived_timestamp": true,
  
  /*
    Can be used on all collection types
  */
  "save_timeout": 1,
  "save_directly_after": 5,
  "cache_retention_time": 10,
  "backup_retention_time": 3,
  "caching": true,
  "auto_create_backup": true,
  "detailed_debugger_logs": true,
  "activate_destroy_function": false
});

Methods

insert(document) (document-based)

Insert a document.

ParameterDescription
documentObjectThe document to be written to the collection.

returns Object

Example:

accounts.insert({"email": "fir4tozden@gmail.com", "username": "fir4tozden", "password": "12345678", "region": "Muğla"});
/*
  {
    "_id": "RMmXZVDfQrVLQwFlquMPb98XNUCxQ6MM",
    "_updated": false,
    "_archived": false,
    "_created_at": 2022-03-20T00:00:00.000Z,
    "_created_timestamp": 1647745200000,
    "email": "fir4tozden@gmail.com",
    "username": "fir4tozden",
    "password": "12345678",
    "region": "Muğla"
  }
*/

find(params, options) (document-based)

Find a document.

ParameterDescription
paramsFunction | ObjectThe parameters you will use to find the data.
optionsObjectFind options.
options.archivedBooleanWhether to find archived documents.

returns Object

Example:

accounts.find(document => document.email === "fir4tozden@gmail.com", {"archived": true});
// or
accounts.find({"email": "fir4tozden@gmail.com"}, {"archived": true});
/*
  {
    "_id": "RMmXZVDfQrVLQwFlquMPb98XNUCxQ6MM",
    "_updated": false,
    "_archived": false,
    "_created_at": 2022-03-20T00:00:00.000Z,
    "_created_timestamp": 1647745200000,
    "email": "fir4tozden@gmail.com",
    "username": "fir4tozden",
    "password": "12345678",
    "region": "Muğla"
  }
*/

filter(params, options) (document-based)

Filter documents.

ParameterDescription
paramsFunction | ObjectThe parameters you will use to filter the data.
optionsObjectFilter options.
options.archivedBooleanWhether to filter archived documents.

returns Array<Object>

Example:

accounts.filter(document => document.region === "Muğla", {"archived": true});
// or
accounts.filter({"region": "Muğla"}, {"archived": true});
/*
  [
    {
      "_id": "RMmXZVDfQrVLQwFlquMPb98XNUCxQ6MM",
      "_updated": false,
      "_archived": false,
      "_created_at": 2022-03-20T00:00:00.000Z,
      "_created_timestamp": 1647745200000,
      "email": "fir4tozden@gmail.com",
      "username": "fir4tozden",
      "password": "12345678",
      "region": "Muğla"
    },
    {
      "_id": "23ERK9fHqiH_n83fhzU7eOYtzz6tUl7S",
      "_updated": false,
      "_archived": false,
      "_created_at": 2022-03-20T00:05:00.000Z,
      "_created_timestamp": 1647734700000,
      "email": "nehir@gmail.com",
      "username": "nehir",
      "password": "12345678",
      "region": "Muğla"
    }
  ]
*/

has(params, options) (document-based)

Check if they have document.

ParameterDescription
paramsFunction | ObjectThe parameters you will use to check the data.
optionsObjectFind options.
options.archivedBooleanWhether to has archived documents.

returns Boolean

Example:

accounts.has(document => document.region === "Muğla"); // -> true
accounts.has({"region": "Muğla"}); // -> true

update(document_id, document) (document-based)

Update a document.

ParameterDescription
document_idStringThe ID of the document to be updated.
documentObjectThe document to be updated in the collection.

returns Object

Example:

let document = accounts.find(document => document.email === "fir4tozden@gmail.com");
accounts.update(document._id, {"email": "fir4tozden@gmail.com", "username": "hey_im_fir4tozden", "password": "87654321", "region": "İstanbul"});
/*
  {
    "_id: "23ERK9fHqiH_n83fhzU7eOYtzz6tUl7S",
    "_updated": true,
    "_archived": false,
    "_created_at": 2022-03-20T00:00:00.000Z,
    "_created_timestamp": 1647745200000,
    "_updated_at": 2022-03-20T00:10:00.000Z,
    "_updated_timestamp": 1647735000000,
    "email": "fir4tozden@gmail.com",
    "username": "hey_im_fir4tozden",
    "password": "87654321",
    "region": "İstanbul"
  }
*/

archive(document_id) (document-based)

Archive a document.

ParameterDescription
document_idStringThe ID of the document to be archived.

returns Boolean

Example:

let document = accounts.find(document => document.email === "fir4tozden@gmail.com");
accounts.archive(document._id); // -> true

unarchive(document_id) (document-based)

Unarchive a document.

ParameterDescription
document_idStringThe ID of the document to be unarchived.

returns Boolean

Example:

let document = accounts.find(document => document.email === "fir4tozden@gmail.com", {"archived": true});
accounts.unarchive(document._id); // -> true

delete(document_id) (document-based)

Delete a document.

ParameterDescription
document_idStringThe ID of the document to be deleted.

returns Boolean

Example:

let document = accounts.find(document => document.email === "fir4tozden@gmail.com");
accounts.delete(document._id); // -> true

set(key, value) (key-value-based)

Set a value.

ParameterDescription
keyString | NumberKey to value.
valueString | Number | Object | ArrayYour data to set.

returns String | Number | Object | Array

Example:

user_settings.set("USER_1", {"friend_requests": true});
/*
  {
    "friend_requests": true
  }
*/

get(key) (key-value-based)

Get a value.

ParameterDescription
keyString | NumberKey to value.

returns String | Number | Object | Array

Example:

user_settings.get("USER_1.friend_requests"); // -> true

push(key, data) (key-value-based)

Push a data to array.

ParameterDescription
keyString | NumberKey to value.
dataString | Number | Object | ArrayData to be push to the array.

returns Array

Example:

user_settings.push("USER_1.friends", "USER_2");
/*
  [
    "USER_2"
  ]
*/

remove(key, data) (key-value-based)

Remove a data from array.

ParameterDescription
keyString | NumberKey to value.
dataString | Number | Object | ArrayData to be remove from the array.

returns Array

Example:

user_settings.remove("USER_1.friends", "USER_2");
/*
  []
*/

find(key, params) (key-value-based)

Find a data from array.

ParameterDescription
keyString | NumberKey to value.
paramsFunction | ObjectThe parameters you will use to find the data.

returns Object

Example:

user_settings.find("USER_1.social_media_addresses", data => data.platform === "Instagram");
// or
user_settings.find("USER_1.social_media_addresses", {"platform": "Instagram"});
/*
  {
    "platform": "Instagram",
    "username": "fir4tozden"
  }
*/

filter(key, params) (key-value-based)

Filter data from array.

ParameterDescription
keyString | NumberKey to value.
paramsFunction | ObjectThe parameters you will use to filter the data.

returns Array

Example:

user_settings.filter("USER_1.social_media_addresses", data => data.username === "fir4tozden");
// or
user_settings.filter("USER_1.social_media_addresses", {"username": "fir4tozden"});
/*
  [
    {
      "platform": "Instagram",
      "username": "fir4tozden"
    },
    {
      "platform": "Twitter",
      "username": "fir4tozden"
    }
  ]
*/

has(key, params) (key-value-based)

Check if they have key or data.

ParameterDescription
keyString | NumberKey to value.
paramsFunction | Object | String | NumberThe parameters you will use to check the data.

returns Boolean

Example:

user_settings.has("USER_1.hobbies"); // -> true
user_settings.has("USER_1.hobbies", data => data === "Watching TV"); // -> false
user_settings.has("USER_1.hobbies", "Watching TV"); // -> false
user_settings.has("USER_1.social_media_addresses", {"platform": "Instagram"}); // -> true

increase(key, value) (key-value-based)

Increase the number in the value.

ParameterDescription
keyString | NumberKey to value.
valueNumberThe number to be incremented.

returns Number

Example:

user_settings.increase("USER_1.age", 15); // -> 15
user_settings.increase("USER_1.age", 1); // -> 16

decrease(key, value) (key-value-based)

Decrease the number in the value.

ParameterDescription
keyString | NumberKey to value.
valueNumberThe number to be decremented.

returns Number

Example:

user_settings.decrease("USER_1.age", 5); // -> 11

delete(key) (key-value-based)

Delete a key.

ParameterDescription
keyString | NumberKey to value.

returns Number

Example:

user_settings.delete("USER_1.age"); // -> true

createBackup()

Create a backup of the collection.

returns String<BackupFilename> | Boolean

Example:

example_collection.createBackup(); // -> EXAMPLE_COLLECTION_2022-03-20_AUTO.pea

loadBackup(filename)

Load a backup to the collection.

ParameterDescription
filenameStringThe filename of the backup.

returns Boolean

Example:

example_collection.loadBackup("EXAMPLE_COLLECTION_2022-03-20_AUTO.pea"); // -> true

destroy()

Destroy the collection.

returns Boolean

Example:

example_collection.destroy(); // -> true

License

MIT

2.3.9

2 years ago

2.3.8

2 years ago

2.4.3

2 years ago

2.4.2

2 years ago

2.4.1

2 years ago

2.4.0

2 years ago

2.3.7

2 years ago

2.3.6

2 years ago

2.3.5

2 years ago

2.3.4

2 years ago

2.3.3

2 years ago

2.3.2

2 years ago

2.3.1

2 years ago

2.3.0

2 years ago

2.2.2

2 years ago

2.2.1

2 years ago

2.2.0

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

2.1.0

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago