Home Manual Reference Source Repository
import GuildStorage from 'discord-graf/src/storage/index.js'
public class | source

GuildStorage

Stores data entries associated with guilds

Constructor Summary

Public Constructor
public

constructor(key: string, localStorage: LocalStorage, logger: Logger, objectBased: boolean)

Member Summary

Public Members
public
public
public
public
public

Method Summary

Public Methods
public

clear(guild: Guild | string)

Clears all entries associated with a guild

public

Clears all entries

public

delete(guild: Guild | string, entry: * | Object | string, searchFunction: function): boolean

Deletes an entry associated with a guild

public

exists(guild: Guild | string, entry: * | Object | string, searchFunction: function): boolean

Checks if an entry associated with a guild exists

public

find(guild: Guild | string, searchString: string, searchOptions: SearchOptions): *[]

Finds all entries in a storage that optionally match a search string

public

Checks if there are no entries associated with a guild

public

Loads the data from LocalStorage

public

save(guild: Guild | string, entry: * | Object, searchFunction: function): boolean

Saves an entry associated with a guild

public

Saves the data to LocalStorage

Public Constructors

public constructor(key: string, localStorage: LocalStorage, logger: Logger, objectBased: boolean) source

Params:

NameTypeAttributeDescription
key string

The key of the storage in the LocalStorage

localStorage LocalStorage

The LocalStorage instance to use

logger Logger
  • optional

The logger to use

objectBased boolean
  • optional
  • default: false

If true, the storage will be object based. If false, it will be array-based.

Public Members

public guildsMap: Object source

public key: string source

public localStorage: LocalStorage source

public logger: Logger source

public objectBased: boolean source

Public Methods

public clear(guild: Guild | string) source

Clears all entries associated with a guild

Params:

NameTypeAttributeDescription
guild Guild | string

The guild or guild ID to clear the entries of

public clearAll() source

Clears all entries

public delete(guild: Guild | string, entry: * | Object | string, searchFunction: function): boolean source

Deletes an entry associated with a guild

Params:

NameTypeAttributeDescription
guild Guild | string

The guild or guild ID the entry is associated with

entry * | Object | string

If the storage is array-based, this can be any value to find and delete. If it is object-based, this must be an object with a "key" property, or a string that is the key.

searchFunction function
  • optional

The function to find existing entries (See GuildStorage#exists)

Return:

boolean

Whether or not the entry was deleted

public exists(guild: Guild | string, entry: * | Object | string, searchFunction: function): boolean source

Checks if an entry associated with a guild exists

Params:

NameTypeAttributeDescription
guild Guild | string

The guild or guild ID the entry is associated with

entry * | Object | string

If the storage is array-based, this can be any value to check existence of. If it is object-based, this must be an object with a "key" property, or a string that is the key.

searchFunction function
  • optional

The function to find existing entries. If the storage is array-based, it will be passed the value of each entry. If it is object-based, it will be passed the key and value of each entry.

Return:

boolean

Whether or not the entry exists

public find(guild: Guild | string, searchString: string, searchOptions: SearchOptions): *[] source

Finds all entries in a storage that optionally match a search string

Params:

NameTypeAttributeDescription
guild Guild | string

The guild or guild ID to find the entries of

searchString string
  • optional

The string to match entries against

searchOptions SearchOptions
  • optional

Options for the search

Return:

*[]

All found entries

public isEmpty(guild: Guild | string): boolean source

Checks if there are no entries associated with a guild

Params:

NameTypeAttributeDescription
guild Guild | string

The guild or guild ID to check emptiness of

Return:

boolean

Whether or not there are no entries associated with the guild

public loadStorage() source

Loads the data from LocalStorage

public save(guild: Guild | string, entry: * | Object, searchFunction: function): boolean source

Saves an entry associated with a guild

Params:

NameTypeAttributeDescription
guild Guild | string

The guild or guild ID the entry should be associated with

entry * | Object

If the storage is array-based, this can be any value to store. If it is object-based, this must be an object with "key" and "value" properties to store.

searchFunction function
  • optional

The function to find existing entries (See GuildStorage#exists)

Return:

boolean

Whether or not the entry was saved (will be false only if the storage is array-based and the entry already exists)

public saveStorage() source

Saves the data to LocalStorage