Skip to content

Attribute Value Definition

Overview

Dore generates fake data for models of schemas by generating fake data for each of its attributes and combining them to form records.

In order for Dore to generate value for an attribute, we need to configure details in the attribute using the value object which defines how Dore generates value for it.

The Value Definition of an attribute should specify an Attribute Value Generator, along with any parameters that it might need, that Dore will use to generate values for the attribute.

Let's define value configs for each of the attributes we created in the previous section.



Customer Model

This section contains details of value definitions for attributes of the customer model.

customerId

Since each customer ID needs to be a unique string, we can use UUID values for the customer_id column.

Dore supports various Attribute Value Generators that you can use to define how value for a particular attribute should to be generated.

In order to generate UUID values, we can use the Faker Value Generator. Let's provide the value definition for customerId attribute to indicate that Dore should generate UUID values for this column using the Faker Value Generator:

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": {
          "value": {
            "faker": {
              "uuid4": {}
            }
          }
        },
        "customerName": {}
      }
    },
    "order": {
      "datastore": "ecommerce",
      "records": 100,
      "attributes": {
        "orderId": {},
        "customerId": {},
        "orderDate": {}
      }
    }
  }
}


customerName

For generating random names, we can use the Faker Value Generator again and use the name method. Let's add the value definition for customerName attribute to our manifest:

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": {
          "value": {
            "faker": {
              "uuid4": {}
            }
          }
        },
        "customerName": {
          "value": {
            "faker": {
              "name": {}
            }
          }
        }
      }
    },
    "order": {
      "datastore": "ecommerce",
      "records": 100,
      "attributes": {
        "orderId": {},
        "customerId": {},
        "orderDate": {}
      }
    }
  }
}



Order Model

This section contains details of value definitions for attributes of the order model.

orderId

The Order ID, similar to a Customer ID, uniquely defines an Oder. We can use UUID values for the order_id column.

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": {
          "value": {
            "faker": {
              "uuid4": {}
            }
          }
        },
        "customerName": {
          "value": {
            "faker": {
              "name": {}
            }
          }
        }
      }
    },
    "order": {
      "datastore": "ecommerce",
      "records": 100,
      "attributes": {
        "orderId": {
          "value": {
            "faker": {
              "uuid4": {}
            }
          }
        },
        "customerId": {},
        "orderDate": {}
      }
    }
  }
}

customerId

Based on the ecommerce schema, The customer_id column of the Order table is a Foreign Key which references the customer_id column of the Customer table.

You can use the Ref Value Generator to define that Dore should generate values for an attribute by deriving its values of from values of another attribute. Such attributes are also known as Dependent Attributes.

Since the value of order.customerId attribute is dependent on customer.customerId attribute, we can add value definition for order.customerId 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,
      "attributes": {
        "customerId": {
          "value": {
            "faker": {
              "uuid4": {}
            }
          }
        },
        "customerName": {
          "value": {
            "faker": {
              "name": {}
            }
          }
        }
      }
    },
    "order": {
      "datastore": "ecommerce",
      "records": 100,
      "attributes": {
        "orderId": {
          "value": {
            "faker": {
              "uuid4": {}
            }
          }
        },
        "customerId": {
          "value": {
            "ref": "customer.customerId"
          }
        },
        "orderDate": {}
      }
    }
  }
}

orderDate

For generating random dates, we can use the Faker Value Generator again and use the date_between method:

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": {
          "value": {
            "faker": {
              "uuid4": {}
            }
          }
        },
        "customerName": {
          "value": {
            "faker": {
              "name": {}
            }
          }
        }
      }
    },
    "order": {
      "datastore": "ecommerce",
      "records": 100,
      "attributes": {
        "orderId": {
          "value": {
            "faker": {
              "uuid4": {}
            }
          }
        },
        "customerId": {
          "value": {
            "ref": "customer.customerId"
          }
        },
        "orderDate": {
          "value": {
            "faker": {
              "date_between": {
                "start_date": "-1y"
              }            
            }
          }
        }
      }
    }
  }
}

We have defined the value config for orderDate attribute to be a random date in the last year


Next: Protocol specific properties