Creating Data Models

Initializing a Data Model

Viewing typescript

switch to python

Using the CLI

To create a new Data Model in your Moose application, use the data-model init command. This will generate a file in the /datamodels directory of your Moose application and define your Data Model within it.

Terminal
npx moose-cli data-model init --sample <PATH_TO_SAMPLE_DATA> <DATA_MODEL_NAME>
  • <PATH_TO_SAMPLE_DATA>: The path to the sample data file.
  • <DATA_MODEL_NAME>: The name of the Data Model.
Automatically Infer Data Model

If you have a .json or .csv file with sample data representing the structure of the data you want to ingest, you can use the --sample flag to specify the path to that file. The CLI will then infer the Data Model schema from the provided file and create the Data Model for you.

Creating a new Data Model Manually

There are two additional ways to initialize a new Data Model in your Moose project:

  • By creating a new .ts file in the /datamodels directory of your Moose application and defining a new Data Model inside this file.
  • By appending a new Data Model to an existing .ts file in your /datamodels directory.
datamodels/myDataModel.ts
import { Key } from "moose-lib";
 
export interface MyNewDataModel {
  primaryKey: Key<string>;
  someString: string;
  someNumber: number;
  someBoolean: boolean;
  someDate: Date;
  someArray: string[];
  ...
}