-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* examples - first commit. extra containers info not needed in components, this data is already available via the fns containing-parents/contained-children. * minor fixes in text * preprocess patterns in conditional matches * docstring support for dataflows * customer loyalty example * add resolver example
- Loading branch information
1 parent
63267c7
commit 6293e21
Showing
12 changed files
with
265 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
(component :Loyalty.Core) | ||
|
||
(entity :Customer | ||
{:Email {:type :Email :guid true} | ||
:Name :String | ||
:Joined :Now}) | ||
|
||
(entity :Point | ||
{:Value :Int | ||
:Created :Now | ||
:meta {:doc "Loyalty point earned by a customer for each purchase."}}) | ||
|
||
(relationship :Points | ||
{:meta {:between [:Customer :Point]}}) | ||
|
||
(entity :Purchase | ||
{:CustomerEmail :Email | ||
:InvoiceNo {:type :String :guid true} | ||
:Date :Now | ||
:Amount :Decimal}) | ||
|
||
(defn compute-points | ||
"Compute the loyalty point based on the purchase amount." | ||
[amt] | ||
(cond | ||
(>= amt 5000.0) 10 | ||
(>= amt 2000.0) 5 | ||
:else 2)) | ||
|
||
(dataflow [:after :create :Purchase] | ||
"When a new purchase happens, use its amount to compute | ||
a loyalty point for the customer." | ||
[:match | ||
[:> :Instance.Amount 1000.0] | ||
{:Point {:Value '(compute-points :Instance.Amount)} | ||
:-> [[{:Points {}} {:Customer {:Email? :Instance.CustomerEmail}}]]} | ||
:Instance]) | ||
|
||
(defn total-points [ps] | ||
(reduce + 0 (map :Value ps))) | ||
|
||
(dataflow :FetchPoints | ||
"Return the total loyalty-points for a customer." | ||
{:Point? {} :-> [[{:Points {:Customer? :FetchPoints.CustomerEmail}}]] | ||
:as :Result} | ||
[:eval '(total-points :Result)]) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{:name :loyalty | ||
:doc "Customer Loyalty Program Management" | ||
:version "0.0.1" | ||
:fractl-version "current" | ||
:components [:Loyalty.Core]} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{:name :school | ||
:version "0.0.1" | ||
:fractl-version "current" | ||
:components [:School.Core]} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
(component :School.Core) | ||
|
||
(entity | ||
:School | ||
{:Name {:type :String :guid true} | ||
:RegistrationNumber {:type :String :unique true} | ||
:Address :String}) | ||
|
||
(attribute | ||
:Gender | ||
{:oneof ["M" "F"]}) | ||
|
||
(entity | ||
:Student | ||
{:EnrollmentNumber {:type :Int :id true} | ||
:Id :Identity | ||
:Name :String | ||
:Age :Int | ||
:Gender :Gender | ||
:EnrollmentDate :Date}) | ||
|
||
(entity | ||
:ParentInfo | ||
{:Address :String | ||
:ParentName :String | ||
:ParentEmail :Email | ||
:ParentPhoneNumber :String}) | ||
|
||
(relationship | ||
:ParentInfoForStudent | ||
{:meta {:between [:Student :ParentInfo]}}) | ||
|
||
(relationship | ||
:StudentOf | ||
{:meta {:contains [:School :Student]}}) | ||
|
||
(entity | ||
:Teacher | ||
{:StaffNumber {:type :Int :id true} | ||
:Id :Identity | ||
:Name :String | ||
:Age :Int | ||
:Gender :Gender | ||
:Designation :String | ||
:Qualification :String | ||
:JoiningDate :Date}) | ||
|
||
(entity | ||
:ContactInfo | ||
{:Address :String | ||
:Email :Email | ||
:PhoneNumber :String}) | ||
|
||
(relationship | ||
:TeacherContactInfo | ||
{:meta {:between [:Teacher :ContactInfo]}}) | ||
|
||
(relationship | ||
:StaffOf | ||
{:meta {:contains [:School :Teacher]}}) | ||
|
||
(entity | ||
:Class | ||
{:Id :Identity | ||
:Name :String | ||
:Grade :String | ||
:meta {:unique [:Name :Grade]}}) | ||
|
||
(entity | ||
:Subject | ||
{:Name {:type :String :guid true} | ||
:Texts {:listof :String}}) | ||
|
||
(relationship | ||
:ClassTeacher | ||
{:meta {:between [:Teacher :Class]}}) | ||
|
||
(relationship | ||
:TeachingAssignment | ||
{:meta {:between [:Teacher :Subject]} | ||
:AssignedOn :Now | ||
:Class {:ref :Class.Id}}) | ||
|
||
(relationship | ||
:Enrollment | ||
{:meta {:between [:Student :Class]} | ||
:EnrolledOn :Now}) | ||
|
||
(entity | ||
:Attendance | ||
{:Date :Now | ||
:Present :Boolean}) | ||
|
||
(relationship | ||
:ClassAttendance | ||
{:meta {:between [:Student :Attendance]}}) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{:name :todo | ||
:doc "TODO app with custom data-store." | ||
:version "0.0.1" | ||
:fractl-version "current" | ||
:components [:Todo.Core]} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
(component :Todo.Core) | ||
|
||
;; This example shows how to persist instances of an | ||
;; entity (:TodoEntry) in a custom format. | ||
;; This is achieved via a custom "resolver" that writes | ||
;; and reads :TodoEntry instances to a file in a user-specified | ||
;; format. | ||
|
||
(entity :TodoEntry | ||
{:Content :String | ||
:DateCreated :Now}) | ||
|
||
(def buffer (atom nil)) | ||
(def todo-file ".todo") | ||
|
||
(defn refresh-buffer! [] | ||
(try | ||
(reset! buffer (read-string (slurp todo-file))) | ||
(catch Exception _ nil))) | ||
|
||
(defn flush-buffer! [] | ||
(spit todo-file @buffer)) | ||
|
||
(defn upsert [inst] | ||
(when-not @buffer | ||
(refresh-buffer!)) | ||
(swap! buffer conj [(:DateCreated inst) (:Content inst)]) | ||
(flush-buffer!) | ||
inst) | ||
|
||
(defn as-todo-entry [[date-created content]] | ||
{:Content content | ||
:DateCreated date-created}) | ||
|
||
(defn lookup-entries [[_ query]] | ||
(when-not @buffer | ||
(refresh-buffer!)) | ||
(let [[_ _ value] (:where query) | ||
entries (filter #(clojure.string/index-of (second %) value) @buffer)] | ||
(mapv as-todo-entry entries))) | ||
|
||
(def todo-resolver | ||
(fractl.resolver.core/make-resolver | ||
:todo.resolver ; a unique name for the resolver. | ||
{:create upsert | ||
:query lookup-entries})) | ||
|
||
(fractl.resolver.registry/override-resolver :Todo.Core/TodoEntry todo-resolver) |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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