Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
/bdmPublic

BDM is super simple, fully declarative clj/cljc bi directional mapper.

License

NotificationsYou must be signed in to change notification settings

Aitem/bdm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Clojars Projectci

BDM is super simple, fully declarative clj/cljc bi directional mapper that allow convert your data fromA toB and back.

Usage

(nsuser  (:require [bdm.core as bdm]))(defperson  {:name"John":lastname"Smith":contacts [{:type"email":value"john@smith.com"}              {:type"phone":use"home":value"12223334455"}  {:type"phone":use"work":value"15556667788"}]})(defmapping  [[[:name]]   [[:lastname]]   [[:emails] [:contacts {:get [:=:type"email"]}:#]]   [[:phones] [:contacts {:get [:=:type"phone"]}:#]]])(bdm/import person mapping);; Will return;; {:name "John",;;  :lastname "Smith",;;  :emails [{:type "email", :value "john@smith.com"}],;;  :phones [{:type "phone", :use "home", :value "12223334455"};;           {:type "phone", :use "vork", :value "15556667788"}]};; We can do import/export roundtrip(= person (bdm/export (bdm/import person mapping) mapping));; => true

Concepts

Mapping

Mapping is a array ofpaths pairs. Firstpath of pair used as setter rule and second as a getter rule.

(defmapping  [[[:username] [:login]]])(defuser  {:login"super-user"})(bdm/import user mapping);; will return;; {:username "super-user"}(defimported-user  {:username"super-user"})(bdm/export imported-user mapping);; will return;; {:login "super-user"}

In this sample we take value fromuser by path[:login] and set this value into result with path[:username].

Path can be deep

(defwindow-mapping  [[[:hash] [:window:location:hash]]   [[:path] [:window:location:pathname]]])(defwindow  {:window {:location {:hash"#about":pathname"/index.html"}}})(bdm/import window window-mapping);; Will return;; {:hash "#about";;  :path "/index.html"}(deflocation {:hash"#contact":path"/spa.html"})(bdm/export location window-mapping);; Will return;; {:window {:location {:hash     "#contact";;                      :pathname "/spa.html"}}})

Path

...

Short alias

...

Predicates and arrays

...

Setters

...

Submapping

...

Develop

# run repl$ make repl# run test$ make test

Extra

For more details and usage details see tests.

MIT License Copyright (c) 2020 Marat Surmashev

About

BDM is super simple, fully declarative clj/cljc bi directional mapper.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp