9. Syntax

DNAL views are used for data conversion. A view is a mapping from one set of fields to another.

outview

An outview maps a DNAL type to an output type that may have different field names and types. For example, given a Person type, we can define an outview to generate a PersonDTO

type Person struct { 
  firstName string,
  lastName string,
  birthData date,
  id        int
} end

outview Person -> PersonDTO { 
  firstName -> fName string,
  lastName -> lName string,
  birthDate -> birthDate string format('yyyy-mm-dd'),
  id -> customerId string
}

The first field firstName is copied to a destination field fName of the same type (string). lastName is copied to lName.  The birthDate field is converted from date to string using the format expression.  The id field is converted from int to string. DNAL does many conversions automatically (described below), or you can specify a format expression.

Like a database view, an outview can combine data from several types into a single output type.  In the following example, DNAL types Person and PersonProfile are exported to a PersonDTO view type.

outview Person as p, Profile as pf -> CustomerDTO { 
  p.firstName -> fName string,
  p.lastName -> lName string,
  pf.accountLevel -> level int
}

In Java, use a ViewRenderer to render a DValue to a outview.  The render method produces a new DValue whose type is a DViewType.  In the above example, it would represent a CustomerDTO view that has fields fName, lName, and level.

inview

An inview is used to convert input data that may have different field names and types.

inview Person <- PersonDTO { 
  firstName <- fName string,
  lastName <- lName string,
  birthDate <- birthDate string format('yyyy-mm-dd'),
  id <- customerId int
}

Note that inviews use “<-” and outviews use “->”.

Automatic Conversions

DNAL performs the following conversions automatically

Source Type

Destination Type

boolean

boolean, string

int

int, long, number, string

long

int, long, number, string

number

int, long, number, string

date

long, date, string

list

no automatic conversions are supported

struct

no automatic conversions are supported

enum

string