fastdb中的relation

RELARION-关系,在fastdb内存数据库中表示在类(表)之间指定是一对一,一对多,还是多对多关系。

例如:class Detail {
  public:
    char const* name;
    char const* material;
    char const* color;
    real4       weight;

    dbArray< dbReference<Contract> > contracts;

    TYPE_DESCRIPTOR((KEY(name, INDEXED|HASHED),
                     KEY(material, HASHED),
                     KEY(color, HASHED),
                     KEY(weight, INDEXED),
                     RELATION(contracts, detail)));
};

class Supplier {
  public:
    char const* company;
    char const* location;
    bool        foreign;

    dbArray< dbReference<Contract> > contracts;

    TYPE_DESCRIPTOR((KEY(company, INDEXED|HASHED),
                     KEY(location, HASHED),
                     FIELD(foreign),
                     RELATION(contracts, supplier)));
};


class Contract {
  public:
    dbDateTime            delivery;
    int4                  quantity;
    db_int8               price;
    dbReference<Detail>   detail;
    dbReference<Supplier> supplier;

    TYPE_DESCRIPTOR((KEY(delivery, HASHED|INDEXED),
                     KEY(quantity, INDEXED),
                     KEY(price, INDEXED),
                     RELATION(detail, contracts),
                     RELATION(supplier, contracts)));
};

Detail和Contract是一对多的关系,Supplier和Contract也是一对多的关系。在每个类中最好的标记符号就是dbArray和dbReference。

阅读更多
个人分类: 内存数据库
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

fastdb中的relation

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭