AceDB-3.0 API Documentation

From WowAce Wiki
Jump to: navigation, search

Data types

There are 8 different data types an AceDB-3.0 object can handle.

char
Character-specific data. No other characters can access or change this data, it is specific to one character and one character alone.
realm
Realm-specific data. All of the players characters on the same realm share this database.
class
Class-specific data. All of the players characters of a certain class share this database.
race
Race-specific data. All of the players characters of a certain race share this database.
faction
Faction-specific data. All of the players characters of a certain faction share this database.
factionrealm
Faction and realm specific data. All of the players characters on the same realm and in the same faction share this database.
profile
Profile-specific data. All characters using the same profile share this database. Every character can select its own profile, or they can all share one.
global
Global Data. All characters on the same account share this database.

AceDB:New( tbl [, defaults [, defaultprofile]] )

tbl (string or table) 
target table to store our DB in, either string pointing to a global table (your addons SV table), or a direct table reference
[defaults] (table) 
reference to the defaults table
[defaultprofile] (string) 
default profile to start with on an empty DB (defaults to character)

Returns a new DBObject on top of the specified table. This should be called from OnInitialize or another post-load event; calling it from the main chunk won't properly load existing data.

DBObject:RegisterDefaults( [defaults] )

[defaults] (table) 
A table of defaults for this database

Sets the defaults table for the given database object. All previously set defaults will be cleared from the database, and the new default values will be applied.

Calling db:RegisterDefaults() without specifying a defaults table will remove all defaults from the table.

Note: This function is available on child databases/namespaces as well

DBObject:SetProfile( name )

name (string) 
The name of the profile to set as the current profile

Changes the profile of the database and all of it's namespaces to the supplied named profile

Fires the "OnProfileChanged" callback on success ( see AceDB-3.0 Callbacks for details )

DBObject:GetProfiles( [tbl] )

[tbl] (table) 
A table to store the profile names in (optional)
Return values
tbl (table) : A table containing the names of the profiles known to the database.
count (integer) : The number of profiles known

Returns a integer indexed table containing the names of the existing profiles in the database. You can optionally supply a table to re-use for this purpose.

DBObject:GetCurrentProfile()

Returns the current profile name used by the database

DBObject:DeleteProfile(name)

name (string) 
The name of the profile to be deleted

Deletes a named profile. This profile must not be the active profile.

Fires the "OnProfileDeleted" callback on success. ( see AceDB-3.0 Callbacks for details )

DBObject:CopyProfile(name)

name (string) 
The name of the profile to be copied into the current profile

Resets the current profile to default and copies the data from the specified profile into the current profile.

Fires the "OnProfileCopied" callback on success. ( see AceDB-3.0 Callbacks for details )

DBObject:ResetProfile( [noChildren] )

[noChildren] (boolean) - If set to true, do not populate the reset to all child namespaces and only reset the main database.

Resets the currently selected profile to its default values.

Fires the "OnProfileReset" callback on success ( see AceDB-3.0 Callbacks for details )

Note: This function is available on child databases/namespaces as well

DBObject:ResetDB( [defaultProfile] )

[defaultProfile] (string) 
The profile name to use as the default

Resets the entire database, using the string defaultProfile as the new default profile, if supplied.

Fires the "OnDatabaseReset" and "OnProfileChanged" callbacks on success ( see AceDB-3.0 Callbacks for details )

DBObject:RegisterNamespace(name [, defaults])

name (string) 
The name of the new namespace
defaults (table) 
A table of values to use as defaults

Creates a new database namespace, directly tied to the database. This is a full scale database in it's own rights other than the fact that it cannot control its profile individually. Returns a new DBObject pointing to the namespace.

Note: Keep in mind that a namespace is not a fully functional database on its own. Most of the API functions are not defined for namespaces, in fact only RegisterDefaults and ResetProfile are implemented for use with the namespace object.