peak.db v2.2.1
Contents
About
Fast and advanced, document based and key-value based NoSQL database that able to work as it is installed.
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.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 active, will be automatically specified date when documents are archived.<CollectionOptions>.Indicate_Archived_Timestamp<[Boolean]>
added. If this is active, will be automatically specified timestamp when documents are archived.<CollectionOptions>.Indicate_Unarchived_At<[Boolean]>
added. If this is active, will be automatically specified date when documents are unarchived.<CollectionOptions>.Indicate_Unarchived_Timestamp<[Boolean]>
added. If this is active, 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.
Installation
npm install peak.db
Documentation
Constructor
new Collection(options)
Create a collection where you can manage and store your data.
Parameter Default Description options ObjectCollection options. options.name StringName of collection. options.type StringIMPORTANT Type of the collection, which cannot be changed again later.Valid values: DOCUMENT_BASED
,KEY_VALUE_BASED
options.id_length 32
Number DOCUMENT BASED COLLECTIONSThis determines the length of unique identities given to documents. options.indicate_created_at false
Boolean DOCUMENT BASED COLLECTIONSWhether to specify the creation date of documents. options.indicate_created_timestamp false
Boolean DOCUMENT BASED COLLECTIONSWhether to specify the creation timestamp of documents. options.indicate_edited_at false
Boolean DOCUMENT BASED COLLECTIONSWhether to specify the edited date of documents. options.indicate_edited_timestamp false
Boolean DOCUMENT BASED COLLECTIONSWhether to specify the edited timestamp of documents. options.indicate_archived_at false
Boolean DOCUMENT BASED COLLECTIONSWhether to specify the archived at of documents. options.indicate_archived_timestamp false
Boolean DOCUMENT BASED COLLECTIONSWhether to specify the archived timestamp of documents. options.indicate_unarchived_at false
Boolean DOCUMENT BASED COLLECTIONSWhether to specify the unarchived at of documents. options.indicate_unarchived_timestamp false
Boolean DOCUMENT BASED COLLECTIONSWhether to specify the unarchived timestamp of documents. options.save_timeout 1
NumberThis 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_after 5
NumberThis specifies that after how many documents have been inserted, the collection will be saved without the save timeout. options.cache_retention_time 10
NumberIf 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_time 3
NumberIf this value is -1
, backups will never be deleted This determines after how many days the backups will be deleted.options.caching false
BooleanIMPORTANT If this is active, 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_backup false
BooleanIf this is active, this collection will receive automatic backups. options.detailed_debugger_logs false
BooleanIf this is active, it will print more events in the collection to the console. options.activate_destroy_function false
BooleanIMPORTANT If this is active, 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_backup": true, "detailed_debugger_logs": true, "activate_destroy_function": false });
Methods
insert(data)
(document based)
Insert a document.
Parameter Description data ObjectThe data 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.
Parameter Description params Function | ObjectThe parameters you will use to find the data. options ObjectFind options. options.archived BooleanWhether 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.
Parameter Description params Function | ObjectThe parameters you will use to filter the data. options ObjectFilter options. options.archived BooleanWhether to filter archived documents. 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.
Parameter Description params Function | ObjectThe parameters you will use to check the data. options ObjectFind options. options.archived BooleanWhether to has archived documents. returns Boolean
Example:
accounts.has(document => document.region === "Muğla"); // -> true accounts.has({"region": "Muğla"}); // -> true
update(document_id, data)
(document based)
Update a document.
Parameter Description document_id StringThe ID of the document to be updated. data ObjectData to be updated in the document. 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.
Parameter Description document_id StringThe 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.
Parameter Description document_id StringThe ID of the document to be archived. 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.
Parameter Description document_id StringThe 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.
Parameter Description key String | NumberKey to value. value String | 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.
Parameter Description key String | 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.
Parameter Description key String | NumberKey to value. data String | 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.
Parameter Description key String | NumberKey to value. data String | 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.
Parameter Description key String | NumberKey to value. params Function | 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.
Parameter Description key String | NumberKey to value. params Function | 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.
Parameter Description key String | NumberKey to value. params Function | 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.
Parameter Description key String | NumberKey to value. value NumberThe number to be incremented. returns Number
Example:
user_settings.increase("USER_1.age", 15); // -> 15 user_settings.increase("USER_1.age", 1); // -> 16
reduce(key, value)
(key-value based)
Reduce the number in the value.
Parameter Description key String | NumberKey to value. value NumberThe number to decrease. returns Number
Example:
user_settings.reduce("USER_1.age", 5); // -> 11
delete(key)
(key-value based)
Reduce the number in the value.
Parameter Description key String | NumberKey to value. returns Number
Example:
user_settings.delete("USER_1.age"); // -> true
backup()
Backup the collection.
returns Boolean
Example:
collection.backup(); // -> true
destroy()
Destroy the collection.
returns Boolean
Example:
collection.destroy(); // -> true
License
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