A simple Clojure library for data mapping where it's possible to define associations, validations and callbacks.
The current version it's not production ready yet and the APIs might change in the next interations.
(ns example.core
(:require [yadm.core :as yadm]
[yadm.dmi.default :as ydmi]))
(def db-spec
{:classname "org.postgresql.Driver"
:subprotocol "postgresql"
:subname "//localhost:5432/a_db_name"
:user "an-user"
:password "a-password"})
(def dmi
(ydmi/default-dmi db-spec))
(yadm/defdatamapper User
:validations
{:name [[:required]]
:email [[:required]
[:format :with #"\S+@\S+\.\S+"]]}
:associations
[[:has-many :product]]
:after-create [send-welcome-email])
(yadm/defdatamapper Product
:validations
{:name [[:required]]
:price [[:required]
[:range :min 0]]
:condition [[:required]
[:in :set #{"new" "used"}]]}
:associations
[[:belongs-to :user]])
(yadm/find-where dmi
User
[:= :id 1]
{:columns [:id]
:includes [[Product {:as :items
:columns [:name :price]}]]})
(yadm/create! dmi
User {:name "Test"
:email "test@test.com"})
Copyright © 2019 Thiago Lewin
Distributed under the Eclipse Public License either version 1.0 or any later version.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close