Data Management

Speedier Interactions With Actian Zen From Node.js

Actian Corporation

October 15, 2020

Actian Zen

Make Faster Calls Using the High-Speed Btrieve 2 API

Developers building real-time, data-intensive edge applications are increasingly turning to Node.js. It’s not in itself a programming language but an open-source, multi-platform, run-time environment that leverages JavaScript and its ecosystem — and turns out to be quite well suited for today’s data streaming and JSON API applications.

If you’re using Actian Zen as your edge data management platform — and naturally we think you should — you’ll find that Node.js pairs well with Zen. However, there’s more than one way to pair them. You can easily interact with Actian Zen from Node.js using SQL via ODBC, for example, and when the complexity of your interactions warrants the use of SQL that’s a perfect option.

But SQL via ODBC isn’t the fastest way to interact with Zen, and when you need speed there’s a better option: From Node.js you can access Zen data via the Btrieve 2 API. Let’s talk conceptually about how you can do this, and then we’ll dive into the practicalities of doing this. You’ll need certain software components to facilitate interaction with the Btrieve 2 API – including PHP, Python3, C++, and a few others that are easily downloaded – but let’s skip over the setup for now and focus on how you can speed up access to the Zen data you need.

Using the Btrieve 2 API

Conceptually, your JavaScript program is going to push a call through a special Node.js interface to the Btrieve 2 API, which is a C++ library that interacts directly with the Zen database engine.

From the standpoint of a JavaScript program, the interactions are relatively straightforward. Here’s the procedural logic:

  • Define the libraries and components to be loaded.
  • Set up and variables to be used.
  • Define the name, location, and record characteristics of the data file to hold the results of a query.
  • Instantiate an instance of the BtrieveClient class used for performing engine-wide operations such as creating and deleting files and opening and closing files.
  • Prepare information defining the key segment.
  • Set the created key segment information into the index attribute.
  • Create a file attributes object and set the fixed record length.
  • Create a new Btrieve file based on the information set (BtrieveFile object is a class that handles Btrieve data files).
  • Open the file.
  • Perform the database operations that your application requires.
  • Close the Btrieve File.

You can download a sample .js file here that will enable you to see the logic in action. Performatively, the 43-line sample application creates a Btrieve file and populates it with 10,000 10-byte records (each record consisting of an 8-byte timestamp and a 2-byte integer that, in this instance, might represent input from, say, an IoT sensor). The sample program also stores for later use the timestamp index for every 200th record and, ultimately, extracts the last written record from the data file and displays the value recorded in that record. Naturally, your use case may be far more involved but you’ll see how easy it is to create the JavaScript that will provide a high-performance interaction with Zen.

Putting the Sample Through its Paces

Care to run the aforementioned .js file to experience the performance of the Btrieve 2 API?  There’s a more detailed Application Note that walks you through the steps to do so. So give it a try! Net-net, Node.js and Zen can provide a powerful array of options when it comes to developing mobile and IoT applications.

About Actian Corporation

Actian is helping businesses build a bridge to a data-defined future. We’re doing this by delivering scalable cloud technologies while protecting customers’ investments in existing platforms. Our patented technology has enabled us to maintain a 10-20X performance edge against competitors large and small in the mission-critical data management market. The most data-intensive enterprises in financial services, retail, telecommunications, media, healthcare and manufacturing trust Actian to solve their toughest data challenges.