From ef36304796c52169df23bf99781a1fa2c3f616aa Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Thu, 1 Mar 2012 00:57:52 +0100 Subject: ebus-racket: db.plt pgsql test; #lang racket/base --- ebus-racket/db.plt | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 ebus-racket/db.plt (limited to 'ebus-racket/db.plt') diff --git a/ebus-racket/db.plt b/ebus-racket/db.plt new file mode 100644 index 0000000..050eafe --- /dev/null +++ b/ebus-racket/db.plt @@ -0,0 +1,22 @@ +#lang racket/base +(require (prefix-in db: (planet ryanc/db:1:5))) + +(define pgc + (db:postgresql-connect #:user "ebus" + #:database "ebus" + #:password "ebus" + #:server "10.2.2.26")) + + +(define (query-sensor-id sensor-name) + (db:query-value pgc "select id from sensor where name = $1" sensor-name)) + +(define (insert sensor-name value-float value-int value-string) + (let ([sensor-id (query-sensor-id sensor-name)] + [type (cond ((not (void? value-string)) "string") + ((not (void? value-float)) "float") + ((not (void? value-int)) "int"))]) + (db:query-exec (string-append "INSERT INTO value(timestamp, sensor_id, type, value_float, value_int, value_string) " + "VALUES (now(), $1, $2, $3, $4, $5)") + sensor-id type value-float value-int value-string))) + ;(db:query-exec pgc "select \ No newline at end of file -- cgit v1.2.1