N NezamDocumentation

Functions and services#

Functions express executable behavior. Services define integration-facing operations when a boundary should be explicit. Function declarations may include annotations, an optional access modifier, function modifiers, typed parameters with optional defaults, and an optional return type written with : or ->.

For the full syntax reference, see Function declarations.

Query functions#

Query functions select records and return JSON or typed records.

bl
@http(GET)
function get_vendors(
  company_code_param: CompanyCode,
  limiter: limiter
): Json {
  select *
  from Vendor
  where Vendor.company_code = company_code_param
    and Vendor.active = true
  order by vendor_name, vendor_id
  with limiter limiter;
}

Query functions may also use expression-bodied syntax for query statements.

bl
function active_vendors(company_code_param: CompanyCode): Json =>
  select *
  from Vendor
  where Vendor.company_code = company_code_param
    and Vendor.active = true;

Command functions#

Command functions load state, validate inputs, update records, and save only after the replacement state is valid.

bl
public function deactivate_vendor(vendor_id_param: VendorId): Vendor? {
  let vendor = await get_vendor(vendor_id_param);
  if (vendor is null) {
    return null;
  }

  vendor.active = false;
  save vendor;
  return vendor;
}

Function bodies can be block bodies, abstract semicolon declarations, fat-arrow statement bodies, or fat-arrow expression bodies. Fat-arrow query bodies support query statements and delete query statements directly.

bl
function vendor_count(company_code_param: CompanyCode): int =>
  count_vendors(company_code_param);

function remove_vendor(vendor_id_param: VendorId) =>
  delete from Vendor
  where Vendor.vendor_id == vendor_id_param;

Functions may be nested inside function bodies when helper behavior is local to the enclosing function.

Atomic update rule#

Validate replacement input before clearing or overwriting existing valid state. Failed updates should preserve runtime state.

HTTP annotations#

Use @http(GET) for read operations and reserve mutating verbs for commands that change state.

Source: packages/business/language/functions-services.md