From 4622bbfea0ebda4072637ba2490fca1746ac650d Mon Sep 17 00:00:00 2001 From: Masaya Tojo Date: Sun, 24 Mar 2024 21:12:30 +0900 Subject: Add utility about database connections. --- db/connection.rkt | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 db/connection.rkt (limited to 'db') 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)]) -- cgit v1.2.3