4.3.1. Data Model Property Types

In this chapter, you’ll learn about the types of properties in a data model’s schema.

id#

The id method defines an automatically generated string ID property.

For example:

1import { model } from "@medusajs/utils"2
3const MyCustom = model.define("my_custom", {4  id: model.id(),5  // ...6})7
8export default MyCustom

text#

The text method defines a string property.

For example:

1import { model } from "@medusajs/utils"2
3const MyCustom = model.define("my_custom", {4  name: model.text(),5  // ...6})7
8export default MyCustom

number#

The number method defines a number property.

For example:

1import { model } from "@medusajs/utils"2
3const MyCustom = model.define("my_custom", {4  age: model.number(),5  // ...6})7
8export default MyCustom

bigNumber#

The bigNumber method defines a number property that expects large numbers, such as prices.

For example:

1import { model } from "@medusajs/utils"2
3const MyCustom = model.define("my_custom", {4  price: model.bigNumber(),5  // ...6})7
8export default MyCustom

boolean#

The boolean method defines a boolean property.

For example:

1import { model } from "@medusajs/utils"2
3const MyCustom = model.define("my_custom", {4  hasAccount: model.boolean(),5  // ...6})7
8export default MyCustom

enum#

The enum method defines a property whose value can only be one of the specified values.

For example:

1import { model } from "@medusajs/utils"2
3const MyCustom = model.define("my_custom", {4  color: model.enum(["black", "white"]),5  // ...6})7
8export default MyCustom

The enum method accepts an array of possible string values.


dateTime#

The dateTime method defines a timestamp property.

For example:

1import { model } from "@medusajs/utils"2
3const MyCustom = model.define("my_custom", {4  date_of_birth: model.dateTime(),5  // ...6})7
8export default MyCustom

json#

The json method defines a property whose value is a stringified JSON object.

For example:

1import { model } from "@medusajs/utils"2
3const MyCustom = model.define("my_custom", {4  metadata: model.json(),5  // ...6})7
8export default MyCustom

array#

The array method defines an array of strings property.

For example:

1import { model } from "@medusajs/utils"2
3const MyCustom = model.define("my_custom", {4  names: model.array(),5  // ...6})7
8export default MyCustom
Was this chapter helpful?