aboutsummaryrefslogtreecommitdiff
#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)])