API Download
The source code for the JavaScript 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:create_type() 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:
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 & tutorial.js references in the tutorial.html file point to the correct location of the Kinetica Javascript API library & tutorial script files, respectively—(the default assumes all three files are co-located in a browser-accessible location). Then, open the tutorial.html file in a browser, passing the Kinetica URL, as well as optional username/password credentials for the server as URL parameters:As this script creates a schema and several database objects within
it, system admin permission is
required to run it.