DaZeus  2.0
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
dazeus::Database Class Reference

A database frontend. More...

#include <database.h>

Public Member Functions

 Database (const std::string &hostname, uint16_t port, const std::string &database=std::string("dazeus"), const std::string &username=std::string(), const std::string &password=std::string())
 Constructor. More...
 
 ~Database ()
 Destructor. More...
 
bool open ()
 
std::string lastError () const
 Returns the last error in the QSqlDatabase object. More...
 
std::string property (const std::string &variable, const std::string &networkScope=std::string(), const std::string &receiverScope=std::string(), const std::string &senderScope=std::string())
 Retrieve property from database. More...
 
void setProperty (const std::string &variable, const std::string &value, const std::string &networkScope=std::string(), const std::string &receiverScope=std::string(), const std::string &senderScope=std::string())
 
std::vector< std::string > propertyKeys (const std::string &ns, const std::string &networkScope=std::string(), const std::string &receiverScope=std::string(), const std::string &senderScope=std::string())
 Retrieve all properties under a certain namespace. More...
 

Detailed Description

A database frontend.

This frontend abstracts away from the SQL standard, and simply defines the idea of 'properties'. Properties have a unique identifier and a QVariant value. They can be saved inside global, network, channel or user scope.

Properties are saved into a table 'properties' which may have multiple entries - one per specific scope. The table is created by calling createTable(). Calling tableExists() checks whether this table exists.

See Also
setProperty()

Definition at line 51 of file database.h.

Constructor & Destructor Documentation

dazeus::Database::Database ( const std::string &  hostname,
uint16_t  port,
const std::string &  database = std::string("dazeus"),
const std::string &  username = std::string(),
const std::string &  password = std::string() 
)

Constructor.

Definition at line 23 of file database.cpp.

dazeus::Database::~Database ( )

Destructor.

Definition at line 38 of file database.cpp.

Member Function Documentation

std::string dazeus::Database::lastError ( ) const

Returns the last error in the QSqlDatabase object.

Definition at line 47 of file database.cpp.

bool dazeus::Database::open ( )

Definition at line 52 of file database.cpp.

std::string dazeus::Database::property ( const std::string &  variable,
const std::string &  networkScope = std::string(),
const std::string &  receiverScope = std::string(),
const std::string &  senderScope = std::string() 
)

Retrieve property from database.

The most specific scope will be selected first, i.e. user-specific scope. If that yields no results, channel-specific scope will be returned, then network-specific scope, then global scope.

Variable should be formatted using reverse-domain format, i.e. for the plugin MyFirstPlugin created by John Doe, to save a 'foo' variable one could use: net.jondoe.myfirstplugin.foo

Definition at line 204 of file database.cpp.

std::vector< std::string > dazeus::Database::propertyKeys ( const std::string &  ns,
const std::string &  networkScope = std::string(),
const std::string &  receiverScope = std::string(),
const std::string &  senderScope = std::string() 
)

Retrieve all properties under a certain namespace.

All properties whose names start with the given namespace name, then a single dot, and that match the given scope values, are returned from this method.

This method guarantees that if it returns a certain key, property() will return the correct value of that key given that network, receiver and sender scope are the same.

Definition at line 111 of file database.cpp.

void dazeus::Database::setProperty ( const std::string &  variable,
const std::string &  value,
const std::string &  networkScope = std::string(),
const std::string &  receiverScope = std::string(),
const std::string &  senderScope = std::string() 
)

selector: {network:'foo',receiver:'bar',sender:null,variable:'bla.blob'} object: {'$set':{ 'value': 'bla'}}

Definition at line 326 of file database.cpp.


The documentation for this class was generated from the following files: