From 280179806ad4426480032769f5296d3875044530 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Wed, 12 Jan 2011 16:44:31 +0100 Subject: some cleanup, tests with bo --- src/nodejs/start.js | 73 +++++++++++++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 33 deletions(-) diff --git a/src/nodejs/start.js b/src/nodejs/start.js index 2cf923e..c664cfe 100644 --- a/src/nodejs/start.js +++ b/src/nodejs/start.js @@ -9,42 +9,49 @@ var http = require('http'), var connectionString = "pg://user:pass@localhost/xapi" -function getDataBaseResult(tag,bbox,res){ -pg.connect(connectionString,function(err,client){ - var the_result; - if(err){ - console.log(err); - } else { - client.query(createQuery(tag,bbox),function(err,result){ - if (err) { - console.log(err); - } else { - console.log(result); - res.write(result.rows); - res.end("/n"); - } - - }); - } -}); +function getDataBaseResult(tag,bbox,res) { + pg.connect(connectionString,function(err,client) { + var the_result; + + if (err) { + console.log(err); + } + else { + client.query(createQuery(tag,bbox),function(err,result) { + if (err) { + console.log(err); + } + else { + console.log(result); + res.write(result.rows); + res.end("\n"); + } + }); + } + }); } function createQuery(tag,bbox){ // FIXME: validate - var table = tag[0] + "#" + tag[1]; - var filter = ""; + // var table = tag[0] + "#" + tag[1]; + // var filter = ""; + + // // input validation + // for(i=0;i " + bbox[2] + " AND latitude < " + bbox[3]; + // } - // input validation - for(i=0;i " + bbox[2] + " AND latitude < " + bbox[3]; - } - return "SELECT * FROM \"" + table + "\" " + filter + ";"; + return "SELECT id, tags, linestring \ + FROM ways \ + WHERE (tags @> '\"amenity\"=>\"pub\"' AND \ + lseg(linestring) @ box('(13.0882097323,52.3418234221)'::point,'(13.7606105539,52.6697240587)'::point));" } @@ -67,13 +74,13 @@ http.createServer(function (req, res) { } base_url_re.exec(req.url); var type = RegExp.$1, url_rest = querystring.unescape(RegExp.$2); - + var filters = []; while (v = filter_re.exec(url_rest)) { filters.push(v[1]); } console.log(filters); - + var tag; var bbox; @@ -90,10 +97,10 @@ http.createServer(function (req, res) { console.log(tag); console.log(bbox); - getDataBaseResult(tag,bbox,res); + getDataBaseResult(tag,bbox,res); res.writeHead(200, {'Content-Type': 'text/plain; charset=utf8', }); - + res.write('URL was: ' + req.url + '\n'); res.write('type: ' + type + '\n'); res.write('filters:\n'); -- cgit v1.2.3