From aa998886fc0762c221ea41af68a0490c45bb7cba Mon Sep 17 00:00:00 2001 From: Masaya Tojo Date: Sun, 24 Mar 2024 21:13:28 +0900 Subject: Add procedures for database operation. --- db/tags.rkt | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 db/tags.rkt (limited to 'db/tags.rkt') diff --git a/db/tags.rkt b/db/tags.rkt new file mode 100644 index 0000000..eee2141 --- /dev/null +++ b/db/tags.rkt @@ -0,0 +1,27 @@ +#lang typed/racket +(require typed/db) + +(module untyped-db-ops racket + (require db + db/util/datetime + "../entities/article.rkt") + (provide fetch-tag-ids + insert-tag) + + (define (fetch-tag-ids conn) + (for/hash ([(name tag-id) + (in-query conn "SELECT name, tag_id FROM diary.tags")]) + (values name tag-id))) + + (define (insert-tag conn name) + (query-value conn + " +INSERT INTO diary.tags(name) +VALUES($1) +RETURNING tag_id +" + name))) + +(require/typed/provide (submod "." untyped-db-ops) + [fetch-tag-ids (-> Connection (Immutable-HashTable String Integer))] + [insert-tag (-> Connection String Integer)]) -- cgit v1.2.3