(asdf:oos 'asdf:load-op :clsql) (asdf:operate 'asdf:load-op :clsql-postgresql) (defpackage brew-db (:use common-lisp) (:use clsql) (:export style master-recipe recipe-revision hop grain yeast connect-to-brew-db)) (in-package brew-db) #.(locally-enable-sql-reader-syntax) (defun connect-to-brew-db () "Connects to the homebrew db and returns the connection" (connect '("" "homebrew" "clinton" "") :database-type :postgresql :if-exists :old)) ;;; Categorization (def-view-class style () ((id :type integer :db-kind :key :initarg :id) (name :type varchar :initarg :name) (og-low :type float :initarg :og-low) (og-high :type float :initarg :og-high) (fg-low :type float :initarg :fg-low) (fg-high :type float :initarg :fg-high) (ibu-low :type integer :initarg :ibu-low) (ibu-high :type integer :initarg :ibu-high) (srm-low :type integer :initarg :srm-low) (srm-high :type integer :initarg :srm-high))) ;;; Ingredients (def-view-class hop () ((id :type integer :db-kind :key :initarg :id) (name :type varchar :initarg :name) (alpha :type float :initarg :alpha) (form :type (varchar 32) :initarg :form))) (def-view-class grain () ((id :initarg :id :type integer :db-kind :key) (name :initarg :name :type varchar) (color :initarg :color :type float) (extract :initarg :extract :type float) (use :initarg :use :type (varchar 64)))) (def-view-class yeast () ((id :type integer :db-kind :key :initarg :id) (name :type varchar :initarg :name) (attenuation-min :type real :initarg :attenuation-min) (attenuation-max :type real :initarg :attenuation-max) (temp-min :type real :initarg :temp-min) (temp-max :type real :initarg :temp-max))) ;;; Recipes (def-view-class master-recipe () ((name :type (varchar 64) :db-kind :key :initarg :name) (description :type varchar :initarg :description) (style :db-kind :join :db-info (:join-class style :home-key style-id :foreign-key id :set nil)))) (def-view-class recipe-revision () ((id :type integer :db-kind :key :initarg :id) (recipe :db-kind :join :db-info (:join-class master-recipe :home-key recipe-name :foreign-key name)) (revision :type integer :initarg :revision) (batch-size :type real :initarg :batch-size) (boil-size :type real :initarg :boil-size) (og :type real :initarg :og) (fg :type real :initarg :fg))) ;;; Add steps and ingredients (def-view-class recipe-step () ((recipe :db-kind :join :db-info (:join-class recipe-revision :home-key recipe-id :foreign-key id)) (step :type integer :initarg :step) (direction :type varchar :initarg :direction))) (def-view-class recipe-hop () ((recipe :db-kind :join :db-info (:join-class recipe-revision :home-key recipe-id :foreign-key id)) (hop :db-kind :join :db-info (:join-class hop :home-key hop-id :foreign-key id)) (quantity :type real :initarg :quantity) (alpha :type real :initarg :alpha) (time :type time :initarg :time)))