API Download
The source code for the Node.js API is available for download from the GitHub repository kineticadb/kinetica-api-javascript. Follow the instructions in the included README file to use the API library.Connecting to the Database
To connect to the database, instantiate an object of the GPUdb class, providing the connection URL, including host & port of the database server as well as an optional username & password for secure connections:Loading Data
Before any data can be loaded into the system, a Type needs to be defined in the system. The type definition is a JSON string describing the fields (i.e. columns) of the type along with a name for the type. Each field consists of a name and a data type:Type.create() call contains a unique type
identifier allocated by the system. This identifier can then be used in the
request to create a new table as follows:
Retrieving Data
Once the table is populated with data, the data can be retrieved from the system by a call toget_records() as shown below:
offset and limit parameters. The returned response also contains
the schema (or data type) of the results.
Running Queries
To filter a subset of the records, use thefilter() method with an
expression as follows:
aggregate_group_by()
method as shown below. The next query shows how to get the count of records,
as well as the sum and average of the values of column col1, within each
group in group_id:
Download & Run
Included below is a complete example containing all the above requests, the data file, and output. To run the complete sample, ensure the GPUdb.js reference in the tutorial.js file points to the correct location of the Kinetica Node.js API library on your Kinetica instance (the default is to be co-located with the tutorial script); then switch to the directory containing tutorial.js and run the following, passing the Kinetica URL, and optionally, the credentials to authenticate to that instance:As this script creates a schema and several database objects within
it, system admin permission is
required to run it.