https://github.com/tlewin/yadm
Simple Clojure library for data mapping
https://github.com/tlewin/yadm
clojure database datamapper sql validation
Last synced: about 1 year ago
JSON representation
Simple Clojure library for data mapping
- Host: GitHub
- URL: https://github.com/tlewin/yadm
- Owner: tlewin
- License: epl-1.0
- Created: 2019-01-02T21:54:25.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-16T07:41:34.000Z (almost 7 years ago)
- Last Synced: 2024-10-19T05:18:04.450Z (over 1 year ago)
- Topics: clojure, database, datamapper, sql, validation
- Language: Clojure
- Size: 54.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# YADM
A simple Clojure library for data mapping where it's possible to define associations, validations and callbacks.
## Warning
The current version it's **not** production ready yet and the APIs **might change** in the next interations.
## Build
[](https://travis-ci.org/tlewin/yadm)
## Leiningen
[](https://clojars.org/yadm)
## Usage
```clojure
(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"})
```
## License
Copyright © 2019 Thiago Lewin
Distributed under the Eclipse Public License either version 1.0 or any later version.