{"id":20863350,"url":"https://github.com/howardabrams/clojure-yesql-xp","last_synced_at":"2025-07-11T09:38:24.359Z","repository":{"id":29462427,"uuid":"32998899","full_name":"howardabrams/clojure-yesql-xp","owner":"howardabrams","description":"Mini workshop scenario for learning YesQL and Clojure","archived":false,"fork":false,"pushed_at":"2015-04-03T00:01:36.000Z","size":132,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-12T14:49:38.920Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/howardabrams.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-27T17:06:59.000Z","updated_at":"2015-04-03T00:01:37.000Z","dependencies_parsed_at":"2022-09-06T17:52:02.939Z","dependency_job_id":null,"html_url":"https://github.com/howardabrams/clojure-yesql-xp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/howardabrams/clojure-yesql-xp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/howardabrams%2Fclojure-yesql-xp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/howardabrams%2Fclojure-yesql-xp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/howardabrams%2Fclojure-yesql-xp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/howardabrams%2Fclojure-yesql-xp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/howardabrams","download_url":"https://codeload.github.com/howardabrams/clojure-yesql-xp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/howardabrams%2Fclojure-yesql-xp/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264777876,"owners_count":23662555,"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-11-18T05:28:40.687Z","updated_at":"2025-07-11T09:38:24.293Z","avatar_url":"https://github.com/howardabrams.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"This contains the project files for a Workshop on Clojure +\n[YesQL][0].  YesQL is a way to connect your Clojure code to data\nhosted in some sort of data base. To fascilitate this workshop, we\ncreate a *virtual machine* to host the database server as well as\nloading up some interesting data to use as we explore this project.\n\nThis workshop assumes that you know the basics of Clojure as well as\nhaving a functional environment for writing Clojure. If you would like\nan introduction to Clojure, please see the Clojure Bridge worksheets\nor one of the many good books on the subject.\n\n\nVirtual Machine Provisioning\n----------------------------\n\nTo get started, download [VirtualBox][1] and [Vagrant][2], as we will\nuse them to stand up a Ubuntu virtual machine with all the goodies\ninstalled and configured (see the `Vagrantfile` if you want to run the\nprevisioning process locally).  The provisioning process installs\nMySQL and a running Clojure world.\n\nIf you are attending the mini-workshop, please run `vagrant up` prior\nto the meeting (which can take up to an hour). When you arrive at the\nworkshop run the `go` script.\n\nThe `go` script brings up the virtual machine (essentially, `vagrant\nup`) and then SSHs into the machine to start a `tmux` session with\na client to the MySQL database and a Clojure REPL.\n\n*Note:*: I actually find it helpful to run the following:\n\n    vagrant ssh-config \u003e\u003e $HOME/.ssh/config\n\nAs then I can `ssh yesql` directly.\n\n  [1]: https://www.virtualbox.org/\n  [2]: https://www.vagrantup.com/\n  [0]: https://github.com/krisajenkins/yesql\n\n\nBackground on the Data Set\n--------------------------\n\nIn order to really explore what can be done through the YesQL\ninterface, we need a data set. Preferably one that is:\n\n  * Small\n  * Multi-table\n  * Interesting\n\nA pretty tall order! Here are locations to site that contain ideas:\n\n  * http://deeplearning.net/datasets/\n  * https://data.sfgov.org/data?category=Energy%20and%20Environment\n  * http://mldata.org/\n  * https://www.civicapps.org/ (need to register to download this Portland City data sets\n  * https://aws.amazon.com/public-data-sets/ consists of huge, E2-specific datasets. Not really an option for this project.\n\nThe following are particular data sets that have potential:\n\n  * Wind Data: https://data.sfgov.org/Energy-and-Environment/San-Francisco-Wind-Monitoring-Data-Current/bkgs-xaqe\n  * Bird Identification: http://ebird.org/ebird/data/download\n  * County Business Census: https://www.census.gov/econ/cbp/download/\n  * Book Reviews: http://www2.informatik.uni-freiburg.de/~cziegler/BX/\n\nIn the end, the **Book Review** project includes 3 tables in SQL\nformat that is directly downloadable, so that is the winner for this\nproject.  See the `Vagrantboot/import-dataset.sh` script for how we\ndownload and install this dataset.\n\n\nDeveloping and Forking\n----------------------\n\nThis project was designed as an example for hosting mini Workshops for user groups.\nConsequently, one of the goals is to keep this Git project simple, including:\n\n  * `yesql-xp` ... The actual Clojure project\n  * `go` ... The script to start the workshop project\n  * `Vagrantfile` ... configuration for the virtual machine\n  * `Vagrantboot` ... All virtual machine scripts needed to start\n\n\nThe Workshop\n------------\n\nThe `go` script starts a headless REPL from this directory and opens\nit to port `4242`. Which means, you can have Emacs Cider connect to it\nwith:   `M-x cider-connect`\nAnd supply that with `localhost` and port `4242`.\n\n*Note:* The Clojure project is located in the `yesql-xp` directory,\nand we could follow along with instructions from [this site][3].\nHowever, I'm thinking that for this project, we could probably figure\nout how to explore it on our own.\n\nThe SQL query files for YesQL go in the `yesql-xp/resources` directory.\nCreate file, `book-count.sql` that contains (including the comments):\n\n    -- Counts the number of books. Notice this uses the un-standard MySQL\n    -- syntax that requires the table name to be surrounded in backquotes.\n\n    SELECT count(*) AS count\n    FROM `BX-Books`;\n\nAssuming you can connect to the running REPL running on `localhost` on port 4242,\nget the `defquery` function:\n\n    (require '[yesql.core :refer [defquery]])\n\nAnd let's associate our SQL file with a variable:\n\n    (defquery num-books \"book-count.sql\")\n\nNow `num-books` references the SQL file: `yesql-xp/resources/book-count.sql`\n\nTyping: `(clojure.repl/doc num-books)` gets that query's documentation\n(e.g. comments). Pretty nice.\n\nTo write some Clojure code to use this SQL \"function\" and connect to\nthe database to have it evaluated, edit `yesql-xp/src/yesql_xp/core.clj`\n(or use the REPL), and create a *database connector specification* to\nconnect to our MySQL database:\n\n    (def db-spec {:classname \"com.mysql.jdbc.Driver\"\n                  :subprotocol \"mysql\"\n                  :subname \"//localhost:3306/bx\"\n                  :user \"root\"\n                  :password \"byebye\"})\n\nNow, let's call the `num-books` function. Keep in mind, the parameter\nis this database connector specification is the first parameter. Any\nother variables that should be substituted in the query go after this:\n\n    (num-books db-spec)\n\nWhat's next?\n\nAt this point, we should explore the database tables in the `mysql`\nclient (in the `tmux` session, type `Ctrl-b 1`, and use commands like\n`show tables;` to get to know the schema.\n\nNext, create SQL queries in the `yesql-xp/resources` directory. These\nshould work the same as the queries typed into the MySQL client REPL.\n\nFinally, edit the `core.clj` file to see just how the YesQL interface\nexposes those queries to Clojure.\n\n\n\n  [3]: https://fitacular.com/blog/clojure/web/2014/07/25/clojure-migration-examples/\n  [4]: http://www.luminusweb.net/docs/database.md\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhowardabrams%2Fclojure-yesql-xp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhowardabrams%2Fclojure-yesql-xp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhowardabrams%2Fclojure-yesql-xp/lists"}