Developing your App
Primitive: Data Models
Using Data Models

Creating a Model

To get started you simply need to open the models.prisma file in your project's datamodels directory and add a new Data Model definition.

datamodels/models.prisma
model UserActivity {
    eventId     String @id
    timestamp   DateTime
    userId      String
    activityType String
}

Data Model conventions

As you can see, the data model is very simple. It's just a list of fields and their types. MooseJS's data modeling is built on top of Prisma's intuitive schema modeling language. You can read more about Prisma's schema modeling language here (opens in a new tab). We don't currently support all of Prisma's schema modeling features, but we're working on it; and we’ll also soon be adding support to define Data Models as Typescript interfaces.

Data Models can be defined in any file with a .prisma extension in your project's datamodels directory. The name of the file is not important. You may also define multiple models in the same Prisma file.

Supported Types

Here is the status of MooseJS support for various data types in Data Models:

PrismaClickhouseTypescriptMoose
StringStringString
BooleanBooleanBoolean
IntInt64Number
BigIntInt256BigInt
FloatFloat64Number
DecimalDecimalNumber
DateTimeDateTimeDate
JsonJsonObject
Bytesn/an/a
EnumEnumEnum
ArraysArrayArray
Optionalnullablenullable

Note: support for Enum in automatically generated Typescript SDK is coming soon.

Inspecting Your Model

Once you've created your model, you can inspect it along with the infrastructure that MooseJS automatically generated for you by navigating to the console at http://localhost:3001 (opens in a new tab).

Here you fill find a list of all your Data Models. You can click into any Data Model to see details about it, to get information about the APIs/SDKs for that Data Model, and to directly query the data currently stored in the Data Model (technically, the data stored in the database table associated with that Data Model).

Data Model Console

Test Your Model

When you create a model, MooseJS automatically creates an ingestion point to facilitate immediate data testing. Send a sample payload to this endpoint using:

curl -X POST \
  -H "Content-Type: application/json" \
  -d '{"eventId": "1234567890", "timestamp": "2019-01-01 00:00:01", "userId": "123456", "activityType":"click"}' \
  http://localhost:4000/ingest/UserActivity

Next steps

You're all set to start sending data into your Moose application from upstream sources, and consuming into downstream sources. Check out the next two sections of the docs for more details on Ingesting and Consuming Data. To understand the impact of changes to your Data Model, refer to the Data Change Management section of the docs.