Collection

The data is stored in collections, where how the collection is created and its detailed information are specified.

new Collection(options)

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

ParameterDefaultDescription

options

Object Collection options.

options.name

String Name of collection.

options.type

String [IMPORTANT] Type of the collection, which cannot be changed again later. Valid values: DOCUMENT_BASED, KEY_VALUE_BASED

options.id_length

32

Number (optional) [DOCUMENT-BASED COLLECTIONS] This determines the length of unique identities given to documents.

options.indicate_created_at

false

Boolean (optional) [DOCUMENT-BASED COLLECTIONS] Whether to specify the creation date of documents.

options.indicate_created_timestamp

false

Boolean (optional) [DOCUMENT-BASED COLLECTIONS] Whether to specify the creation timestamp of documents.

options.indicate_edited_at

false

Boolean (optional) [DOCUMENT-BASED COLLECTIONS] Whether to specify the edited date of documents.

options.indicate_edited_timestamp

false

Boolean (optional) [DOCUMENT-BASED COLLECTIONS] Whether to specify the edited timestamp of documents.

options.indicate_archived_at

false

Boolean (optional) [DOCUMENT-BASED COLLECTIONS] Whether to specify the archived at of documents.

options.indicate_archived_timestamp

false

Boolean (optional) [DOCUMENT-BASED COLLECTIONS] Whether to specify the archived timestamp of documents.

options.indicate_unarchived_at

false

Boolean (optional) [DOCUMENT-BASED COLLECTIONS] Whether to specify the unarchived at of documents.

options.indicate_unarchived_timestamp

false

Boolean (optional) [DOCUMENT-BASED COLLECTIONS] Whether to specify the unarchived timestamp of documents.

options.save_timeout

1

Number (optional) This 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

Number (optional) This specifies that after how many documents have been inserted, the collection will be saved without the save timeout.

options.cache_retention_time

10

Number (optional) [If 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

Number (optional) [If this value is -1, backups will never be deleted] This determines after how many days the backups will be deleted.

options.caching

false

Boolean (optional) [IMPORTANT] 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_backup

false

Boolean (optional) If this is enabled, this collection will create automatic backups.

options.detailed_debugger_logs

false

Boolean (optional) If this is enabled, it will print more events in the collection to the console.

options.activate_drop_method

false

Boolean (optional) [IMPORTANT] If this is enabled, the <Collection>.Drop() method becomes operable. This command serves to drop your collection completely. It is a dangerous method.

Example:

const example_collection = new <PeakDB | Connection>.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_drop_method": false
});

Last updated