summaryrefslogtreecommitdiff
path: root/ebus-racket
diff options
context:
space:
mode:
Diffstat (limited to 'ebus-racket')
-rw-r--r--ebus-racket/db.plt22
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