Skip to content

Commit

Permalink
call HTTP(s) from SQLcl and process the results.
Browse files Browse the repository at this point in the history
  • Loading branch information
krisrice committed Dec 4, 2018
1 parent c931e13 commit aa9b8a3
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions sqlcl/examples/emojiWorldData.sql
@@ -0,0 +1,53 @@
drop table emoji
/

create table emoji ( keyword varchar2(30), emoji varchar2(200))
/

script
// read text content from the given URL
function readText(url) {
// Using JavaImporter to resolve classes
// from specified java packages within the
// 'with' statement below

with (new JavaImporter(java.io, java.net)) {
// more or less regular java code except for static types
var is = new URL(url).openStream();
try {
var reader = new BufferedReader(
new InputStreamReader(is));
var buf = '', line = null;
while ((line = reader.readLine()) != null) {
buf += line;
}
} finally {
reader.close();
}
return buf;
}
}


// get the remote URL
var emoji = JSON.parse(readText('https://raw.githubusercontent.com/muan/emoji/gh-pages/javascripts/emojilib/emojis.json'));
var keys = Object.keys(emoji);

ctx.write( "Got :" + keys.length + " emojis \n\n" )

// process the JSON

for (var key in emoji) {
//ctx.write(key + ">")
if ( emoji[key] && emoji[key].char ) {
//ctx.write( emoji[key].char )
var binds = {};
binds.keyword = key;
binds.emoji = emoji[key].char;
var ret = util.execute("insert into emoji(keyword,emoji) values(:keyword , :emoji)",binds);
}
}
ctx.write( "\n\n" )
/
select * from emoji order by keyword;
/

0 comments on commit aa9b8a3

Please sign in to comment.