Skip to content

Commit

Permalink
count hits
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Sofaer committed Aug 15, 2012
1 parent 7b6e9e3 commit afd028e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion db.js
Expand Up @@ -5,7 +5,7 @@ function create_db(){
pg.connect(process.env.DATABASE_URL || "tcp://michael:1234@localhost/michael", function(err, client) {
client.query("CREATE TABLE account(account_id BIGINT PRIMARY KEY, cdate TIMESTAMPTZ default now());");
client.query("CREATE TABLE domain(domain_id BIGINT PRIMARY KEY, account_id BIGINT REFERENCES account(account_id), cdate TIMESTAMPTZ default now());");
client.query("CREATE TABLE hit(hit_id BIGINT PRIMARY KEY, domain_id BIGINT REFERENCES domain(domain_id), cdate TIMESTAMPTZ default now());");
client.query("CREATE TABLE hit(hit_id serial PRIMARY KEY, domain_id BIGINT REFERENCES domain(domain_id), cdate TIMESTAMPTZ default now());");
})
}

Expand Down
1 change: 0 additions & 1 deletion public/javascripts/sample_app.js
Expand Up @@ -2,7 +2,6 @@ CloudFlare.define("sample_app",
[ "cloudflare/dom", "sample_app/config", "cloudflare/console"],
function(dom, config, console)
{
console.log("stuff");
return {
name: "Sample App",
dom: dom
Expand Down
15 changes: 12 additions & 3 deletions web.js
Expand Up @@ -72,10 +72,14 @@ function log_hit(domain_id, respond){

query.on('end', function() {
var query2 = client.query('select count(*) from hit where domain_id = $1', [domain_id]);
query2.on('end', function() {
console.log(query2);
query2.on('row', function(row) {
respond(row.count);
});
query2.on('error', function(something) {
console.log(something);
respond("0");
});

});

query.on('error', function(something) {
Expand Down Expand Up @@ -143,7 +147,12 @@ app.post('/hit', function(request, response) {
count : count
}));
}
log_hit(request.body.domain_id, respond);

if (!request.body.domain_id) {
respond({error: "no domain_id"}, 400)
} else {
log_hit(request.body.domain_id, respond);
}
});


Expand Down

0 comments on commit afd028e

Please sign in to comment.