dboo::odb::throw_on_undefined

Node.js only

n/a
throw_on_undefined ( enable )                     // 1)
throw_on_undefined() : Boolean                    // 2)
1

Change behaviour of how dboo::odb::commit handles undefined member variables/properties in Node.js. If

throw_on_undefined is enabled, dboo::odb::commit will throw an exception when encountering n undefined property. If disabled, commit will store default value(s) for any primitive and null for pointers/references. Default behaviour is to not throw. .. [2] Returns the current setting for throw_on_undefined.

Parameters

enable

A bool. If set to true, dboo::odb::commit will throw.

Return value

1

(none)

2

A bool with current setting.

Exceptions

Example

n/a
const dboo = require('dboo');
const config = require('config');


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

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

dboo.argv(process.argv);

dbConfig = config.get('dbConfig');

dboo.init(); // Class declarations must come before init!

const db = new dboo.odb();

db.throw_on_undefined(true); // set on connection object

db.connect(dbConfig.host, Number(dbConfig.port),
            dbConfig.dbName, dbConfig.webUserName,
            dbConfig.webUserPwd);


let u = new UserId("me");
db.commit(u);  // Throws because screenName is not set