forked from snowaid/GQL
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial version from GQL blog https://t.co/6LjK5UrBSa
- Loading branch information
p16070
committed
Oct 28, 2016
1 parent
2127c62
commit 3cab251
Showing
9 changed files
with
448 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Generated files | ||
This repository contains generated files and a checksum. | ||
|
||
**Do not edit the files in this repository outside of an instance of ServiceNow.** | ||
|
||
If you find yourself unable to import your repository due to the presence of files edited outside an instance of ServiceNow, merge commits that mix files from different revisions, or other data that does not match the checksum, you may recover using either of the following techniques: | ||
* Remove the problem commits: | ||
1. Clone your repository to a personal computer with the git command line tools installed and open a git command prompt in the repository root | ||
2. Run `git log` and take note of the SHA1s of the problem commits | ||
3. Build revert commits using `git revert SHA1` repeatedly, working backward in time, for each commit that introduced changes not generated by a ServiceNow instance | ||
4. Run `git push` | ||
|
||
* Overwrite the problem code snapshot with a known good one: | ||
1. Clone your repository to a personal computer with the git command line tools installed and open a git command prompt in the repository root, | ||
2. Locate a known good code snapshot and record its SHA1. For this step, `git log` can be useful. | ||
2. Run `git reset --hard SHA1` to a commit that was generated by a ServiceNow instance | ||
3. Run `git reset HEAD{1}` | ||
4. Run `git add -A` | ||
5. Run `git commit` | ||
6. Run `git push` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
vo-b8trkiREqN6M4rJdH7rwsHG-7xwi82ZiLROe5qBg9uj0EUqK2NYWVq5lkUlk2U7_mXvAAMccPjEc3G5Sh1FLf3ZoCZ-98U66H3Nke8NoI0xPpazoEdFbcbBgBrxnMC0lXW2TlMUdXvtG-em2BLnjE3-ZKolXn6rbfvL_fr0PWjFN4Czgf3OcS0gdsYCqDDkjZ1Do59FwhsR6Iwh85eS_xe-ZZdgOKlGA851mUC7ffZkYJS9TSlZia6JLDdkHO_gNRhfJkJAuKWO5c62ft9ckucbBDDlCCfz_YBe31NoAna9oSi5pSzTrHzFgpl6eJvWL-29aWhz1nCUOeoPtly3CYmVGxtaLOXfy_r3paTqKs2COoU6wWoG5JRmBCQULGjgQNtN6LcEZSDiFX-q7a8j6bFnjDX2d9cSkHxlpjgUndAL1DecxKYDEfbh8xaFmNx-ShUfx1wQVQPMgP3_DHhS0ahcl4NGTmEM9yXyS9nL1TayySRRetKbqMdZgqoVkGdEvSeoMMfW5GWuTBkriO8fogvQyIwM51KIC7mDnTFtkXXyehMdOpcTgTKr3UBMhUhdFqii33PISs0qD29ZSJKpCVJ4dXeu2Xhbo7G8g2QpjEOo7gnrR2ajCoyrM6XB_ia84S3_8JTQ0hfAr0owhnJgLTQCRogBRb7lSA5DxkiUo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<record_update table="sys_app"> | ||
<sys_app action="INSERT_OR_UPDATE"> | ||
<active>true</active> | ||
<enforce_license>log</enforce_license> | ||
<js_level>helsinki_es5</js_level> | ||
<licensable>true</licensable> | ||
<logo/> | ||
<menu/> | ||
<name>gql</name> | ||
<private>false</private> | ||
<restrict_table_access>false</restrict_table_access> | ||
<runtime_access_tracking>permissive</runtime_access_tracking> | ||
<scope>x_64935_gql</scope> | ||
<scoped_administration>false</scoped_administration> | ||
<short_description/> | ||
<source>x_64935_gql</source> | ||
<store_correlation_id/> | ||
<store_url/> | ||
<sys_class_name>sys_app</sys_class_name> | ||
<sys_code/> | ||
<sys_created_by>john.chun</sys_created_by> | ||
<sys_created_on>2016-10-17 20:09:00</sys_created_on> | ||
<sys_id>a4d8ddd54f62a600463efd218110c731</sys_id> | ||
<sys_mod_count>1</sys_mod_count> | ||
<sys_updated_by>john.chun</sys_updated_by> | ||
<sys_updated_on>2016-10-21 01:00:56</sys_updated_on> | ||
<template/> | ||
<trackable>true</trackable> | ||
<user_role/> | ||
<vendor/> | ||
<vendor_prefix/> | ||
<version>0.1.0</version> | ||
</sys_app> | ||
</record_update> |
32 changes: 32 additions & 0 deletions
32
update/sys_app_application_b8fadd264fe6e600463efd218110c788.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<record_update sys_domain="global" table="sys_app_application"> | ||
<sys_app_application action="INSERT_OR_UPDATE"> | ||
<active>true</active> | ||
<category display_value="Custom Applications">e0355b31ef303000a61d5a3615c0fb78</category> | ||
<description>GQL (Glide Query Language) is a SQL-like query syntax for GlideRecords.</description> | ||
<device_type>browser</device_type> | ||
<hint>Glide Query Language</hint> | ||
<name/> | ||
<order>100</order> | ||
<roles>itil</roles> | ||
<sys_class_name>sys_app_application</sys_class_name> | ||
<sys_created_by>john.chun</sys_created_by> | ||
<sys_created_on>2016-10-21 17:32:29</sys_created_on> | ||
<sys_customer_update>true</sys_customer_update> | ||
<sys_domain>global</sys_domain> | ||
<sys_domain_path>/</sys_domain_path> | ||
<sys_id>b8fadd264fe6e600463efd218110c788</sys_id> | ||
<sys_mod_count>0</sys_mod_count> | ||
<sys_name>GQL</sys_name> | ||
<sys_overrides/> | ||
<sys_package display_value="gql" source="x_64935_gql">a4d8ddd54f62a600463efd218110c731</sys_package> | ||
<sys_policy/> | ||
<sys_replace_on_upgrade>false</sys_replace_on_upgrade> | ||
<sys_scope display_value="gql">a4d8ddd54f62a600463efd218110c731</sys_scope> | ||
<sys_update_name>sys_app_application_b8fadd264fe6e600463efd218110c788</sys_update_name> | ||
<sys_updated_by>john.chun</sys_updated_by> | ||
<sys_updated_on>2016-10-21 17:32:29</sys_updated_on> | ||
<title>GQL</title> | ||
<view_name/> | ||
</sys_app_application> | ||
</record_update> |
48 changes: 48 additions & 0 deletions
48
update/sys_app_module_f56b51664fe6e600463efd218110c7d4.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<record_update sys_domain="global" table="sys_app_module"> | ||
<sys_app_module action="INSERT_OR_UPDATE"> | ||
<active>true</active> | ||
<application display_value="GQL">b8fadd264fe6e600463efd218110c788</application> | ||
<assessment/> | ||
<content_page/> | ||
<device_type/> | ||
<filter/> | ||
<hint>Use GQL Pad to write and execute GQL scripts. The results can be viewed in various formats.</hint> | ||
<homepage/> | ||
<image/> | ||
<link_type>DIRECT</link_type> | ||
<map_page/> | ||
<mobile_title>GQL Pad</mobile_title> | ||
<mobile_view_name>Mobile</mobile_view_name> | ||
<name/> | ||
<order>100</order> | ||
<override_menu_roles>false</override_menu_roles> | ||
<query>x_64935_gql_pad.do</query> | ||
<report/> | ||
<roles>itil</roles> | ||
<survey/> | ||
<survey_overwrite>true</survey_overwrite> | ||
<sys_class_name>sys_app_module</sys_class_name> | ||
<sys_created_by>john.chun</sys_created_by> | ||
<sys_created_on>2016-10-21 17:37:25</sys_created_on> | ||
<sys_customer_update>true</sys_customer_update> | ||
<sys_domain>global</sys_domain> | ||
<sys_domain_path>/</sys_domain_path> | ||
<sys_id>f56b51664fe6e600463efd218110c7d4</sys_id> | ||
<sys_mod_count>2</sys_mod_count> | ||
<sys_name>GQL Pad</sys_name> | ||
<sys_overrides/> | ||
<sys_package display_value="gql" source="x_64935_gql">a4d8ddd54f62a600463efd218110c731</sys_package> | ||
<sys_policy/> | ||
<sys_replace_on_upgrade>false</sys_replace_on_upgrade> | ||
<sys_scope display_value="gql">a4d8ddd54f62a600463efd218110c731</sys_scope> | ||
<sys_update_name>sys_app_module_f56b51664fe6e600463efd218110c7d4</sys_update_name> | ||
<sys_updated_by>john.chun</sys_updated_by> | ||
<sys_updated_on>2016-10-21 17:44:15</sys_updated_on> | ||
<timeline_page/> | ||
<title>GQL Pad</title> | ||
<uncancelable>false</uncancelable> | ||
<view_name/> | ||
<window_name/> | ||
</sys_app_module> | ||
</record_update> |
114 changes: 114 additions & 0 deletions
114
update/sys_processor_3e0e24694f26a600463efd218110c7da.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<record_update table="sys_processor"> | ||
<sys_processor action="INSERT_OR_UPDATE"> | ||
<active>true</active> | ||
<class_name/> | ||
<description>GQL (Glide Query Language) Processor</description> | ||
<interactive>false</interactive> | ||
<name>GQL</name> | ||
<parameters/> | ||
<params_endpoint/> | ||
<path>proc</path> | ||
<path_endpoint>x_64935_gql_proc</path_endpoint> | ||
<require_csrf>false</require_csrf> | ||
<roles/> | ||
<script><![CDATA[/** | ||
* GQL (Glide Query Language) Processor | ||
* | ||
* MIT License http://tldrlegal.com/l/mit | ||
* Copyright (c) 2016 John.Chun @snowaid.com | ||
*/ | ||
(function process(g_request, g_response, g_processor) { | ||
try { | ||
//var params = g_request.getParameter('params') || {}; // handle Angular POST in JSON | ||
//var gql = g_request.getParameter('gql') || params.gql; | ||
//var format = g_request.getParameter('format') || params.format; | ||
var gql = g_request.getParameter('gql'); | ||
var format = g_request.getParameter('format'); | ||
var result = new GQL().query(gql, format); | ||
/** | ||
* disable page caching to avoid stale result | ||
* g_response.setHeader() overwrites existing header | ||
* g_response.addHeader() unavailable in scoped GlideServletResponse | ||
* http://wiki.servicenow.com?title=Scoped_GlideServletResponse_API_Reference | ||
* usually need all 3 to be sure, but for now set only 'cache-control' | ||
*/ | ||
g_response.setHeader('cache-control', 'no-cache'); | ||
//g_response.addHeader('pragma', 'no-cache'); | ||
//g_response.addHeader('expires', '-1'); | ||
if (/CSV/i.test(format)) { | ||
var filename = result.query && result.query.table || 'gql'; | ||
g_response.setHeader('Content-Disposition', 'attachment;filename=' + filename + '.csv'); | ||
g_processor.writeOutput('text/csv', getCSV()); | ||
} | ||
else if (/HTML/i.test(format)) g_processor.writeOutput('text/html', getHTML()); | ||
else g_processor.writeJSON(result); | ||
} catch (e) { g_processor.writeOutput('text/plain', 'ERROR: ' + e + '\r' + e.stack); } | ||
function getCSV() { | ||
var columns = [], rows = []; | ||
result.labels.forEach(function(label) { columns.push(escapeCSV(label)); }); | ||
rows.push(columns.join(',')); | ||
for (var i = 0; i < result.records.length; i++) { | ||
columns = []; | ||
result.records[i].forEach(function(column) { columns.push(escapeCSV(column)); }); | ||
rows.push(columns.join(',')); | ||
} | ||
return rows.join('\r\n'); | ||
/** | ||
* Takes raw field value and returns CSV escaped value | ||
* based on RFC 4180 Common Format and MIME Type for CSV Files | ||
* October 2005 http://tools.ietf.org/html/rfc4180 | ||
* | ||
* @param {string} raw - raw field value | ||
* @return {string} escaped CSV field value, if applicable per RFC 4180 | ||
*/ | ||
function escapeCSV(raw) { | ||
var out = (raw + '').replace(/"/g,'""'); // escape all double quotes | ||
if (/[\r\n",]/.test(out)) out = '"' + out + '"'; // if it has special characters, enclose in double quotes | ||
return out; | ||
} | ||
} | ||
function getHTML() { | ||
var columns = [], rows = ['<table><thead><tr><th>']; | ||
result.labels.forEach(function(label) { columns.push(escapeHTML(label)); }); | ||
rows.push(columns.join('</th><th>'), '</th></tr></thead><tbody>'); | ||
for (var i = 0; i < result.records.length; i++) { | ||
columns = []; | ||
result.records[i].forEach(function(column) { columns.push(escapeHTML(column)); }); | ||
rows.push('<tr><td>', columns.join('</td><td>'), '</td></tr>'); | ||
} | ||
rows.push('</tbody></table>'); | ||
return rows.join(''); | ||
function escapeHTML(raw) { // escape reserved HTML characters | ||
var MAP = { '&':'&','<':'<','>':'>'}; | ||
return (raw + '').replace(/[&<>]/g, function(c) { return MAP[c]; }); | ||
} | ||
} | ||
})(g_request, g_response, g_processor);]]></script> | ||
<sys_class_name>sys_processor</sys_class_name> | ||
<sys_created_by>john.chun</sys_created_by> | ||
<sys_created_on>2016-10-18 11:57:00</sys_created_on> | ||
<sys_customer_update>true</sys_customer_update> | ||
<sys_id>3e0e24694f26a600463efd218110c7da</sys_id> | ||
<sys_mod_count>121</sys_mod_count> | ||
<sys_name>GQL</sys_name> | ||
<sys_package display_value="gql" source="x_64935_gql">a4d8ddd54f62a600463efd218110c731</sys_package> | ||
<sys_policy/> | ||
<sys_replace_on_upgrade>false</sys_replace_on_upgrade> | ||
<sys_scope display_value="gql">a4d8ddd54f62a600463efd218110c731</sys_scope> | ||
<sys_update_name>sys_processor_3e0e24694f26a600463efd218110c7da</sys_update_name> | ||
<sys_updated_by>john.chun</sys_updated_by> | ||
<sys_updated_on>2016-10-27 14:25:02</sys_updated_on> | ||
<type>script</type> | ||
</sys_processor> | ||
</record_update> |
103 changes: 103 additions & 0 deletions
103
update/sys_script_include_37674ed14fa2a600463efd218110c700.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<record_update table="sys_script_include"> | ||
<sys_script_include action="INSERT_OR_UPDATE"> | ||
<access>package_private</access> | ||
<active>true</active> | ||
<api_name>x_64935_gql.GQL</api_name> | ||
<client_callable>false</client_callable> | ||
<description>GQL (Glide Query Language) Class</description> | ||
<name>GQL</name> | ||
<script><![CDATA[/** | ||
* GQL (Glide Query Language) Class | ||
* | ||
* MIT License http://tldrlegal.com/l/mit | ||
* Copyright (c) 2016 John.Chun @snowaid.com | ||
*/ | ||
var GQL = Class.create(); | ||
GQL.prototype = { | ||
initialize: function(format) { | ||
this.format = format || 'JSAN'; // { JSAN | JSON } | ||
}, | ||
type: 'GQL' | ||
}; | ||
/** | ||
* Takes a GQL statement and returns the resultset in an array of records | ||
* | ||
* @param {string} gql - GQL statement | ||
* @return {object} resultset in an array of records | ||
*/ | ||
GQL.prototype.query = function(gql, format) { | ||
// prep params | ||
gql = gql.replace(/\s*--.*/g, ''); // remove comments | ||
format = format || this.format; | ||
var isJSON = /JSON/i.test(format); | ||
// parse gql | ||
var rxParser = /SELECT\s*([^]+?)\s*FROM\s*(.+?)\s*(?:WHERE\s*([^]+?(?=\s*LIMIT)|[^]+?)\s*)?(?:LIMIT\s*([,\d\s]+?)\s*)?$/; | ||
var matches = rxParser.exec(gql); | ||
var columns = matches[1] || ''; // SELECT column_list | ||
var table = matches[2] || ''; // FROM table name | ||
var encodedQuery = matches[3] || ''; // WHERE encoded_query_string | ||
var limit = matches[4] || ''; // LIMIT [offset,] row_count | ||
var query = { full: gql, columns: columns, table: table, encodedQuery: encodedQuery, limit: limit }; // add to result | ||
var offset = 0; | ||
if (limit) { // parse offset, row_count | ||
limit = limit.split(','); | ||
if (limit.length > 1) offset = parseInt(limit[0], 10) || 0; | ||
limit = parseInt(limit[limit.length > 1 ? 1 : 0], 10) || 0; | ||
} | ||
// parse column_list | ||
columns = columns.split(/\s*,\s*/); // split column_list column_1, column_2 [column_2_heading], column_3 | ||
var fields = [], labels = []; | ||
for (var i = 0; i < columns.length; i++) { // parse column heading | ||
matches = /([.\w]+)\s*(?:\[(.+)\])?/.exec(columns[i]); | ||
//columns[i] = { field: matches[1], label: matches[2] || matches[1] }; // if no label, use field name | ||
fields.push(matches[1]); | ||
labels.push(matches[2] || matches[1]); // if no label, use field name | ||
} | ||
// run query & retrieve data | ||
var records = []; // array of rows | ||
var gr = new GlideRecord(table); | ||
if (encodedQuery) gr.addEncodedQuery(encodedQuery); | ||
if (offset) gr.chooseWindow(offset, offset + limit); | ||
else if (limit) gr.setLimit(limit); | ||
gr.query(); | ||
while (gr.next()) records.push(getRow()); | ||
return { fields: fields, labels: labels, query: query, records: records }; | ||
function getRow() { | ||
var row = isJSON ? {} : []; | ||
for (var i = 0; i < fields.length; i++) { | ||
var field = fields[i], isDV = /(^|\.)dv_/.test(field); | ||
var value = isDV ? gr.getDisplayValue(field.replace('dv_', '')) || '' : gr.getElement(field).toString(); | ||
isJSON ? row[labels[i]] = value : row.push(value); // default to JSAN | ||
} | ||
return row; | ||
} | ||
}; | ||
]]></script> | ||
<sys_class_name>sys_script_include</sys_class_name> | ||
<sys_created_by>john.chun</sys_created_by> | ||
<sys_created_on>2016-10-17 23:35:12</sys_created_on> | ||
<sys_customer_update>true</sys_customer_update> | ||
<sys_id>37674ed14fa2a600463efd218110c700</sys_id> | ||
<sys_mod_count>75</sys_mod_count> | ||
<sys_name>GQL</sys_name> | ||
<sys_package display_value="gql" source="x_64935_gql">a4d8ddd54f62a600463efd218110c731</sys_package> | ||
<sys_policy>read</sys_policy> | ||
<sys_replace_on_upgrade>false</sys_replace_on_upgrade> | ||
<sys_scope display_value="gql">a4d8ddd54f62a600463efd218110c731</sys_scope> | ||
<sys_update_name>sys_script_include_37674ed14fa2a600463efd218110c700</sys_update_name> | ||
<sys_updated_by>john.chun</sys_updated_by> | ||
<sys_updated_on>2016-10-27 14:25:37</sys_updated_on> | ||
</sys_script_include> | ||
</record_update> |
Oops, something went wrong.