Add debug facilities.

Commit
086ba55a15dc04914cba500f7ead61dec5490162
Author
Marius Peter <dev@marius-peter.com>
Author date
Committer
Marius Peter <dev@marius-peter.com>
Committer date
Changed files
README.org
index 0b7a9bdd..13b173fb 100644..100644
@@ -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
index 42a75c06..11abc191 100644..100644
@@ -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
index 00000000..0d935578 000000..100644
@@ -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
index 00000000..ee490825 000000..100755
@@ -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