Last Updated: February 25, 2016
·
797
· francescoagati

using idiorm in lisp with pharen

macros

(defmacro orm-config (type host db username password) 
    '(do
      (:: ORM (configure (. ~type ":host=" ~host ";dbname=" ~db )))
      (:: ORM (configure "username" ~username))
      (:: ORM (configure "password" ~password))
      )
  )

(micro table-for (tbl) (:: ORM (for_table ~tbl)))

(defmacro orm-select (tbl fields where order)
  '(-> (table-for ~tbl) (select ~fields) (where ~where) (order ~order) (find-many)))

example

(orm-config #mysql #127.0.0.1 #db_my #root #root)

(-> (table-for #users)
  (where #id 5)
  (find_one)
)

(orm-select #users "name,surname" (. "id=" 2) "id desc")