# How to get the 'connection-token' to connect to JsonPowerDB in your program / code :
# JsonPowerDB - Easiest Way to store and retrieve HTML Form Data
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="http://login2explore.com/jpdb/resources/js/jpdb-commons.js"></script>
<form id="RegisterForm" method="post"
data-connection-token="your-connection-token"
data-db-name="MyDatabase"
data-table-name="MyUsers"
data-success-msg="Thanks for Registering"
data-error-msg="Data NOT submited."
onsubmit="return insertFormData2JPDB(this.id);">
# Create - This session is to practice on how to add HTML form data into database.
var connToken = "connection-token";
,
modify this with your 'connection-token' taken from JPDB dashboard and save it with any file-name and extenstion '.html'.Use of 'jpdb-commons.js' Javascript library to speedup the development.
<script src="http://login2explore.com/jpdb/resources/js/jpdb-commons.js"></script>
Below code snippet defines the JPDB API end point used for manipulating the data i.e. Index Manipulation Language (iml).
var apiBaseUrl = "http://api.login2explore.com:5577"; // API Base URL
var imlPartUrl = "/api/iml"; // API End-Point Part URL
Variables to be defined with your choice of database name and relation name.
// TBD Change the dbName and relName with your choice of database name and relation name.
var dbName = "company_db";
var relName = "emp_rel";
Following Javascript methods are created to make this example page working.
//To Set api base Url so that user can locate its data to baseUrl of another JPDB instance
function setBaseUrl(apiBaseUrl);
// Send data to JPDB instance for inserting in the give relation for the user database.
function mySave() {... }
// Initializes form data to default values
function resetFormData() {... }
// Restore form field focus to first field.
function resetFocus() {... }
This line will set the apiBaseUrl to the Url which you wants to set.
setBaseUrl(apiBaseUrl);
This line will read the form data and convert it to Json object.
var formDataInJson = getFormDataInJson($form);
Connection token is required to call the JPDB API. Replace 'connection-token' with your connection-token taken from JPDB dashboard.
var connToken = "connection-token";
Creates a PUT json request.
var putReq = createPUTRequest(connToken, jsonObj, dbName, relName);
Ajax (POST) call to JPDB API with the given json request.
var respJson = executeCommand(putReq, imlPartUrl);
# Retrieve - This session is to practice on how to retrieve data from database.
Following Javascript methods are created to make this example page working.
// Retrieve an employee record based on Employee ID.
function getEmployee() {... }
// Get next record details from JsonPowerDB database
function getNextRecord() {... }
// Get previous record details from JsonPowerDB database
function getPrevRecord() {... }
// Get first record details from JsonPowerDB database
function getFirstRecord() {... }
// Get last record details from JsonPowerDB database
function getLastRecord() {... }
// Set and display data in the form
function setDataInFormFields(respRecordJson) {... }
Creates a FIND_RECORD json request.
var getFindRecordReq = createFIND_RECORDRequest(connToken, dbName, relName, jsonObj);
Creates a NEXT_RECORD json request.
var getNextRecordReq = createNEXT_RECORDRequest(connToken, dbName, relName, recordNumber);
Creates a PREV_RECORD json request.
var getPreviousRecordReq = createPREV_RECORDRequest(connToken, dbName, relName, recordNumber);
Creates a FIRST_RECORD json request.
var getFirstRecordReq = createFIRST_RECORDRequest(connToken, dbName, relName);
Creates a LAST_RECORD json request.
var getLastRecordReq = createLAST_RECORDRequest(connToken, dbName, relName);
var connToken = "connection-token";
and
modify this with your connection-token taken from JPDB dashboard.Following Javascript methods are created to make this example page working.
// Set a page when a particular button is clicked.
function setPage(buttonId) {... }
// Managing enable or disable buttons as per displayed page
function buttonDisabled() {... }
// Get all data from JPDB database according to the page number and page size.
function getPage(pageNo, pageSize){... }
// Create table heading
function createTableHeader(dataColumn){... }
// Create table rows and table data columns according to the requested page number and page size.
function createTableRows(jsonArrayData, dataColumn){... }
Creates a GETALLCOL json request.
var getReqCol = createGETALLCOLRequest(connToken, dbName, relName);
Creates a GETALL json request.
var getReqData = createGETALLRequest(connToken, dbName, relName, pageNo, pageSize);
# Delete - This session is to practice on how to delete data from JsonPowerDB.
Following Javascript method created to make this example page working.
// Delete a particular record when delete button is clicked.
function deleteRecord(reqId) {... }
Creates a REMOVE json request.
var getRemoveRequest = createREMOVERecordRequest(connToken, dbName, relName, reqId);
# Update - This session is to practice on how to update data in JsonPowerDB.
The following code is having an edit button which will redirect you to ' Edit Employee ' page and remaining code is same as ' Retrieve Multiple Record with Delete Operation '.
Create a another HTML file and copy the following code to edit / update the employee details.
Following Javascript methods are created in Edit Employee Page.
// Get Record Number from URL.
function getRecordNumber() {... }
// Get record details of a particular record number.
function getRecordDetails() {... }
// Get the record details from local storage in case of cancel update.
function getDataOnCancelEvent() {... }
// Update a particular record details in the JPDB database.
function updateRecord() {... }
// Get the form data and check whether any changes occur or not.
function getChangedFormDataInJson($form) {... }
Creates a GET_RECORD json request.
var getReqRecord = createGET_RECORDRequest(connToken, dbName, relName, recordNumber);
Creates a UPDATE json request.
var getReqUpadateRecord = createUPDATERecordRequest(connToken, formJsonStr, dbName, relName, recordNumber);
# Create - Advance - Example code to manage unique key while inserting new data
Following Javascript methods are created to make this example page working.
// Check whether a particular record is exist or not in JSONPowerDB database.
function checkExistingData() {... }
Creates a FIND_RECORD json request.
var getReqData = createFIND_RECORDRequest(connToken, dbName, relName, dataObj);
Department (dpt_id(String), dpt_name(String), dpt_manager_emp_idl(long))
Employee (emp_id(String), emp_name(String), emp_sex((String)), emp_dsg(String), emp_basic(long), emp_allowance(double), emp_ded(double), emp_net(double), emp_lead_id(String), emp_dpt_id(String))
Projects (prj_id(String), prj_name(String), prj_start_date(String), is_prj_active(String), prj_rmk(String), prj_mgr_emp_id(String) )
ProjectEmployee (prj_id(String), emp_id(String), emp_hrs(long))
{"dpt_id":"00H", "dpt_name":"HR", "dpt_manager_emp_idl":109},
{"dpt_id":"00J", "dpt_name":"JAVA", "dpt_manager_emp_idl":101},
{"dpt_id":"00P", "dpt_name":"PHP", "dpt_manager_emp_idl":101},
{"dpt_id":"00U", "dpt_name":"UI", "dpt_manager_emp_idl":101},
{"dpt_id":"00A", "dpt_name":"ACCOUNTS", "dpt_manager_emp_idl":115},
{"dpt_id":"00OP", "dpt_name":"OPERATIONS", "dpt_manager_emp_idl":105},
{"dpt_id":"00Q", "dpt_name":"QA", "dpt_manager_emp_idl":101}
{"emp_id":"119", "emp_name":"MONALI LALWANI", "emp_sex":"M", "emp_dsg":"php developer", "emp_basic":15000, "emp_allowance":1500.0, "emp_ded":0.0, "emp_net":0.0, "emp_lead_id":"102", "emp_dpt_id":"00P"},
{"emp_id":"120", "emp_name":"SOURBH SHARMA", "emp_sex":"M", "emp_dsg":"java developer", "emp_basic":20000, "emp_allowance":2000.0, "emp_ded":0.0, "emp_net":0.0, "emp_lead_id":"106", "emp_dpt_id":"00J"},
{"emp_id":"101", "emp_name":"ARPIT TODEWALE", "emp_sex":"M", "emp_dsg":"Technical head java", "emp_basic":25000, "emp_allowance":2500.0, "emp_ded":0.0, "emp_net":0.0, "emp_lead_id":"105", "emp_dpt_id":"00J"},
{"emp_id":"102", "emp_name":"SANJAY VERMA", "emp_sex":"M", "emp_dsg":"php developer lead", "emp_basic":25000, "emp_allowance":2500.0, "emp_ded":0.0, "emp_net":0.0, "emp_lead_id":"101", "emp_dpt_id":"00P"},
{"emp_id":"103", "emp_name":"SALONI PATNI", "emp_sex":"F", "emp_dsg":"QA lead", "emp_basic":20000, "emp_allowance":2000.0, "emp_ded":0.0, "emp_net":0.0, "emp_lead_id":"101", "emp_dpt_id":"00Q"},
{"emp_id":"104", "emp_name":"DEEPAK PAL", "emp_sex":"M", "emp_dsg":"UI developer", "emp_basic":15000, "emp_allowance":1500.0, "emp_ded":0.0, "emp_net":0.0, "emp_lead_id":"112", "emp_dpt_id":"00U"},
{"emp_id":"105", "emp_name":"ARPIT SHARMA", "emp_sex":"M", "emp_dsg":"CEO", "emp_basic":40000, "emp_allowance":4000.0, "emp_ded":0.0, "emp_net":0.0, "emp_lead_id":"", "emp_dpt_id":"00OP"},
{"emp_id":"106", "emp_name":"RAHUL GUPTA", "emp_sex":"M", "emp_dsg":"java developer lead", "emp_basic":25000, "emp_allowance":2500.0, "emp_ded":0.0, "emp_net":0.0, "emp_lead_id":"101", "emp_dpt_id":"00J"},
{"emp_id":"107", "emp_name":"ADITI PHADNIS", "emp_sex":"F", "emp_dsg":"HR", "emp_basic":20000, "emp_allowance":2000.0, "emp_ded":0.0, "emp_net":0.0, "emp_lead_id":"109", "emp_dpt_id":"00H"},
{"emp_id":"108", "emp_name":"SURABHI ARYA", "emp_sex":"F", "emp_dsg":"java developer", "emp_basic":20000, "emp_allowance":2000.0, "emp_ded":0.0, "emp_net":0.0, "emp_lead_id":"106", "emp_dpt_id":"00J"},
{"emp_id":"109", "emp_name":"ABHISHEK TRIPATHI", "emp_sex":"M", "emp_dsg":"HR manager", "emp_basic":25000, "emp_allowance":2500.0, "emp_ded":0.0, "emp_net":0.0, "emp_lead_id":"105", "emp_dpt_id":"00H"},
{"emp_id":"110", "emp_name":"MUKUND JHA", "emp_sex":"M", "emp_dsg":"Operator", "emp_basic":15000, "emp_allowance":1500.0, "emp_ded":0.0, "emp_net":0.0, "emp_lead_id":"105", "emp_dpt_id":"00OP"},
{"emp_id":"111", "emp_name":"PRITHVIRAJ PRAMANIK", "emp_sex":"M", "emp_dsg":"java developer", "emp_basic":20000, "emp_allowance":2000.0, "emp_ded":0.0, "emp_net":0.0, "emp_lead_id":"106", "emp_dpt_id":"00J"},
{"emp_id":"112", "emp_name":"ANISHA TULIKA", "emp_sex":"F", "emp_dsg":"UI designer", "emp_basic":15000, "emp_allowance":1500.0, "emp_ded":0.0, "emp_net":0.0, "emp_lead_id":"101", "emp_dpt_id":"00U"},
{"emp_id":"113", "emp_name":"AKSHITA SINGH", "emp_sex":"F", "emp_dsg":"php developer", "emp_basic":20000, "emp_allowance":2000.0, "emp_ded":0.0, "emp_net":0.0, "emp_lead_id":"102", "emp_dpt_id":"00P"},
{"emp_id":"114", "emp_name":"BHAWNA ARORA", "emp_sex":"F", "emp_dsg":"QA", "emp_basic":15000, "emp_allowance":1500.0, "emp_ded":0.0, "emp_net":0.0, "emp_lead_id":"103", "emp_dpt_id":"00Q"},
{"emp_id":"115", "emp_name":"SHRADDHA SHARMA", "emp_sex":"F", "emp_dsg":"Accountant manager", "emp_basic":25000, "emp_allowance":2500.0, "emp_ded":0.0, "emp_net":0.0, "emp_lead_id":"105", "emp_dpt_id":"00A"},
{"emp_id":"116", "emp_name":"RAJEEV JOSHI", "emp_sex":"M", "emp_dsg":"java developer", "emp_basic":20000, "emp_allowance":2000.0, "emp_ded":0.0, "emp_net":0.0, "emp_lead_id":"106", "emp_dpt_id":"00J"},
{"emp_id":"117", "emp_name":"SNEHASHISH DAS", "emp_sex":"M", "emp_dsg":"junior php dev", "emp_basic":10000, "emp_allowance":1000.0, "emp_ded":0.0, "emp_net":0.0, "emp_lead_id":"102", "emp_dpt_id":"00P"}
{"prj_id":"1L", "prj_name":"Library management system", "prj_start_date":"01/01/2018", "is_prj_active":"true", "prj_rmk":"Project on schedule", "prj_mgr_emp_id":"106"},
{"prj_id":"2HT", "prj_name":"Hotel management system", "prj_start_date":"08/11/2017", "is_prj_active":"true", "prj_rmk":"Project under testing", "prj_mgr_emp_id":"102"},
{"prj_id":"3HP", "prj_name":"Hospital management system", "prj_start_date":"27/06/2017", "is_prj_active":"true", "prj_rmk":"Project behind schedule", "prj_mgr_emp_id":"106"},
{"prj_id":"4B", "prj_name":"Banking management system", "prj_start_date":"09/08/2017", "is_prj_active":"true", "prj_rmk":"Project on schedule", "prj_mgr_emp_id":"102"},
{"prj_id":"5I", "prj_name":"Inventory management system", "prj_start_date":"15/06/2016", "is_prj_active":"false", "prj_rmk":"Project completed", "prj_mgr_emp_id":"106"}
{"prj_id":"1L", "emp_id":"106", "emp_hrs":7},
{"prj_id":"1L", "emp_id":"102", "emp_hrs":8},
{"prj_id":"1L", "emp_id":"120", "emp_hrs":8},
{"prj_id":"1L", "emp_id":"119", "emp_hrs":7},
{"prj_id":"2HT", "emp_id":"106", "emp_hrs":5},
{"prj_id":"2HT", "emp_id":"108", "emp_hrs":7},
{"prj_id":"2HT", "emp_id":"102", "emp_hrs":8},
{"prj_id":"2HT", "emp_id":"113", "emp_hrs":7},
{"prj_id":"3HP", "emp_id":"111", "emp_hrs":8},
{"prj_id":"3HP", "emp_id":"106", "emp_hrs":7},
{"prj_id":"3HP", "emp_id":"102", "emp_hrs":8},
{"prj_id":"4B", "emp_id":"106", "emp_hrs":5},
{"prj_id":"4B", "emp_id":"116", "emp_hrs":5},
{"prj_id":"4B", "emp_id":"117", "emp_hrs":7},
{"prj_id":"4B", "emp_id":"118", "emp_hrs":8},
{"prj_id":"4B", "emp_id":"102", "emp_hrs":8},
{"prj_id":"5I", "emp_id":"106", "emp_hrs":5},
{"prj_id":"5I", "emp_id":"102", "emp_hrs":7}
# Insert sample data
# How to create NoSQL scripts (only in Dashboard) : Open user dashboard and click on the NoSQL and follow the following:
# How to execute NoSQL query and see results using Dashboard :
# Executing NoSQL Query from Program
Object projectActive = params.get("isActive");
ArrayList <Integer> proActiveArr = QueryService.get("Company","Projects","is_prj_active",projectActive,this);
finalQueryResult = QueryService.project("Company","Projects",proActiveArr, new String[]{"prj_name"},this);
{
"token": "-1167378244|1086969151789951602|-1167386760",
"cmd": "EXECUTE_SCRIPT",
"jsonStr": {
"scriptName": "display_active_project_name",
"scriptParams":{"isActive":"true"}
}
}
Object empLead = params.get("leadId");
ArrayList <Integer> empDetails = QueryService.get("Company","Employee","emp_lead_id",empLead,this);
finalQueryResult = QueryService.project("Company","Employee",empDetails,new String[]{"emp_name"},this);
{
"token": "-1167378244|1086969151789951602|-1167386760",
"cmd": "EXECUTE_SCRIPT",
"jsonStr": {
"scriptName": "emp_name_answer_to_lead",
"scriptParams":{"leadId":"105"}
}
}
Object deptId = params.get("opDeptId");
ArrayList <Integer> empOopDeptDetails = QueryService.get("Company","Employee","emp_dpt_id",deptId,this);
finalQueryResult = QueryService.project("Company","Employee",empOopDeptDetails,new String[]{"emp_name","emp_dsg","emp_basic"},this);
{
"token": "-1167378244|1086969151789951602|-1167386760",
"cmd": "EXECUTE_SCRIPT",
"jsonStr": {
"scriptName": "operation_dept_emp_details",
"scriptParams":{"opDeptId":"00OP"}
}
}
Object empGender = params.get("empGender"); Object empDpt = params.get("empDepartment"); ArrayList <Integer> empGenderArr = QueryService.get("Company", "Employee", "emp_sex", empGender,this);
ArrayList <Integer> empDptArr = QueryService.get("Company","Employee","emp_dpt_id",empDpt,this);
ArrayList<Integer> finalEmpNametList = SetOpUtils.intersection(empGenderArr, empDptArr); finalQueryResult = QueryService.project("Company", "Employee", finalEmpNametList, new String[]{"emp_dpt_id","emp_name"}, this);
{
"token": "-1167378244|1086969151789951602|-1167386760",
"cmd": "EXECUTE_SCRIPT",
"jsonStr": {
"scriptName": "name_java_male_employee",
"scriptParams":{"empGender":"M","empDepartment":"00J"}
}
}
Object empDpt1 = params.get("dpt1"); Object empDpt2 = params.get("dpt2"); ArrayList <Integer> empDpt1Details = QueryService.get("Company","Employee","emp_dpt_id",empDpt1,this);
ArrayList <Integer> empDpt2Details = QueryService.get("Company","Employee","emp_dpt_id",empDpt2,this);
ArrayList <Integer> finalEmpNametList = SetOpUtils.union(empDpt1Details, empDpt2Details); finalQueryResult = QueryService.project("Company", "Employee", finalEmpNametList, new String[]{"emp_dpt_id","emp_name"}, this);
{
"token": "-1167378244|1086969151789951602|-1167386760",
"cmd": "EXECUTE_SCRIPT",
"jsonStr": {
"scriptName": "all_emp_name_in_account_operation_dept",
"scriptParams":{"dpt2":"00OP","dpt1":"00A"}
}
}
int totalRec = QueryService.getFileSize("Company","Department",this); ArrayList <Integer> idList = QueryService.getAll("Company","Department","dpt_id","","zzz",totalRec, this);
for(int i=0; i< idList.size();i++){ JSONObject finalRowJSONObj = new JSONObject(); Record rec = QueryService.get("Company","Department",idList.get(i),this); JSONObject empJsonObj = rec.getJsonObject(); finalRowJSONObj.put("managerId", empJsonObj.get("dpt_manager_emp_idl")); finalRowJSONObj.put("deptName", empJsonObj.get ("dpt_name")); String managerEmpId = (String)empJsonObj.get("dpt_manager_emp_idl").toString(); ArrayList <Integer> empDetailsList = QueryService.get("Company","Employee","emp_id",managerEmpId,this); Record empRecDetails = QueryService.get("Company","Employee", empDetailsList.get(0),this); JSONObject empRecJsonObj = empRecDetails.getJsonObject(); finalRowJSONObj.put("managerName ", empRecJsonObj.get("emp_name")); finalQueryResult.addRecord(new Record(new Row(i,finalRowJSONObj))); }
{
"token": "-1167378247|1086969151769521885|-1167389995",
"cmd": "EXECUTE_SCRIPT",
"jsonStr": {
"scriptName": "manager_name_with_dept_name",
"scriptParams":
}
}