Postmodern: PostgreSQL Access from Lisp

Posted by Daniel Lyons on November 22, 2008

Postmodern is my new favorite database library. And for a couple simple reasons.

(defprepared insert-word
        “INSERT INTO words (word, lang) VALUES ($1, $2)”))
        

(insert-word “my-word” “en”)

(defprepared word-exists
        (sql (:select t :from ’words :where (:and (:= ’word ’$1)
        (:= ’lang ’$2))))
        :single)
        

(word-exists “my-word” “en”) ;; => t
(word-exists “your-word” “en”) ;; => nil

If you’re using Postmodern under CCL on your Intel 32-bit Mac, and you’re working with UTF-8 characters, you might want to add this line to the top of your Lisp or your ASD file after installing trivial-utf-8:

#+ccl
        (push :unicode *features*)

Otherwise you will get really weird errors related to Unicode.