#include "lmdb-typed.hh" #include unsigned int getMaxID(MDBRWTransaction& txn, MDBDbi& dbi) { auto cursor = txn.getCursor(dbi); MDBOutVal maxidval, maxcontent; unsigned int maxid{0}; if(!cursor.get(maxidval, maxcontent, MDB_LAST)) { maxid = maxidval.get(); } return maxid; } using namespace std; struct DNSResourceRecord { string qname; // index uint16_t qtype{0}; uint32_t domain_id{0}; // index string content; uint32_t ttl{0}; string ordername; // index bool auth{true}; }; template void serialize(Archive & ar, DNSResourceRecord& g, const unsigned int version) { ar & g.qtype; ar & g.qname; ar & g.content; ar & g.ttl; ar & g.domain_id; ar & g.ordername; ar & g.auth; } struct compound { std::string operator()(const DNSResourceRecord& rr) { std::string ret; ret.assign((char*)&rr.domain_id, 4); ret.append(rr.ordername); return ret; } }; int main() { TypedDBI, index_on, index_on_function > tdbi(getMDBEnv("./typed.lmdb", MDB_NOSUBDIR, 0600), "records"); { auto rotxn = tdbi.getROTransaction(); DNSResourceRecord rr0; if(rotxn.get(2, rr0)) { cout << "id 2, found "<("powerdns.com"); for(auto& iter = range.first; iter != range.second; ++iter) { cout << iter->qname << " " << iter->qtype << " " <content <() << " " << rotxn.size<1>() << " " << rotxn.size<2>() << endl; cout<<" " << rotxn.cardinality<0>() << endl; cout<<" " << rotxn.cardinality<1>() << endl; cout<<" " << rotxn.cardinality<2>() << endl; } auto txn = tdbi.getRWTransaction(); txn.clear(); cout<<"Currently have "<< txn.size()<< " entries after clear"<() << " " << txn.size<1>() << " " << txn.size<2>() << endl; cout<<" " << txn.cardinality<0>() << endl; cout<<" " << txn.cardinality<1>() << endl; cout<<" " << txn.cardinality<2>() << endl; DNSResourceRecord rr; rr.domain_id=11; rr.qtype = 5; rr.ttl = 3600; rr.qname = "www.powerdns.com"; rr.ordername = "www"; rr.content = "powerdns.com"; auto id = txn.insert(rr); cout<<"Inserted as id "<("www.powerdns.com", rr2); cout<<"Retrieved id "<< id <<", content: "<("powerdns.com", rr2); cout<<"Retrieved id "<< id <<", content: "<("powerdns.com", rr3); cout<< id << endl; cout<<"Going to iterate over everything, ordered by name!"<(); iter != txn.end(); ++iter) { cout << iter.getID()<<": "<qname << " " << iter->qtype << " " << iter->content <(); iter != txn.end(); ++iter) { cout << iter.getID()<<": "<qname << " " << iter->qtype << " " << iter->content <qname << " " << iter->qtype << " " << iter->content <(); iter != txn.end(); ++iter) { cout << iter.getID()<<": "<qname << " " << iter->qtype << " " << iter->content <<" # "<ordername << endl; } compound c; rr3.ordername = "www"; rr3.domain_id = 10; auto iter = txn.find<2>(c(rr3)); cout <<"Found using compound index: "<qname<< " # " <ordername<qname<< " # " <ordername<("powerdns.com"); iter.first != iter.second; ++iter.first) { cout << iter.first.getID()<<": "<qname << " " << iter.first->qtype << " " << iter.first->content <(10); iter != txn.end(); ++iter) { cout << iter.getID()<<": "<qname << " " << iter->qtype << " " << iter->content <