summary refs log tree commit diff stats
path: root/lib/group.cpp
blob: 8b6d98551a0c1a11d5edb99f7eaa035ff4528d18 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "group.h"
#include <sqlite3.h>
#include "frame.h"
#include "database.h"
#include "query.h"

namespace verbly {
  
  const object group::objectType = object::group;
  
  const std::list<std::string> group::select = {"group_id", "data"};
  
  const field group::id = field::integerField(object::group, "group_id");
  
  const field group::frame = field::joinThrough(object::group, "group_id", object::frame, "groups_frames", "frame_id");
  const field group::word = field::joinField(object::group, "group_id", object::word);
  
  group::group(const database& db, sqlite3_stmt* row) : db_(&db), valid_(true)
  {
    id_ = sqlite3_column_int(row, 0);
    
    // TODO: Initialize role data from row.
  }
  
  const std::vector<frame>& group::getFrames() const
  {
    if (!valid_)
    {
      throw std::domain_error("Bad access to uninitialized group");
    }
    
    if (!initializedFrames_)
    {
      frames_ = db_->frames(frame::group %= *this, false, -1).all();
      
      initializedFrames_ = true;
    }
    
    return frames_;
  }
  
};