1.2.2 • Published 3 years ago

akera-api v1.2.2

Weekly downloads
-
License
SEE LICENSE IN <L...
Repository
-
Last release
3 years ago

Akera Logo

Application Programming Library for Akera.io application server.

Installation

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

Docs

Tests

To run the test suite, first install the dependencies, then run npm test:

$ npm install
$ npm test

Quick Start

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

Connect to an application server:

	var akera = require('../index.js');
	
	var server = {
	    host : '10.10.10.6',
	    port : 38900
	  };

	akera.connect(server.host, server.port).then(function(conn) {
	  return conn;
	});

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:

	var p = akera.call.parameter;

  conn.call.procedure('test/call-test.p')
  			.parameters(p.input(123),
            			p.output('character'), 
            			p.output('date'),
            			p.inout('hello', 'character'))
          .run().then(function(result) {
          
          console.log(result);
          // close the connection
          conn.disconnect().then(function () {
            console.log('done');
          });
  });

Run an internal function defined inside a procedure library:

	var p = akera.call.parameter;

  conn.call.dynamic_function('test/call-test-ip.p', 'testFunc', 'date')
  			.parameters(p.input(123),
            			p.inout('hello', 'character'))
          .run().then(function(result) {
          
          console.log(result);
          // close the connection
          conn.disconnect().then(function () {
            console.log('done');
          });
  });

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.

    		var f = akera.query.filter;
    
      conn.query.select('customer').fields('custnum', 'name')
      		.where(f.eq('balance', 1000))
      		.offset(3)
      		.limit(5)
      		.all().then(function(result) {
      		console.log(result.name + '[' + result.custnum + ']');
      }, function (err) {
      		console.log(err);
      });

    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.

    		var f = akera.query.filter;
    
      conn.query.select('customer').fields('custnum', 'name')
      		.where(f.eq('state', 'AK'))
      		.each('order').fields('*')
      		.join('customer').on('custnum')
      		.where(f.or(f.eq('orderstatus', 'ordered'), f.eq('orderstatus', 'back ordered')))
      		.all().then(function(result) {
      		console.log(result.customer.name + result.order.OrderDate);
      }, function (err) {
      		console.log(err);
      });

    Find the first back order.

    		var f = akera.query.filter;
    
      conn.query.find('order', 'first').fields('*')
      		.where(f.eq('orderstatus', 'back ordered'))
      		.fetch().then(function(result) {
      		console.log(result);
      }, function (err) {
      		console.log('No back order found');
      });

    Create a new customer call record.

      conn.query.insert('refcall').
      		.set({
          		custnum: 666,
          		salesrep: 'medu',
          		txt: 'hello world'
        		})
        	.fetch().then(function(result) {
      		console.log(result);
      }, function (err) {
      		console.log(err);
      });

    Update the customer call record.

    		var f = akera.query.filter;
    	
      conn.query.update('refcall').
      		.where(f.and(f.eq('custnum', 666), f.eq('salesrep', 'medu'))
      		.set({
          		custnum: 666,
          		salesrep: 'medu',
          		txt: 'hello wonderful world'
        		})
        	.fetch().then(function(result) {
      		console.log(result);
      }, function (err) {
      		console.log(err);
      });

    Delete the customer call record.

    		var f = akera.query.filter;
    	
      conn.query.destroy('refcall').
      		.where(f.eq('custnum', 666))
      		.go().then(function(affected) {
      		console.log('Number of records deleted: ' + affected);
      }, function (err) {
      		console.log(err);
      });

License

Copyright (c) 2015 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.