Relatude Help

Describing the model

Describe each node type as an interface named by its CodeName, with the property names exactly as in C#. The interface is for the compiler only: it decides which conditions a query offers, what rows look like and which values a write takes. The examples use this model:

interface IPage {                        // the CMS's page type
  Name: string;
  MetaTitle: string;
  ShowInMenu: boolean;
  Parent: db.One<IPage>;                 // the page tree
  Children: db.Many<IPage>;
}
interface ISection extends IPage { Intro: string; }
interface IArticle extends IPage { Author: string; PublishedUtc: Date; Body: string; Picture: db.FileValue; }
interface IProduct extends IPage { Sku: string; Price: db.Decimal; InStock: boolean; Picture: db.FileValue; }

const Page = db.nodeType<IPage>('IPage');
const Section = db.nodeType<ISection>('ISection');
const Article = db.nodeType<IArticle>('IArticle');
const Product = db.nodeType<IProduct>('IProduct');
C# TypeScript
string, bool string, boolean
int, double, float number
decimal, long db.Decimal, db.Long: JSON numbers, with a double's precision
DateTime, DateTimeOffset Date
TimeSpan db.TimeSpan: text such as 1.02:03:04.5000000
Guid db.Guid, a string
string[], Guid[] string[], db.Guid[]
an enum a TypeScript enum with the same numbers
GeoCoordinate db.GeoCoordinate: { latitude, longitude }
FileValue db.FileValue
a relation's "one" and "many" ends db.One<T>, db.Many<T>
Reference<T>, References<T> db.Ref<T>, db.Refs<T>: read and written as ids

db.nodeType<T>(codeName) pairs a CodeName with its interface, so store.query(Product) knows that its rows are products. A CodeName alone works too, typed as store.query<IProduct>('IProduct'), or untyped as store.query('IProduct'), with every property reachable by name. An interface needs only the properties your code uses.

CodeNames are case-sensitive: n.price against a property Price fails before anything is sent, with Did you mean "Price"? The store reads the schema once and keeps it. store.reloadSchema() reads it again after the model changes on the server.