Ninox language basics

Ninox's scripting language is used to write the formulas, buttons and triggers of your databases. This page gathers what you need to know before writing your first lines.

Ninox is a typed and precompiled language. This means that the data types handled by the language are known in advance, unlike other languages such as JavaScript, which can handle variables without knowing their types.

One of the major advantages of Ninox is that the code it generates is particularly reliable, with malfunctions occurring only on very rare occasions.

For your information, Ninox script is compiled into JavaScript before being executed.

Nested and Linear Code

Each function or statement returns a value that can be directly passed as a parameter to another function or statement:

Ninox
var a := format(now(), "DD/MM/YYYY");

Thus, it is possible to assign a set of nested code to a variable:

Ninox
var a := true;
var b := if a then "true" else "false";

It is also possible to assign to b the result of a block of linear code enclosed in parentheses:

Ninox
var b := (
    var a := true;
    if a then "true" else "false" end
);

It is important to keep in mind that, in the case of linear code, the last line always determines the type and value returned. In this example, b will be equal to 10:

Ninox
var b := (
    var a := true;
    if a then "true" else "false" end;
    10
);

This block is written in parentheses, not between do and end like the body of a loop or a function. The following code is rejected as soon as it is written ("Symbol expected: as"):

Ninox
var b := do
    var a := true;
    if a then "true" else "false" end
end;

do … end opens a block only after for … in … do, while … do or function f(…) do. Everywhere else (at the start of a formula, after :=, after then…), do announces do as server, do as transaction…: Ninox then expects the word as.

Warning

Sent through the API (/query), a query that starts with do without as returns null, without any error message. The trap shows up when writing a test query: (var n := 2; n) returns 2, do var n := 2; n end returns nothing.

(Measured through the Ninox API.)

Methods

Methods are functions that take one or more parameters and return a value. Both the parameters and the return value are predefined.

Some methods can have multiple parameter configurations:

  • date(year, month, day)
    Returns a date value.
  • date(myTimeValue)
    Converts a given time-related value to a date value. If the value is a number, it represents the Unix time in milliseconds.

Refer to the official Ninox documentation for a complete list of methods and their classification by category.

Instructions

var, if then else, for, switch, select where, etc., are instructions.

Unlike methods, the return types of instructions depend on the code they contain. For example, the following code will return an array of numbers [1, 2]:

Ninox
for i in range(1,3) do
  i;
end;