{"id":34985690,"url":"https://github.com/gkhays/db-primer","last_synced_at":"2026-04-16T05:04:45.564Z","repository":{"id":39852256,"uuid":"221830710","full_name":"gkhays/db-primer","owner":"gkhays","description":"Interacting with a database in an enterprise environment","archived":false,"fork":false,"pushed_at":"2022-09-08T01:04:06.000Z","size":211,"stargazers_count":1,"open_issues_count":5,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-03-11T23:26:59.219Z","etag":null,"topics":["database","docker","hibernate","java","junit","liquibase","maven","orm","postgresql","tdd"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gkhays.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":"2019-11-15T02:49:17.000Z","updated_at":"2020-01-30T16:25:18.000Z","dependencies_parsed_at":"2022-08-27T17:20:51.910Z","dependency_job_id":null,"html_url":"https://github.com/gkhays/db-primer","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"purl":"pkg:github/gkhays/db-primer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkhays%2Fdb-primer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkhays%2Fdb-primer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkhays%2Fdb-primer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkhays%2Fdb-primer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gkhays","download_url":"https://codeload.github.com/gkhays/db-primer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkhays%2Fdb-primer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31872036,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-15T15:24:51.572Z","status":"online","status_checked_at":"2026-04-16T02:00:06.042Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["database","docker","hibernate","java","junit","liquibase","maven","orm","postgresql","tdd"],"created_at":"2025-12-27T01:32:10.501Z","updated_at":"2026-04-16T05:04:45.558Z","avatar_url":"https://github.com/gkhays.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Database Primer\n\nThis project serves as an introduction to interacting with a database in an enterprise environment. As such, we use tools like Maven and Liquibase.\n\n## Getting Started\n\nThese instructions will get you up and running on your local PC. Sometimes we take our tool chains for granted but once in place they allow us to be quite productive. In this project we introduce a handful of tools that professional developers keep in their \"tool kit.\"\n\n### Prerequisites\n\nSince this is about Structured Query Language (SQL), one of the first things we will need access to is a database. In the \"old\" days we would have to either install a developer edition of a database server or convince a Database Administrator to let us use one of theirs! With the advent of containerization, we can bring a server of our own up almost immediately! All without having to install a bunch of dependencies on our PC.\n\n#### Docker\n\nIn this case, we are using Docker and a [PostgreSQL image](https://hub.docker.com/_/postgres?tab=description). Docker is fairly easy to install but for more guidance we have provided information in the [Docker section](https://github.com/gkhays/db-primer/wiki/Docker-for-Windows) of the [wiki](https://github.com/gkhays/db-primer/wiki). So be sure to check it out.\n\nWe prefer `docker-compose` because it is suitable for orchestration and reduces the number of parameters and options at invocation time. Using it, bring up an instance of PostgreSQL.\n\n```bash\ndocker-compose up -d db\n```\n\nFor the curious, a recipe is located in the `docker-compose.yml` file, located in the root of this project.\n\n**Optional**: For those desiring more control, the same outcome can be achieved by using Docker directly.\n\n```bash\ndocker pull postgres:10.5-alpine\ndocker run -d -p 5432:5432 postgres:10.5-alpine\n```\n\n#### Git\n\nYou will need Git to retrieve the source code for this project. Instructions for installing Git appear in the [Git section](https://github.com/gkhays/db-primer/wiki/Git-for-Windows) of the [wiki](https://github.com/gkhays/db-primer/wiki).\n\n**Optional**: If you are new to Git or prefer to use a graphical interface, [GitHub Desktop](https://desktop.github.com/) is a very good tool.\n\n#### Java\n\nThe project requires a Java JDK so that Maven may function correctly. We recommend the [Zulu Community OpenJDK](https://www.azul.com/downloads/zulu-community/?\u0026architecture=x86-64-bit\u0026package=jdk) Java 8 (LTS) version.\n\n#### Maven\n\nMaven is an imperative build and dependency management tool that enforces a certain structure on Java software projects. It is favored by enterprise software development in order to facilitate repeatable, predictable builds. It also features a rich ecosystem of plugins, several of which we employ in this project. Detailed instruction for installing it are under the [Maven section](https://github.com/gkhays/db-primer/wiki/Maven) in the [wiki](https://github.com/gkhays/db-primer/wiki).\n\n### Installing\n\nClone this repository.\n\n```bash\ngit clone https://github.com/gkhays/db-primer\ncd db-primer\n```\n\nThen install the database. This is done using the following Maven invocation from a command line prompt.\n\n```bash\nmvn clean install -Ddb.create\n```\n\nIf the database already exists it will be dropped. Then the tables are generated using [Liquibase](https://www.liquibase.org/) changesets. The changesets themselves are defined in [src/main/resources/changelog.xml](https://github.com/gkhays/db-primer/blob/master/src/main/resources/changelog.xml) in the resources section of the source code.\n\nYou can learn more about the Maven settings by looking through the `pom.xml` file in the root of this project.\n\n### Testing\n\nProgrammatic database access is accomplished through [Hibernate](https://hibernate.org/). A couple of tests have been created to demonstrate connectivity and interaction. Execute the test cases with Maven `test`.\n\n```bash\nmvn test\n```\n\nWhen writing new code, use `EntityManager`. If working on existing code, you may encounter the Hibernate `Session` object. Both approaches are encapsulated.\n\n## Interacting with the Database\n\nThere are many ways to interact with a database in the capacity of an administrator or user. We will briefly explore the pgAdmin 4 graphical user interface.\n\n### pgAdmin 4\n\nBring up a containerized instance of `pgAdmin 4`.\n\n```bash\ndocker-compose up -d pgadmin\n```\n\n**Optional**: Invoke from `docker run`.\n\n```bash\ndocker pull thajeztah/pgadmin4\ndocker run --rm -d -p 5050:5050 --name pgadmin thajeztah/pgadmin4\n```\n\nThen navigate to http://localhost:5050 in your browser.\n\nTo connect to the database, use the left hand browser panel. Right or context mouse click on Servers \u003e\u003e Create \u003e\u003e Server and give your server a name such as \"Local.\" Switch to the Connection tab and enter the connection information as follows.\n\n![Create Server](doc/images/create-server.png)\n\n**Note**: Depending on your network configuration you may have to enter your IP address.\n\nNow use the query tool by expanding your server by clicking on the `+` symbol (to the left of `Local` (if that is what you named your server). Further expand Databases and choose `devices`. Now right mouse click and choose `Query Tool...`.\n\n![Query Tool](doc/images/query-tool.png)\n\n#### Select Query\n\nThe first thing we will want to do is survey the `accesspoint` table by executing a `SELECT` query.\n\n```sql\nSELECT * FROM accesspoint;\n```\n\nThen click on `F5` or the little lightning bolt or `Execute/Refresh` button. If this is the first time, there will be no rows but the query tool will display the column headings.\n\n![SELECT](doc/images/empty-select.png)\n\n#### Insert Query\n\nInsert data into the `accesspoint` table. In the same window we used previously, replace the `SELECT` query with the following `INSERT` statments (all three). Again hit `F5` or the `Execute/Refresh` button.\n\n```sql\nINSERT INTO accesspoint (essid, bssid, vendor, channel)\nVALUES ('HoneyPot', 'c4:6e:1f:0c:82:03', 'TP-LINK TECHNOLOGIES CO. LTD.', 4);\n\nINSERT INTO accesspoint (essid, bssid, vendor, channel)\nVALUES ('Demo', '80:2a:a8:5a:fb:2a', 'Ubiquiti Networks Inc.', 11);\n\nINSERT INTO accesspoint (essid, bssid, vendor, channel)\nVALUES ('BELL456', '44:e9:dd:4f:c2:7a', 'Sagemcom Broadband SAS', 6);\n```\n\nPgAdmin will inform you if it successfully inserted the rows or display an error message otherwise.\n\nDisplay all the rows in the table. To view the results, we will use a little trick. Under the last insert statement, start a new line and retype the select query.\n\n```sql\nSELECT * FROM accesspoint;\n```\n\nNow using your mouse, highlight only the select statement and click `F5` or the `Execute/Refresh` button. This will only execute the select query while leaving the previous statement intact in the work area.\n\n![Insert Then Select](doc/images/insert-select.png)\n\nBe sure to continue exploring to become more familiar with the database and features of `pgAdmin`. For more information on SQL see the [corresponding section](https://github.com/gkhays/db-primer/wiki/SQL-Mini-Tutorial) in the [wiki](https://github.com/gkhays/db-primer/wiki).\n\nSee also the [Command-line section](https://github.com/gkhays/db-primer/wiki/Universal-Command-Line-Interface-for-SQL-Databases) of the [wiki](https://github.com/gkhays/db-primer/wiki) for a brief description of the `usql SQL` command-line utility.\n\n## Built With\n\n* [Maven](https://maven.apache.org/) - Dependency management\n* [Liquibase](https://www.liquibase.org/) - Database schema change management\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgkhays%2Fdb-primer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgkhays%2Fdb-primer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgkhays%2Fdb-primer/lists"}