Skip to content

Create database class

Hamed Masafi edited this page Dec 21, 2019 · 5 revisions

Database class must inherits from Database class.

Versioning

Database class can have NUT_DB_VERSION for declaring version number, version will be stored in database if upgrade needed.

NUT_DB_VERSION(version)

Declare tables

for every table in database NUT_DECLARE_TABLE macro should be use, usage:

NUT_DECLARE_TABLE(class_name, table_name)

Sample database class:

class Post;
class Comment;
class WeblogDatabase : public Database
{
    Q_OBJECT

    NUT_DB_VERSION(1)

    NUT_DECLARE_TABLE(Post, post)

    NUT_DECLARE_TABLE(Comment, comment)

public:
    WeblogDatabase();
};

Child tables should initalize in constructor, Example:

WeblogDatabase::WeblogDatabase() : Database(), 
        m_posts(new TableSet<Post>(this)),
        m_comments(new TableSet<Comment>(this))
{
}

Table of contents

Clone this wiki locally