LibRockDB-1.0
From WowAce Wiki
| Summary | |
|---|---|
| Lib: RockDB-1.0 | |
| Database library | |
| TOC | 2.4 (20400) |
| Category | Libraries |
| Author | ckknight |
| Details | |
| Links | |
| Website | http://www.wowace.com |
| Betas | Ace SVN Zip |
| Changelog | FishEye |
[edit]
API Documentation
Note: This documentation is auto-generated. Please note that direct modifications may be overwritten on next autogenerate.
[edit]
:CopyProfile("name")
[edit]
Arguments
- "name"
- string - the profile name to copy from.
[edit]
Notes
- Copy a profile from the given one to the current one.
[edit]
Example
MyAddon:CopyProfile("Monkey") -- copy from the Monkey profile to the current one
[edit]
:GetDatabaseNamespace("namespace")
[edit]
Arguments
- "namespace"
- string - name of the namespace
[edit]
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.
[edit]
Example
MyAddon_Bank.db = MyAddon:AcquireDBNamespace("Bank")
[edit]
:GetProfile()
[edit]
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.
[edit]
Returns
- "short"
- string - The current profile, short-form.
- "long"
- string - The current profile, in its full, long form.
[edit]
Example
local short, long = MyAddon:GetProfile()
[edit]
:RemoveProfile("profile")
[edit]
Arguments
- "profile"
- string - the new profile name
[edit]
Notes
- Deletes the given profile
- This will error if it is the current profile, as that cannot be deleted.
[edit]
Example
MyAddon:RemoveProfile("Monkey") -- remove all monkey-based goodness.
[edit]
:ResetDatabase(kind , namespace)
[edit]
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.
[edit]
Notes
- Resets the database or a specific part of it.
- This will call :OnResetDatabase(kind, namespace) once complete.
[edit]
Example
MyAddon:RemoveProfile("Monkey") -- remove all monkey-based goodness.
[edit]
:SetDatabase("dbName" , "charName")
[edit]
Arguments
- "dbName"
- string - global name of the saved variable.
- "charName"
- string - global name of the per-character saved variable.
[edit]
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
[edit]
Example
MyAddon:SetDatabase("MyAddonDB")
-- or
MyAddon:SetDatabase("MyAddonDB", "MyAddonCharDB")
[edit]
:SetDatabaseDefaults("kind" , defaults)
[edit]
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
[edit]
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.
[edit]
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")
[edit]
:SetDatabaseNamespaceDefaults("namespace" , "kind" , defaults)
[edit]
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
[edit]
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.
[edit]
Example
MyAddon:SetDatabaseNamespaceDefaults('Bank', 'char', {
value = 50
})
assert(MyAddon:GetDatabaseNamespace('Bank').char.value == 50)
[edit]
:SetDefaultProfile("profile")
[edit]
Arguments
- "profile"
- string - the name of the profile.
[edit]
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".
[edit]
Example
MyAddon:SetDefaultProfile("char") -- will default to the character profile on a per-character basis.
[edit]
:SetProfile("name")
[edit]
Arguments
- "name"
- string - the new profile name
[edit]
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.
[edit]
Example
MyAddon:SetProfile("Monkey") -- for all your monkey-based goodness.
MyAddon:SetProfile("char") -- change to your character

