dboo::odb::define

define<T>();                                                           1)
define(const cls_class_base& cls);                                     2)
define(const type_desc_class& type_desc, const type_desc_set& types);  3)
define(Type)

Defines a class to dboo, so that dboo can create indices.

1

Define by using the class type as template parameter. Only classes that have been registered with the dboo_class_init and has a cls<> object associated can be registered with the database.

2

Define by using the class object as parameter.

3

Define by using the type descriptor and descriptor set as parameters.

Template Parameters

T (C++)

The class that will be defined in the database.

Parameters

Type (Node.js)

The class that will be defined in the database

cls (C++)

The class object that will be defined in the database.

type_desc (C++)

A type descriptor object.

types (C++)

The type set the type_desc is part of.

Return value

(none)

Exceptions

Example

class A {
public:
  inline static dboo::cls<A> cls{"A"};
  static void dboo_class_init(dboo::cls<A>& c) {
    c.member(&A::var1, "var1");
  }
private:
  int var1;
};

int main() {

    dboo::odb db;

    db.connect("localhost", 8823,
              "my_database",
              "usr132",
              "password");

    db.define<A>();

    // or...
    db.define(A::cls);


    return 0;
}
const dboo = require('dboo');
dboo.argv(process.argv);

const config = require('config');

dbConfig = config.get('dbConfig');

class UserId {
  userId = "";
  screenName = "";
  constructor(userid = "", screenName = "") {
    this.userId = userid;
    this.screenName = screenName;
  }
};

exports.UserId = UserId;

dboo.class(UserId,
  [{"userId": dboo.string},
    {"screenName": dboo.string},
  ]
);

dboo.init();

const db = new dboo.odb();
db.connect(dbConfig.host, Number(dbConfig.port),
            dbConfig.dbName, dbConfig.webUserName,
            dbConfig.webUserPwd);

db.define(UserId);