Created
August 30, 2017 20:35
-
-
Save krisrice/c7279efe8cd99c0d04a8a4005dd473f6 to your computer and use it in GitHub Desktop.
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
var ddl = (function () { | |
function DDL() { | |
this.options = { | |
//columnNamePrefix: "?", | |
"Object Prefix": {value:"a"}, | |
Schema: {value:"hr"}, | |
"On Delete": {value:'Cascade',check:['Cascade','Restrict','Set Null']}, | |
Compression: {value:'No',check:['Yes','No']}, | |
"Include Drops": {value:'No',check:['Yes','No']}, | |
"Date Data Type":{value:'DATE',check:['DATE','TIMESTAMP','Timestamp with time zone','Timestamp with local time zone']}, | |
"Audit Columns": {value:'No',check:['Yes','No']}, | |
}; | |
this.forest = null; | |
this.find = function( name ) { | |
for( var i = 0; i < this.forest.length; i++ ) { | |
var descendants = this.forest[i].descendants(); | |
for( var j = 0; j < descendants.length; j++ ) { | |
var node = descendants[j]; | |
if( node.parseName() == name ) | |
return node; | |
else if( node.parseName('noprefix=>true') == name ) | |
return node; | |
} | |
} | |
return null; | |
}; | |
this.translate = function (input, options) { | |
var output = ''; | |
this.forest = tree(input); | |
for( var i = 0; i < this.forest.length; i++ ) { | |
output += this.forest[i].toDDL()+'\n'; | |
} | |
for( var i = 0; i < this.forest.length; i++ ) { | |
output += this.forest[i].generateData()+'\n'; | |
} | |
return output; | |
}; | |
this.optionsPopup = function () { | |
if (!window.focus ) return true; | |
var popup = window.open('', 'Options', 'height=500,width=500,scrollbars=yes'); | |
var t = window.document.createElement("table"); | |
popup.document.body.appendChild(t); | |
for( var key in this.options ) { | |
if( this.options.hasOwnProperty(key) ) { | |
//console.log(key + " -> " + p[key]); | |
var row = t.insertRow(-1); | |
var cell0 = row.insertCell(0); | |
var l = window.document.createElement("label"); | |
l.innerHTML = key; | |
cell0.appendChild(l); | |
var cell1 = row.insertCell(1); | |
var i = window.document.createElement("input"); | |
i.type = "text"; | |
if( this.options[key].check != undefined ) { | |
i = window.document.createElement("select"); | |
var values = this.options[key].check; | |
for( var j = 0; j < values.length; j++ ) { | |
var o = window.document.createElement("option"); | |
o.text = values[j]; | |
i.add(o); | |
} | |
} | |
i.value = this.options[key].value; | |
i.name = key; | |
i.id = key; | |
cell1.appendChild(i); | |
} | |
} | |
var row = t.insertRow(-1); | |
var cell = row.insertCell(0); | |
var s = document.createElement("input"); | |
s.type = "submit"; | |
s.value = "Submit"; | |
s.onclick = function() { | |
var options = ddl.options; | |
for( var key in options ) { | |
if( options.hasOwnProperty(key) ) { | |
options[key].value = popup.document.getElementById(key).value; | |
} | |
} | |
popup.close(); | |
}; | |
cell.appendChild(s); | |
return true; | |
}; | |
this.examplesPopup = function () { | |
if (!window.focus ) return true; | |
var popup = window.open('syntax_and_examples.html'); | |
} | |
this.objPrefix = function () { | |
var ret = this.options['Schema'].value; | |
if( '' != ret ) | |
ret = ret + '.'; | |
ret = ret + this.options["Object Prefix"].value; | |
if( '' != ret ) | |
ret = ret + '_'; | |
return ret.toUpperCase(); | |
} | |
this.tree = function ( input, table ) { | |
var forest = tree(input); | |
try { | |
table.innerHTML = ""; | |
try { | |
for( var i = 0; i < forest.length; i++ ) | |
forest[i].render(table, 0); | |
} catch (err) { | |
var row = table.insertRow(-1); | |
var cell = row.insertCell(0); | |
cell.innerHTML = "<html><font color=red>" + err; | |
} | |
} catch (error) { | |
console.log("Error parsing string statement.->" + error); | |
} | |
} | |
} | |
return new DDL(); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment