diff options
| author | Masaya Tojo <masaya@tojo.tokyo> | 2024-03-24 21:12:30 +0900 | 
|---|---|---|
| committer | Masaya Tojo <masaya@tojo.tokyo> | 2024-03-24 21:14:52 +0900 | 
| commit | 4622bbfea0ebda4072637ba2490fca1746ac650d (patch) | |
| tree | 6b0ef76188b8640e82068b61b48513dea7888411 | |
| parent | dce6fe3e40b8d68000df2902d3858b0874aa77b5 (diff) | |
Add utility about database connections.
| -rw-r--r-- | db/connection.rkt | 33 | 
1 files changed, 33 insertions, 0 deletions
| diff --git a/db/connection.rkt b/db/connection.rkt new file mode 100644 index 0000000..642ee35 --- /dev/null +++ b/db/connection.rkt @@ -0,0 +1,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)]) | 
