aboutsummaryrefslogtreecommitdiff
path: root/db/connection.rkt
blob: 642ee35e8ac37424d3e520c88f2df4bc8c769918 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#lang typed/racket

(provide current-connection
         get-connection
         set-connection!
         connect)

(require typed/db)

(: current-connection (Parameterof (Option Connection)))
(define current-connection (make-parameter #f))

(define (get-connection)
  (cond
    [(current-connection) => identity]
    [else (error "set-connection! でコネクションを設定してください")]))

(: set-connection! (-> Connection Void))
(define (set-connection! c)
  (current-connection c))

(module untyped racket
  (provide (rename-out [postgresql-connect connect]))
  (require db))

(require/typed/provide (submod "." untyped)
  [connect (->* (#:user String #:database String)
                (#:server (Option String)
                 #:port Exact-Positive-Integer
                 #:socket (U 'guess Path-String False)
                 #:password (U String (List 'hash String) False)
                 #:allow-cleartext-password? (U 'local Boolean))
                Connection)])