Wowpedia

We have moved to Warcraft Wiki. Click here for information and the new URL.

READ MORE

Wowpedia
(Creation of non-db specific api)
 
m (Change to links)
Line 7: Line 7:
 
====Arguments====
 
====Arguments====
 
* name (string) - The name of the global variable associated with this database.
 
* name (string) - The name of the global variable associated with this database.
* defaults ([[#Dongle_Default_Table]]) - A table of defaults to be used for the given database. Should be given as a [[#Dongle_Default_Table]]
+
* defaults (table) - A table of defaults to be used for the given database. Should be given as a [[#Dongle_Default_Table|Dongle Default Table]]
 
* defaultProfile (string) - The default profile to use if the user hasn't selected one.
 
* defaultProfile (string) - The default profile to use if the user hasn't selected one.
 
====Returns====
 
====Returns====
* db ([[#Dongle_Database_Object]]) - The [[#Dongle_Database_Object]] encapsulating the new database.
+
* db (table) - The [[#Dongle_Database_Object|DongleDB Object]] encapsulating the new database.
 
====Behavior====
 
====Behavior====
 
This function can be called anytime AFTER :Initialize(). If you call this function prior to that point, it will succeed but your results will be unpredictable, since the saved variables are not loaded until :Initialize().
 
This function can be called anytime AFTER :Initialize(). If you call this function prior to that point, it will succeed but your results will be unpredictable, since the saved variables are not loaded until :Initialize().

Revision as of 19:01, 8 February 2007

Dongle provides a very powerful database system that easily enables the use of multiple and custom profiles. Each dongle object can have multiple databases associated with it, specified by a global variable name. Databases are registered with the core dongle object, which returns a database object.

DongleObject Database API

DongleObject:InitializeDB(name[, defaults, defaultProfile])

Initializes a database object and returns it.

Arguments

  • name (string) - The name of the global variable associated with this database.
  • defaults (table) - A table of defaults to be used for the given database. Should be given as a Dongle Default Table
  • defaultProfile (string) - The default profile to use if the user hasn't selected one.

Returns

Behavior

This function can be called anytime AFTER :Initialize(). If you call this function prior to that point, it will succeed but your results will be unpredictable, since the saved variables are not loaded until :Initialize().

Dongle Database Object

Each call to InitializeDB returns a new Dongle Database Object. These functions are all injected into the table, which can be used to store data in the various profiles. The profiles made available to each database object are:

  • db.profile - Most data storage should happen here. The user is able to change their profile, so any "portable" data should wind up here.
  • db.char - A character specific section ("CharName of RealmName")
  • db.realm - A realm specific section ("RealmName").
  • db.class - A class specific section ("LocalisedClassName").
  • db.faction - A faction specific section ("Horde").
  • db.factionrealm - A faction/realm specific section ("Horde - RealmName")
  • db.global - A global profile, available to all users

Only the profile section is changable by the user and most data should be stored there. If you have a specific reason for the other sections, they have been provided. Any empty sections are removed when logging off, to prevent unnecessary data storage.

Dongle Default Table

The defaults table has a specific format, which needs to match the sections in the actual database. The following is the general format which should be used:

local defaults = {
  profile = {
    fruits = {
      apple = true
    }
  },
  char = {},
  realm = {},
  class = {},
  faction = {},
  factionrealm = {},
  global = {},
}

You don't need to supply each and every section, only the ones you wish to establish defaults for. There is no harm is having sections missing, or having blank sections as above.

Dongle Database Object API