-
Notifications
You must be signed in to change notification settings - Fork 0
code
David Sarrut edited this page Jul 23, 2015
·
2 revisions
- dont use
using namespace std, instead prefix everystringorvectorwithstd::stringorstd::vector. See why: http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice
When query a database, could use the words get, select, query or find. We decided to keep query because odb use it. We use find when it is a table specific query (FindPatient).
- (prevent Record to be created outside a pointer)
All database type in inherit from this class (in particular syd::StandardDatabase). This is an abstract class. Any class inheriting from syd::Database must implement CreateTables, with a calls to AddTable<MyRecord>, this will define the tables.
Common functions to all databases:
- Dump
- New
- Insert
- Set
- Find -fixme
Inherit from TableBase. Automated class for a new Record type. Created by AddTable
- class syd::Record base class for all table
Inherit from syd::Record, automatically get an id. Need to define:
friend class odb::access;
typedef std::shared_ptr<TABLE_NAME> pointer;
typedef std::vector<pointer> vector;
virtual std::string GetTableName() const { return #TABLE_NAME; }
static std::string GetStaticTableName() { return #TABLE_NAME; }
static pointer New() { return pointer(new TABLE_NAME); }
virtual std::string ToString() const;
virtual bool IsEqual(const pointer p) const;
virtual void CopyFrom(const pointer p);
virtual void Sort(vector & v, const std::string & order);
virtual void Set(const syd::Database * db, const std::vector<std::string> & args);
virtual void InitPrintTable(const syd::Database * db, syd::PrintTable & ta, const std::string & format) const;
virtual void DumpInTable(const syd::Database * db, syd::PrintTable & ta, const std::string & format) const;