[odb-users] An easy one about indexes

Boris Kolpackov boris at codesynthesis.com
Tue Jul 17 06:57:42 EDT 2012


Hi Miguel,

Miguel Revilla Rodríguez <yo at miguelrevilla.com> writes:

> How do I declare by pragmas additional indexes for a table?

I've been waiting for this question for a while now ;-). Currently
there is no way to do it with pragmas. It is always possible to add
indexes using SQL but, I agree, having a pragma would make this much
easier. Something along these lines:

#pragma db object
struct person
{
  #pragma db index     // Add normal index called age_i.
  unsigned short age_;  

  #pragma db unique
  std::string email_;  // Add unique index called email_i.

  std::string first_;
  std::string last_;

  // Add composite index called name_i that uses the BTREE method.
  //
  #pragma db index("name_i") member(first_) member(last_) method("BTREE")
};

I am going to implement this in the next couple of days. Let me know
if you would like to give it a try.

Boris



More information about the odb-users mailing list