diff options
author | Yves Fischer <yvesf-git@xapek.org> | 2012-03-01 00:57:52 +0100 |
---|---|---|
committer | Yves Fischer <yvesf-git@xapek.org> | 2012-03-01 00:57:52 +0100 |
commit | ef36304796c52169df23bf99781a1fa2c3f616aa (patch) | |
tree | decbbea8289b3e2295bdb0bcde9579b444ed6e22 /ebus-racket/db.plt | |
parent | 494ed088e84b92af85d2f7260d242b06615fab69 (diff) | |
download | ebus-alt-ef36304796c52169df23bf99781a1fa2c3f616aa.tar.gz ebus-alt-ef36304796c52169df23bf99781a1fa2c3f616aa.zip |
ebus-racket: db.plt pgsql test; #lang racket/base
Diffstat (limited to 'ebus-racket/db.plt')
-rw-r--r-- | ebus-racket/db.plt | 22 |
1 files changed, 22 insertions, 0 deletions
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 |