Jint: Difference between revisions

From Data Islands
No edit summary
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 10: Line 10:


>di.status()
>di.status()
>di.deleteisland('ISLANDNAME')


----
----
Line 74: Line 76:
var table = di.querydb("select * from customers");
var table = di.querydb("select * from customers");


'''table.AddColumn("SomeCustomfield");'''
'''table.Columns.Add("SomeCustomfield");'''
   
   
'''///adds a column to the dataset'''
'''///adds a column to the dataset'''
Line 93: Line 95:


};
};
----Comments in code
Single line comments only are supported and they must be on their own line.
Not working
var x=2;//set x to 2
working
//set x to 2
var x=2;
and not working
/*
multiline comments
are not supported
<nowiki>*</nowiki>/
----
All commands

Latest revision as of 13:37, 12 January 2024

Syntax : jint "<OBJECT NAME>" <ENTER>

Description : Jint command will be used to initialize Javascript Object which we can use to perform available commands same as Javascript syntax.

For eg.

>jint di

>di.islands()

>di.status()

>di.deleteisland('ISLANDNAME')



You can write and run javascript commands (and scripts in ,js files) allowing you to code iteratation over a dataset (querydb), alter the data (in a csv for example) and automate region creation and various other commands.


The command is

>jint

to switch into javascript coding mode.

You can write a js file and execute using the file path parameter

> jint "pathtofile/file.js"


Here is a sample script that queries a "customers" table for any customers that have a flag set and then for each of those it creates a data island "region" and pushes up the customers "orders" to an island.


var result = di.connect("youraccount","yourpassword");

var table = di.querydb("select top 2 * from customers where hasregionflag='Y'");

for(var x=0;x<table.Rows.Count;x++)

{

   var fieldValue = table.Rows[x]['CustomerID'];

   di.addregion(fieldValue);

   var qorders=di.querydb("select * from Orders where customerid='"+fieldValue+"'");

   di.push("orders");

}


'''More Examples'''

a. Accessing Column names

var table = di.querydb("select top 2 * from customers where hasregionflag='Y'");

for(var x=0;x<table.Columns.Count;x++)

{

   var _colName= table.Columns[x].ColumnName;

di.display("colname="+_colName);

}


b. Altering data before pushing - you can add a column and alter existing

var table = di.querydb("select * from customers");

table.Columns.Add("SomeCustomfield");

///adds a column to the dataset

for(var x=0;x<table.Rows.Count;x++) {

var fieldValueID = table.Rows[x]['CustomerID'];

var fieldValueCode = table.Rows[x]['CustomerCode'];

table.Rows[x]['SomeCustomfield']=fieldValueID+fieldValueCode; //composite field

}

///pass in the altered dataset

di.push("customers", table);

};


Comments in code

Single line comments only are supported and they must be on their own line.

Not working

var x=2;//set x to 2

working

//set x to 2

var x=2;

and not working

/*

multiline comments

are not supported

*/


All commands