Last Updated: February 25, 2016
·
1.023K
· 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")

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

PHP applications still send a browser full of JavaScript. Hardening the server does not inventory the payment, analytics, and plugin scripts that run after the HTML is delivered.

Security insights from Cside