[Racket] Ferti hydroponic nutrient solver, redux.
Add debug facilities.
Changed files
README.org
@@ -8,5 +8,7 @@
8
8
- =FERTI_ENVIRONMENT= :: Can be either =development= or =production=.
9
9
Default value is =production=, which is more secure (password
10
10
required everywhere, no debug traces).
11
Added:
- =FERTI_DEBUG= :: Can be either =true= or =false=. Default value is
12
Added:
=false=.
11
13
- =FERTI_USER= :: User used to log into the web app.
12
14
- =FERTI_PASS= :: Password used to log into the web app.
db/conn.rkt
@@ -1,22 +1,27 @@
1
1
#lang racket
2
2
3
Removed:
(require db)
4
Removed:
5
3
(provide current-conn
6
4
connect!
7
5
disconnect!
8
6
with-db
9
7
with-tx)
10
8
9
Added:
(require db
10
Added:
"../debug.rkt")
11
Added:
11
12
(define current-conn (make-parameter #f))
12
13
13
14
(define (connect! #:path [path 'memory])
14
Removed:
(unless (connection? (current-conn))
15
Removed:
(current-conn (sqlite3-connect #:database path #:mode 'create))))
15
Added:
(if (connection? (current-conn))
16
Added:
(debug-log (format "Connection already instantiated: ~a" (current-conn)))
17
Added:
(begin
18
Added:
(current-conn (sqlite3-connect #:database path #:mode 'create))
19
Added:
(debug-log (format "Connection instantiated: ~a" (current-conn))))))
16
20
17
21
(define (disconnect!)
18
22
(disconnect (current-conn))
19
Removed:
(current-conn #f))
23
Added:
(current-conn #f)
24
Added:
(debug-log "Connection disconnected."))
20
25
21
26
(define-syntax-rule (with-db body ...)
22
27
(begin
debug.rkt
@@ -0,0 +1,11 @@
1
Added:
#lang racket
2
Added:
3
Added:
(provide debug-enabled?
4
Added:
debug-log)
5
Added:
6
Added:
(define debug-enabled?
7
Added:
(make-parameter (let ([env (getenv "FERTI_DEBUG")]) (and env (equal? env "true")))))
8
Added:
9
Added:
(define (debug-log message)
10
Added:
(when (debug-enabled?)
11
Added:
(displayln message)))
run_development.sh
@@ -0,0 +1,9 @@
1
Added:
#!/bin/bash
2
Added:
3
Added:
export FERTI_ENV=development
4
Added:
export FERTI_DEBUG=true
5
Added:
6
Added:
export FERTI_USER=admin
7
Added:
export FERTI_PASS=admin
8
Added:
9
Added:
racket main.rkt