summaryrefslogtreecommitdiff
path: root/ebus-racket/db.plt
blob: 050eafe633c3dba5e6d2bee66a30e7d0d5a05fa9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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