dboo.class (Node.js)

dboo.class(<class name>,
           <base class> | [<base class 1>, <base class 2>, ...],
           [{<member 1 name>: <dboo type>},
            {<member 2 name>: <dboo type>}
            ],
           {<extra params>}
          );

The dboo.class() function is used for describing all classes and their relations that DBOO should know about. It is important that all dboo.class() declarations have been made prior to the call to dboo.init().

Parameters

class name

The name of the class. Not in quotation, but just the class function.

base class

(Optional) If the class has one or more base classes. If more than one, use an array of class references.

member list

An array of objects describing name and type of each member property.

extra params

(Optional) An object with extra parameters. Currently only ‘version’ is supported, but it is not required to use.

Extra params

Explanation

version

Specifies a class version as a number.

Example: {version: 12}

Return value

(none)

Exceptions

Example

class.js

Try it

 1const dboo = require('dboo')
 2
 3class Product {
 4  _name;
 5  _description;
 6  _price;
 7  constructor(name = "", price = 0.) {
 8    this._name = name;
 9    this._price = price;
10  }
11};
12exports.Product=Product;
13
14class Purchase {
15  _customer;
16  _product;
17  _price;
18  _quantity;
19  constructor(prod = null, customer = null, quantity = 0, price = 0) {
20    this._customer = prod;
21    this._product = customer;
22    this._price = quantity;
23    this._quantity = price;
24  }
25};
26exports.Purchase=Purchase;
27
28class Customer {
29  _email;
30  _name;
31  _purchases;
32  
33  constructor( name = "", email = "") {
34    this._name = name;
35    this._email = email;
36    this._purchases = [];
37  }
38  
39  made_purchase(purchase) {
40    this._purchases.push(purchase);
41  }
42};
43exports.Customer=Customer;
44
45
46dboo.class(Product, [
47  {"_name":dboo.string},
48  {"_description":dboo.string},
49  {"_price":dboo.double},
50]);
51
52dboo.class(Purchase, [
53  {"_customer":Customer},
54  {"_product":Product},
55  {"_price":dboo.double},
56  {"_quantity":dboo.double},
57]);
58
59dboo.class(Customer, [
60  {"_email":dboo.string},
61  {"_name":dboo.string},
62  {"_purchases":dboo.array(Purchase)},
63]);
64
65// all dboo.class calls must be done before dboo.init()
66dboo.init();