Skip to content

Models and Attributes

Now that we have configured details for the Dore_Ecommerce database, we need to provide definitions for the Customer and Order tables of the e-commerce schema.

In Dore, A Model represents a set of structured data. Models usually correspond to tables/collections/indexes in a database/cluster. Attributes correspond to columns/fields.

Let's add the models object in the manifest which will contain the model definitions:

dore-ecommerce-manifest.json
{
  "id": "ecommerce-example",
  "datastores": {
    "ecommerce": {
      "protocol": "mysql",
      "properties": {
        "database": "Dore_Ecommerce",
        "host": "127.0.0.1",
        "port": "3306",
        "user": "root",
        "password": "password"
      }
    }
  },
  "models": {}
}

We will be adding definitions for each of the tables of the ecommerce schema.

Models

Like datastores, each model is defined with a key which will be the ID for the Model and value as the Model Definition.

Let's add two models, customer and order, corresponding to Customer and Order tables of the ecommerce schema:

dore-ecommerce-manifest.json
{
  "id": "ecommerce-example",
  "datastores": {
    "ecommerce": {
      "protocol": "mysql",
      "properties": {
        "database": "Dore_Ecommerce",
        "host": "127.0.0.1",
        "port": "3306",
        "user": "root",
        "password": "password"
      }
    }
  },
  "models": {
    "customer": {},
    "order": {}
  }
}

Linked Datastore

Since Customer and Order tables need to be created within the Dore_Ecommerce database, we define that both customer and order models are associated with the ecommerce datastore:

dore-ecommerce-manifest.json
{
  "id": "ecommerce-example",
  "datastores": {
    "ecommerce": {
      "protocol": "mysql",
      "properties": {
        "database": "Dore_Ecommerce",
        "host": "127.0.0.1",
        "port": "3306",
        "user": "root",
        "password": "password"
      }
    }
  },
  "models": {
    "customer": {
      "datastore": "ecommerce"
    },
    "order": {
      "datastore": "ecommerce"
    }
  }
}

Records

We need to define the count of records that Dore should generate for each of the models. So let's define this for the customer and order models as follows:

dore-ecommerce-manifest.json
{
  "id": "ecommerce-example",
  "datastores": {
    "ecommerce": {
      "protocol": "mysql",
      "properties": {
        "database": "Dore_Ecommerce",
        "host": "127.0.0.1",
        "port": "3306",
        "user": "root",
        "password": "password"
      }
    }
  },
  "models": {
    "customer": {
      "datastore": "ecommerce",
      "records": 10
    },
    "order": {
      "datastore": "ecommerce",
      "records": 100
    }
  }
}

With the records field on the models, we have defined that Dore should generate 10 records for the customer model and 100 records for the order model.

Attributes

The Customer table of the e-commerce schema has two columns:

  • customer_id
  • customer_name

And the Order table has three columns:

  • order_id
  • customer_id
  • order_date

In order to add definitions for these columns in the manifest, we need to define Attributes for the customer and order models corresponding to these columns.

Attributes for a model are defined at $.models[*].attributes in the Manifest; i.e, within the attributes field for a model. Like datastores and models, each attribute is defined with a key which will be the ID for the Attribute and value as the Attribute Definition.

dore-ecommerce-manifest.json
{
  "id": "ecommerce-example",
  "datastores": {
    "ecommerce": {
      "protocol": "mysql",
      "properties": {
        "database": "Dore_Ecommerce",
        "host": "127.0.0.1",
        "port": "3306",
        "user": "root",
        "password": "password"
      }
    }
  },
  "models": {
    "customer": {
      "datastore": "ecommerce",
      "records": 10,
      "attributes": {
        "customerId": {},
        "customerName": {}
      }
    },
    "order": {
      "datastore": "ecommerce",
      "records": 100,
      "attributes": {
        "orderId": {},
        "customerId": {},
        "orderDate": {}
      }
    }
  }
}

We will be now be adding value definitions for the attributes above.


➡ Next: Attribute Value Definition