{"id":26186938,"url":"https://github.com/ivarref/datomic-schema","last_synced_at":"2025-04-15T00:35:47.686Z","repository":{"id":57713746,"uuid":"132465607","full_name":"ivarref/datomic-schema","owner":"ivarref","description":"Simplified writing of Datomic schemas.","archived":false,"fork":false,"pushed_at":"2020-02-14T21:06:05.000Z","size":40,"stargazers_count":6,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T12:38:26.080Z","etag":null,"topics":["clojure","datomic"],"latest_commit_sha":null,"homepage":"","language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"epl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ivarref.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-07T13:37:07.000Z","updated_at":"2023-06-20T07:11:59.000Z","dependencies_parsed_at":"2022-09-18T06:36:32.849Z","dependency_job_id":null,"html_url":"https://github.com/ivarref/datomic-schema","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivarref%2Fdatomic-schema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivarref%2Fdatomic-schema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivarref%2Fdatomic-schema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivarref%2Fdatomic-schema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ivarref","download_url":"https://codeload.github.com/ivarref/datomic-schema/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248518649,"owners_count":21117713,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clojure","datomic"],"created_at":"2025-03-11T23:35:42.885Z","updated_at":"2025-04-15T00:35:47.667Z","avatar_url":"https://github.com/ivarref.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# datomic-schema\n\nSimplified writing of [Datomic schemas](https://docs.datomic.com/on-prem/schema.html).\n\n## Installation\n\n[![Clojars Project](http://clojars.org/ivarref/datomic-schema/latest-version.svg)](http://clojars.org/ivarref/datomic-schema)\n\nAdd `[ivarref/datomic-schema \"0.2.0\"]` to your dependency vector.\n\n## Syntax\n\nThe syntax is\n\n```\n#d/schema[[attribute-name cardinality? type toggles* docstring?]*]\n\nattribute-name = The name of your attribute\ncardinality    = :one or :many. Defaults to :one\ntype           = A type from the list below\ntoggles        = Zero or more toggles\ndocstring      = An optional documentation string\n\ntype           = :bigdec\n               | :bigint\n               | :boolean\n               | :bytes\n               | :double\n               | :float\n               | :instant\n               | :keyword\n               | :long\n               | :ref\n               | :string\n               | :symbol\n               | :uri\n               | :uuid\n               | tuple-type\n\ntuple-type     = Composite tuple: a 2-8 length vector referring other attributes\n               | Heterogeneous fixed length tuples: a 2-8 length vector referring scalar types such as :long, :string, etc.\n               | Homogeneous variable length tuples: a 1 length vector referring a single scalar type.\n\ntoggles        = :component\n               | :fulltext\n               | :id         ; alias for :identity\n               | :identity\n               | :index\n               | :indexed    ; alias for :index\n               | :no-history\n               | :unique\n\nEnums are also supported: #d/schema [[attribute-name :enum]]\n```\n\n## Example usage from REPL\n\n```clojure\n(require 'datomic-schema.core) ; namespace needs to be required so that reader literal is loaded\n\n#d/schema [[:entity/attr :one :string \"Documentation\"]]\n=\u003e [#:db{:ident       :entity/attr\n         :cardinality :db.cardinality/one\n         :valueType   :db.type/string\n         :doc         \"Documentation\"}]\n\n#d/schema [[:entity/attr :string]] ; default cardinality is :one\n=\u003e [#:db{:ident       :entity/attr\n         :cardinality :db.cardinality/one\n         :valueType   :db.type/string}]\n\n#d/schema [[:entity/attr :many :long]] ; cardinality :many\n=\u003e [#:db{:ident       :entity/attr\n         :cardinality :db.cardinality/many\n         :valueType   :db.type/long}]\n\n#d/schema [[:entity/id :uuid :id]] ; use :id toggle for :db.unique/identity\n=\u003e [#:db{:ident       :entity/id\n         :cardinality :db.cardinality/one\n         :valueType   :db.type/uuid\n         :unique      :db.unique/identity}]\n\n#d/schema [[:e/id :uuid :id]\n           [:e/info :string]] ; multiple attribute definitions\n=\u003e [#:db{:ident :e/id   :cardinality :db.cardinality/one :valueType :db.type/uuid :unique :db.unique/identity}\n    #:db{:ident :e/info :cardinality :db.cardinality/one :valueType :db.type/string}]\n\n#d/schema [[:entity/attr :enum]] ; enums\n=\u003e [#:db{:ident :entity/attr}]\n```\n\nand so forth.\n\n## Example usage with conformity\n\nIn order to use this library with [conformity](https://github.com/rkneufeld/conformity),\nyou will need to require the namespace so that the reader literal is loaded before `conformity` runs.\n\nAdd the following file to `resources/`:\n\n```\n;; resources/something.edn\n{:my-project/something-schema\n {:txes [#d/schema[[:something/title :one :string]\n                   [:something/author :one :uuid]]]}}\n```\n\nThen in your code:\n\n```clojure\n(ns my-project.something\n  (:require [datomic-schema.core] ; namespace needs to be required so that reader literal is loaded\n            [io.rkn.conformity :as c]\n            [datomic.api :as d]))\n\n(def uri \"datomic:mem://my-project\")\n(d/create-database uri)\n(def conn (d/connect uri))\n\n(def norms-map (c/read-resource \"something.edn\"))\n\n(println (str \"Has attribute? \" (c/has-attribute? (d/db conn) :something/title)))\n(c/ensure-conforms conn norms-map [:my-project/something-schema])\n(println (str \"Has attribute? \" (c/has-attribute? (d/db conn) :something/title)))\n```\n\n## Example development usage\n\n```clojure\n(ns dato-ivre.dev-demo\n  (:require [datomic.api :as d]\n            [datomic-schema.core])) ; namespace needs to be required so that reader literal is loaded\n\n(defn create-empty-in-memory-db []\n  (let [uri \"datomic:mem://pet-owners-test-db\"]\n    (d/delete-database uri)\n    (d/create-database uri)\n    (let [conn (d/connect uri)]\n      conn)))\n\n(def conn (create-empty-in-memory-db))\n\n@(d/transact conn #d/schema[[:m/id :string :id]\n                            [:m/info :string]])\n\n@(d/transact conn [{:m/id \"id1\" :m/info \"Hello\"}]) ; upsert (insert)\n\n@(d/transact conn [{:m/id \"id1\" :m/info \"Hello2\"}]) ; upsert (update)\n\n(println (d/pull (d/db conn) '[:*] [:m/id \"id1\"]))\n; {:db/id 17592186045418, :m/id id1, :m/info Hello2}\n```\n\n## Acknowledgements\n\nThis project is derived from [cognitect-labs/vase](https://github.com/cognitect-labs/vase).\nPlease see their [LICENSE](https://github.com/cognitect-labs/vase/blob/master/LICENSE).\n\n## License\n\nCopyright © 2015-2017 Cognitect, Inc. All rights reserved.\n\nCopyright © 2018-2020 Ivar Refsdal.\n\nDistributed under the Eclipse Public License either version 1.0 or (at\nyour option) any later version.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivarref%2Fdatomic-schema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fivarref%2Fdatomic-schema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivarref%2Fdatomic-schema/lists"}