StorageUnit

open class StorageUnit<T : Data>(val storageType: StorageType, val namespace: String, val identifier: String, val dataType: KClass<T>) : KordExKoinComponent

Class representing a storage unit. Storage units represent specific, single units of data, and explain how to store, retrieve and serialize that data.

Storage units instruct the data adapters, explaining exactly what needs to be done. However, those adapters are free to handle the storage as they feel they need to.

Constructors

Link copied to clipboard
constructor(storageType: StorageType, namespace: String, identifier: String, dataType: KClass<T>)

Properties

Link copied to clipboard
open var channel: Snowflake?

Channel context, supplied via withChannel or withChannelFrom.

Link copied to clipboard

The classobj representing your data - usually retrieved via MyDataClass::class.

Link copied to clipboard
open var guild: Snowflake?

Guild context, supplied via withGuild or withGuildFrom.

Link copied to clipboard
open val identifier: String

The identifier - usually a specific category or name. Represents a filename for file-backed storage.

Link copied to clipboard
open var message: Snowflake?

Message context, supplied via withMessage or withMessageFrom.

Link copied to clipboard
open val namespace: String

The namespace - usually a plugin or extension ID. Represents a folder for file-backed storage.

Link copied to clipboard
val serializer: KSerializer<T>

Reference to the serializer for this storage unit's data type.

Link copied to clipboard

The type of data to store.

Link copied to clipboard

Storage unit key - used to construct paths, or just as a string reference to this storage unit.

Link copied to clipboard
open var user: Snowflake?

User context, supplied via withUser or withUserFrom.

Functions

Link copied to clipboard
open fun copy(): StorageUnit<T>

Return a new StorageUnit object, containing a copy of all the data that's stored in this one.

Link copied to clipboard
suspend fun delete(): Boolean

Convenience function, allowing you to delete the data represented by this storage unit.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean

Generated function provided here because data classes don't care about non-constructor properties.

Link copied to clipboard
suspend fun get(): T?

Convenience function, allowing you to retrieve the data represented by this storage unit.

Link copied to clipboard
open override fun getKoin(): Koin

Get the associated Koin instance.

Link copied to clipboard
open override fun hashCode(): Int

Generated function provided here because data classes don't care about non-constructor properties.

Link copied to clipboard
suspend fun reload(): T?

Convenience function, allowing you to reload the data represented by this storage unit.

Link copied to clipboard
suspend fun save(): T?

Convenience function, allowing you to save the cached data represented by this storage unit.

suspend fun save(data: T): T

Convenience function, allowing you to save the given data object, as represented by this storage unit.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
fun withChannel(channelId: Snowflake): StorageUnit<T>

Copy this StorageUnit, applying the given channel ID to its context, but only if it's not a DM channel.

suspend fun withChannel(channelObj: ChannelBehavior): StorageUnit<T>

Copy this StorageUnit, applying the given channel's ID to its context, but only if it's not a DM channel.

Link copied to clipboard
suspend fun withChannelFrom(event: Event): StorageUnit<T>

Copy this StorageUnit, applying the channel ID from the given event to its context, but only if it's present and not a DM channel.

Link copied to clipboard
fun withGuild(guildId: Snowflake): StorageUnit<T>

Copy this StorageUnit, applying the given guild ID to its context.

fun withGuild(guildObj: GuildBehavior): StorageUnit<T>

Copy this StorageUnit, applying the given guild's ID to its context.

Link copied to clipboard
suspend fun withGuildFrom(event: Event): StorageUnit<T>

Copy this StorageUnit, applying the guild ID from the given event to its context, if present.

Link copied to clipboard
fun withMessage(messageId: Snowflake): StorageUnit<T>

Copy this StorageUnit, applying the given message ID to its context.

fun withMessage(messageObj: MessageBehavior): StorageUnit<T>

Copy this StorageUnit, applying the given message's ID to its context.

Link copied to clipboard
suspend fun withMessageFrom(event: Event): StorageUnit<T>

Copy this StorageUnit, applying the message ID from the given event to its context, if present.

Link copied to clipboard
fun withUser(userId: Snowflake): StorageUnit<T>

Copy this StorageUnit, applying the given user ID to its context.

fun withUser(userObj: UserBehavior): StorageUnit<T>

Copy this StorageUnit, applying the given user's ID to its context.

Link copied to clipboard
suspend fun withUserFrom(event: Event): StorageUnit<T>

Copy this StorageUnit, applying the user ID from the given event to its context, if present.