Options
All
  • Public
  • Public/Protected
  • All
Menu

Akera Api

Akera Logo

Application Programming Library for Akera.io application server.

Installation

$ npm set registry "http://repository.akera.io/"
$ npm install @akera/api

Docs

Quick Start

All asynchronous functions in Akera API returns a promise, those can be chained one to another if needed.

Connect to an akera.io application server:

  import * as akera from '@akera/api';

  akera.connect('localhost', 8900).then(async (conn) => {
    // list information about the connected databases
    for (let db of await conn.catalog.getDatabases()) {
        console.log('database', db.name, db.lname, db.version);
    }

    return conn.disconnect();
  });

The API allows one to access Progress application business logic by using the 'call' interface from connection object. This have two separate parts, a static one that serves as a builder using the fluent syntax and second that executes the statement built.

Run an external procedure:

  let ret = await conn.run(
        BusinessLogic.procedure('demo/api/tellError.p')
            .input(1024)
            .output(DataType.CHARACTER)
            .output(DataType.LONGCHAR)
            .build(), 2000);

  console.log(ret.parameters[0], ret.parameters[1]);

Run an internal function defined inside a procedure library:

  let ret = await conn.run(
        BusinessLogic.internal_function('demo/test/call-test-ip.p', 'testFunc', DataType.DATE)
            .input(1024)
            .inout(DataType.CHARACTER, 'hello')
            .build(), 2000);

  console.log(ret.parameters[0], ret.return);

Basic CRUD database access is available using the ‘query' interface from connection object. Same as for the call interface this also have two separate parts, a static one that serves as a builder using the fluent syntax and second that executes the statement built.

The following functionality is available through the query interface:

  • select records: multiple tables, joins, filter, sorting, paging
  • open query, same as select but the query allows sequential record access: next, previous, first, last, reposition
  • find: one table, unique/first/last
  • insert/upsert: returns rows data or number of affected rows
  • update: one or more tables, returns rows data or number of affected rows
  • delete: one or more tables in query, delete only from first buffer

    Select five customer's records with balance lower than 1000 starting from 3'rd record from Sports2000 database.

    let rows = await connection.query.select('customer', { Balance: {lt: 1000} })
                    .fields('Name', 'CustNum', 'Balance')
                    .setOffset(3)
                    .setLimit(5).all();
    
    for (let row of rows) {
      // row contains only customer data
      console.log(row['Name'], row['Balance']);
    }
    

    Select Alaska customer's orders not shipped, note that when data is selected from multiple tables fields from each table is grouped inside the result object using the table name.

    let rows = await connection.query.select('customer', {State: 'AK'})
        .join('order', 'customer', SelectionMode.EACH).on('custnum')
        .filter({or: [{OrderStatus: 'ordered'}, {OrderStatus: 'back ordered'}]}).all();
    
    for (let row of rows) {
      // row contains both customer and order data
      console.log(row['customer']['Name'], row['order']['OrderDate']);
    }
    

    Find the first back order.

    let order = await connection.catalog.getTable('order');
    try {
      let border = await refcall.find({OrderStatus: 'back ordered'}, FindMode.FIRST);
    
      console.log('First back order record: ' + callbuf.record);
    } catch (err) {
      console.log('No back order record found.');
    }
    

    Create a new customer call record.

    let refcall = await connection.catalog.getTable('refcall');
    let newcall = await refcall.create({CustNum: 666,
                                        SalesRep: 'akera', 
                                        Txt: 'hello world'});
    
    console.log('New record: ' + newcall.record);
    

    Update all call records where customer number is less than 100.

    let refcall = await connection.catalog.getTable('refcall');
    let affected = await refcall.update({SalesRep: 'akera', Txt: 'hello world'}, //values
                                        {CustNum: {lt: 100}} // filter clause
                                        );
    
    console.log('Number of records updated: ' + affected);
    

    Delete all call records for the customer with number 100.

    let refcall = await connection.catalog.getTable('refcall');
    let affected = await refcall.delete({CustNum: 100});
    
    console.log('Number of records deleted: ' + affected);
    

License

Copyright (c) 2015-2018 ACORN IT, Romania - All rights reserved

This Software is protected by copyright law and international treaties. This Software is licensed (not sold), 
and its use is subject to a valid WRITTEN AND SIGNED License Agreement. The unauthorized use, copying or 
distribution of this Software may result in severe criminal or civil penalties, and will be prosecuted to the 
maximum extent allowed by law.