{"id":16681804,"url":"https://github.com/sveri/closp-crud","last_synced_at":"2025-04-09T23:12:46.897Z","repository":{"id":29581833,"uuid":"33121596","full_name":"sveri/closp-crud","owner":"sveri","description":"Plugin for closp providing generation of crud modules","archived":false,"fork":false,"pushed_at":"2017-04-26T13:40:48.000Z","size":114,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-09T23:12:37.501Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/sveri.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.MD","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":"2015-03-30T12:24:27.000Z","updated_at":"2017-12-15T16:57:54.000Z","dependencies_parsed_at":"2022-09-14T23:05:56.037Z","dependency_job_id":null,"html_url":"https://github.com/sveri/closp-crud","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sveri%2Fclosp-crud","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sveri%2Fclosp-crud/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sveri%2Fclosp-crud/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sveri%2Fclosp-crud/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sveri","download_url":"https://codeload.github.com/sveri/closp-crud/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248125589,"owners_count":21051770,"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":[],"created_at":"2024-10-12T14:05:20.296Z","updated_at":"2025-04-09T23:12:46.875Z","avatar_url":"https://github.com/sveri.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# closp-crud\n\n\n# This projet is deprecated and integrated directly within \u003chttps://github.com/sveri/closp\u003e\n\n\n\n\n\nA Leiningen plugin to provide CRUD functionality for clojure web projects. Optimized for the usage\nwithin \u003chttps://github.com/sveri/closp\u003e.\n\n## Rationale\n\nI find it tedious to create a lot of stuff manually like most developers do. And some day while playing around \nwith clojure web stuff it occured to me that I need some kind of CRUD functionality again and again.\n\nThat's why I started **closp-crud**. It's the first release and does not contain much functionality. However, it should\nbe enough to get going with a very basic UI.\n\n### Disclaimer\n\nI only did some basic tests. Given the fact that there are many million differnt ways this library can be used, please\nbe aware that there will be bugs and missing functionality. I am happy about either, bug reports or pull requests.\nAlso suggestions of any kind are welcome.\n\n## Usage\n\nThere are two ways to use **closp-crud**. First, you can use it standalone or second\nas part of [closp](https://github.com/sveri/closp) which it comes integrated with.\n\n### As part of **closp**\n\nYou need a table definition in a file somewhere. It may look like this:\n\n    ; closp-definitions/person.edn\n    {:name    \"person\"\n     :columns [{:name \"id\" :type :int :null false :pk true :autoinc true}\n               {:name \"first_name\" :type :varchar :max-length 30}\n               {:name \"last_name\" :type :varchar :max-length 30}\n               {:name \"role\" :type :varchar :max-length 30}\n               {:name \"email\" :type :varchar :max-length 30 :null false :unique true}]}\n               \nThen run\n\n    $ lein run -m de.sveri.clospcrud.closp-crud/closp-crud -f closp-definitions/person.edn\n    \nThis will generate several files:\n\n* Up and down file in `./migrations` containing the SQL code to create and drop a person table.\n* A database clj source file in `de/sveri/siwf/db/person.clj` containing the source to do CRUD operations on \nthe person table using [korma](https://github.com/korma/Korma/)\n* A routes clj source file in `de/sveri/siwf/routes/person.clj` containing the route definitions using compojure\nand noir.\n* Several html files containing three templates: `index.html, create.html and delete.html`\n\nFinally you need to add the generated routes definition (person-routes) from `routes/person.clj` to your handler in\n`ns.handler` in the `get-handler` function under *;; add your application routes here*.\n \n\n\n## Options\n\n* **-f** **Mandatory** The path to the table definition file. \n\n## Dependencies \n\nThis plugin only works if the following libraries exist in your classpath:\n\n* lib-noir\n* compojure\n* timbre\n* korma\n* plumatic/schema\n\n## Prerequisites\n\n`closp-crud` expects a layout namespace containing a render function. This will be used to render the templates and\ncan be configured via the project settings.\n`closp` provides a template here: \n\u003chttps://github.com/sveri/closp/blob/master/resources/leiningen/new/closp/clj/layout.clj\u003e\n\n## closp-crud.edn options\n\n`closp-crud` expects a `closp-crud.edn` file in your resources path. It expects several keys there, namely:\n\n### :jdbc-url \nThis is the jdbc uri that closp-crud will use to create the SQL files. This must be an accessible database. You cannot\nprovide fake uris here. \n\nThis will create a h2 database in memory. \n    \n    :jdbc-url \"jdbc:h2:mem:test_mem\"\n    \n### :migrations-output-path \nThe path where the generated SQL files will be stored. Can be anywhere, but should be somewhere where a migration\nlibrary can pick it up.\n\nExample:\n\n    :migrations-output-path \"./migrations\"\n    \n### :clj-src \nThe file path to your projects clj source files. Should be relativ to the current project.\n\nExample:\n\n    :clj-src \"src/clj\"\n    \n### :ns-db \nThe namespace where generated db functions will be written to.\n\nExample:\n\n    :ns-db \"de.sveri.siwf.db\"    \n### :ns-db-entities \nThe namespace where generated db entity declaration will be put.\n\nExample:\n\n    :ns-db-entities \"de.sveri.siwf.db.entities\"\n    \n### :ns-routes \nThe namespace where the generated routes will be written to.\n\nExample:\n\n    :ns-routes \"de.sveri.siwf.routes\"\n\n### :ns-layout \nThe namespace where your layout.clj with a given render function resides.\n\nExample:\n\n    :ns-layout \"de.sveri.siwf.layout\"\n    \n### :templates\nA file path where the generated html templates will be stored\n\nExample:\n\n    :templates \"resources/templates\"\n    \n    \n## Table Definition\nTable definitions are stored in edn files whereas one definition has to be in one file. Multiple definitions per\nfile are not supported.\n\nExample: \n\n    {:name    \"person\"\n     :columns [{:name \"id\" :type :int :null false :pk true :autoinc true}\n              {:name \"first_name\" :type :varchar :max-length 30}\n              {:name \"last_name\" :type :varchar :max-length 30}\n              {:name \"role\" :type :varchar :max-length 30}\n              {:name \"email\" :type :varchar :max-length 30 :null false :unique true}]}\n\n### Structure\nTwo key / value pairs are expected:\n\n* **:name** The name of the entity\n* **:columns** A vector of maps containing the description for each single column in the table.\n\n### Column definitions\nThe structure of the columns is somewhat flexible.\n\n* **Mandatory** `:name` - The name of the column\n* **Mandatory** `:type` - The type of the column wih can be one of the following:\n    :int :varchar :boolean :text :time :date\n    :char :binary :smallint :bigint :decimal\n    :float :double :real :timestamp\n    If you choose a `:char` or `:varchar` type it makes sense to add the `:max-length` option to the map. \n\n* **Optional** \n    :null       Bool\n    :max-length Num\n    :required   Bool\n    :pk         Bool\n    :autoinc    Bool\n    :unique     Bool\n    :default    s/Any\n\nExamples:\n\n* **{:name \"id\" :type :int :null false :pk true :autoinc true}** creates a primary key named \"id\" of type \"int\" which will \nautoincrement \n* **{:name \"age\" :type :int :null false}** creates an \"age\" column of type \"int\" which cannot be null\n* **{:name \"male\" :tpye :boolean :default true}** creates a \"male\" column of type \"boolean\"  which defaults to true and can be null.\n\n\nFor a complete reference of supported tags please look at: \u003chttp://www.liquibase.org/documentation/column.html\u003e\n\n## FAQ\n\n### Using h2 I get an error it cannot find columns or tables\n\nThis is due to the fact the h2 sticks to the SQL standards and some others don't.  \nTLDR: add _;DATABASE_TO_UPPER=FALSE_ to your database uris like this: _\"jdbc:h2:./db/korma.db;DATABASE_TO_UPPER=FALSE\"_  \n\nLong version is the SQL standards and this SO post: \n\u003chttp://stackoverflow.com/questions/10789994/make-h2-treat-quoted-name-and-unquoted-name-as-the-same\u003e\n\n### Standalone\n\n**Deprecated** I will still work standalone, but the documentation is not up to date. For a complete\nexample look at: \u003chttp://github.com/sveri/closp\u003e\n\nPlease be aware that **closp-crud** is tied to *closp*. It is possible to run it standalone,\nbut expects a certain structure, some dependencies and existing functions to call.\n\nPut `[de.sveri/closp-crud \"0.2.1\"]` into the `:dependencies` vector of your `project.clj` file.\n\nThen add the configuration to your `project.clj` file like this (see below for explanation of options):\n\n    :closp-crud {:jdbc-url \"jdbc:h2:mem:test_mem\"\n                 :migrations-output-path \"./migrations\"\n                 :clj-src \"src/clj\"\n                 :ns-db \"de.sveri.siwf.db\"\n                 :ns-routes \"de.sveri.siwf.routes\"\n                 :ns-layout \"de.sveri.siwf.layout\"\n                 :templates \"resources/templates\"}\n\nNext you need a table definition in a file somewhere. It may look like this:\n\n    ; closp-definitions/person.edn\n    {:name    \"person\"\n     :columns [[:id :int :null false :pk true :autoinc true]\n               [:name [:varchar 40] :null false]\n               [:age :int :null false]\n               [:male :boolean :default true]]}\n               \nThen run\n\n    $ lein run -m de.sveri.clospcrud.closp-crud/closp-crud -f closp-definitions/person.edn\n    \nThis will generate several files:\n\n* Up and down file in `./migrations` containing the SQL code to create and drop a person table.\n* A database clj source file in `de/sveri/siwf/db/person.clj` containing the source to do CRUD operations on \nthe person table using [korma](https://github.com/korma/Korma/)\n* A routes clj source file in `de/sveri/siwf/routes/person.clj` containing the route definitions using compojure\nand noir.\n* Several html files containing three templates: `index.html, create.html and delete.html`\n\nFinally you need to add the generated routes definition from `routes/person.clj` to your handler.\n\n## License\n\nCopyright © 2015 Sven Richter\n\nDistributed under the Eclipse Public License version 1.0.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsveri%2Fclosp-crud","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsveri%2Fclosp-crud","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsveri%2Fclosp-crud/lists"}