Created
November 27, 2012 19:46
"Why not to use my library clj-record" code examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmodel widget db | |
(associations | |
(:has-many :sizes)) | |
(validation | |
(:name "Name is required" #(not (empty? %))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; model configuration | |
(clj-record.meta/init-model-metadata "user") | |
(clj-record.core/set-db-spec "user" db) | |
(clj-record.core/set-table-name "user" "users") | |
; expose model metadata | |
(def model-name "user") | |
(def table-name (clj-record.core/table-name "user")) | |
(defn model-metadata [& args] | |
(apply clj-record.meta/model-metadata-for "user" args)) | |
(defn table-name [] (clj-record.core/table-name "user")) | |
; data manipulation | |
(defn record-count | |
([] (clj-record.core/record-count "user")) | |
([attributes] (clj-record.core/record-count "user" attributes))) | |
(defn get-record [id] | |
(clj-record.core/get-record "user" id)) | |
(defn all-records [] | |
(clj-record.core/all-records "user")) | |
(defn find-records [attributes] | |
(clj-record.core/find-records "user" attributes)) | |
; ... and so on. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns my.model.widget | |
(:require clj-record.boot | |
[my.model.config :refer (db)])) | |
(clj-record.core/init-model | |
(:associations | |
(has-many sizes)) | |
(:validation | |
(:name "Name is required" #(not (empty? %))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Code examples for http://elhumidor.blogspot.com/2012/11/why-not-to-use-my-library-clj-record.html