LibRockDB-1.0

From WowAce Wiki
Jump to: navigation, search

API Documentation

Note: This documentation is auto-generated. Please note that direct modifications may be overwritten on next autogenerate.

:CopyProfile("name")

Arguments

"name"
string - the profile name to copy from.

Notes

  • Copy a profile from the given one to the current one.

Example

MyAddon:CopyProfile("Monkey") -- copy from the Monkey profile to the current one

:GetDatabaseNamespace("namespace")

Arguments

"namespace"
string - name of the namespace

Notes

  • Acquires a namespace within the database.
  • This is especially handy for a module system to use, simply get a namespace with the same name as your module, and it acts as a fully functioning database.

Example

MyAddon_Bank.db = MyAddon:AcquireDBNamespace("Bank")

:GetProfile()

Notes

  • If you are in a char, class, or realm profile, "short" will be "char", "class", or "realm" and "long" will be "char/Player of Realm Name", "class/Warlock", or "realm/My Realm - Horde". Otherwise, "short" and "long" will be equivalent.
  • "Default" is the default profile unless specified by :SetDefaultProfile.
  • This is only accurate after ADDON_LOADED.

Returns

"short" 
string - The current profile, short-form.
"long" 
string - The current profile, in its full, long form.

Example

local short, long = MyAddon:GetProfile()

:RemoveProfile("profile")

Arguments

"profile"
string - the new profile name

Notes

  • Deletes the given profile
  • This will error if it is the current profile, as that cannot be deleted.

Example

MyAddon:RemoveProfile("Monkey") -- remove all monkey-based goodness.

:ResetDatabase(kind , namespace)

Arguments

kind
string or nil - the data type to reset. If nil, then it means all data types.
namespace
string or nil - the namespace to reset. If nil, then it means the whole database.

Notes

  • Resets the database or a specific part of it.
  • This will call :OnResetDatabase(kind, namespace) once complete.

Example

MyAddon:RemoveProfile("Monkey") -- remove all monkey-based goodness.

:SetDatabase("dbName" , "charName")

Arguments

"dbName"
string - global name of the saved variable.
"charName"
string - global name of the per-character saved variable.

Notes

  • Sets a saved variable so as to correlate to the database table.
  • Setting the charName is unnecessary if you never use char-specific data. If you do use them, it can be a good idea to have.
  • This is to be called before ADDON_LOADED

Example

MyAddon:SetDatabase("MyAddonDB")
-- or
MyAddon:SetDatabase("MyAddonDB", "MyAddonCharDB")

:SetDatabaseDefaults("kind" , defaults)

Arguments

"kind"
string - "char", "class", "realm", "server", "account", "faction", or "profile" - correlates to the type of data you're working with.
defaults
table - the defaults

Notes

  • Set default values for a specific database type.
  • The defaults table can have subtables as well (as many as you want). This can be used to define your basic db structure.
  • You can also set a whole table's default value by using the special key ['*'], which even works with tables.
  • There is another key, ['**'], which does the same thing as ['*'] but also populates inside sibling nodes. For example, { ['**'] = { alpha = true, bravo = true, charlie = true}, monkey = { bravo = false } } makes monkey behave like { alpha = true, bravo = false, charlie = true }
  • If you use the 'profile' dataType, it applies to all profiles.
  • This is to be called between `SetDatabase' and ADDON_LOADED.

Example

MyAddon:SetDatabaseDefaults('char', {
    alpha = {
        bravo = {
            charlie = true
        }
    }
})
assert(MyAddon.db.char.alpha.bravo.charlie == true)
MyAddon:SetDatabaseDefaults('realm', {
    ['*'] = false -- special key
})
assert(MyAddon.db.realm.anyKeyHere == false)
MyAddon:SetDatabaseDefaults('class', {
    colors = {
        ['**'] = {
             r = 1, g = 1, b = 1
        },
		crazyBoss = {
			name = "The boss"
		}
    }
})
assert(MyAddon.db.class.colors.boss.r == 1)
MyAddon.db.class.colors.boss.r = 0
assert(MyAddon.db.class.colors.boss.r == 0)
assert(MyAddon.db.class.colors.otherBoss.r == 1)
assert(MyAddon.db.class.colors.crazyBoss.r == 1)
assert(MyAddon.db.class.colors.crazyBoss.name == "The boss")

:SetDatabaseNamespaceDefaults("namespace" , "kind" , defaults)

Arguments

"namespace"
string - name of the namespace
"kind"
string - "char", "class", "realm", "server", "account", "faction", or "profile" - correlates to the type of data you're working with.
defaults
table - the defaults

Notes

  • Set default values for a specific database type for a specified namespace.
  • The defaults table can have subtables as well (as many as you want). This can be used to define your basic db structure.
  • You can also set a whole table's default value by using the special key ['*'], which even works with tables.
  • There is another key, ['**'], which does the same thing as ['*'] but also populates inside sibling nodes. For example, { ['**'] = { alpha = true, bravo = true, charlie = true}, monkey = { bravo = false } } makes monkey behave like { alpha = true, bravo = false, charlie = true }
  • If you use the 'profile' dataType, it applies to all profiles.
  • This is to be called between :SetDatabase and ADDON_LOADED.

Example

MyAddon:SetDatabaseNamespaceDefaults('Bank', 'char', {
    value = 50
})
assert(MyAddon:GetDatabaseNamespace('Bank').char.value == 50)

:SetDefaultProfile("profile")

Arguments

"profile"
string - the name of the profile.

Notes

  • Sets the default profile.
  • If this is unspecified, "Default" is assumed.
  • Can be any arbitrary name, but it's recommended to use "Default", "Alternative", "char", "class", or "realm".

Example

MyAddon:SetDefaultProfile("char") -- will default to the character profile on a per-character basis.

:SetProfile("name")

Arguments

"name"
string - the new profile name

Notes

  • Set the current profile to the given profile name.
  • If "profile" is "char", "realm", or "class", it gets set to the appropriate profile based on the current character.
  • This will call :OnProfileDisable() if available, change the profile, then call :OnProfileEnable("oldName", oldData) if available. In turn, this will call any embeds :OnEmbedProfileDisable(self) and :OnProfileEnable(self, "oldName", oldData) if available.
  • Defaults will properly transfer to the new profile without harm.

Example

MyAddon:SetProfile("Monkey") -- for all your monkey-based goodness.
MyAddon:SetProfile("char") -- change to your character