diff options
author | Masaya Tojo <masaya@tojo.tokyo> | 2024-03-24 21:13:28 +0900 |
---|---|---|
committer | Masaya Tojo <masaya@tojo.tokyo> | 2024-03-24 21:14:52 +0900 |
commit | aa998886fc0762c221ea41af68a0490c45bb7cba (patch) | |
tree | c38f88a6d67e8b6be53eb5601bf23cfb09cf626a /db/tags.rkt | |
parent | 4622bbfea0ebda4072637ba2490fca1746ac650d (diff) |
Add procedures for database operation.
Diffstat (limited to 'db/tags.rkt')
-rw-r--r-- | db/tags.rkt | 27 |
1 files changed, 27 insertions, 0 deletions
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)]) |