{"id":20393169,"url":"https://github.com/aichbauer/database","last_synced_at":"2025-07-29T22:38:08.342Z","repository":{"id":82477439,"uuid":"430796771","full_name":"aichbauer/database","owner":"aichbauer","description":"database","archived":false,"fork":false,"pushed_at":"2021-11-22T17:13:11.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-02T13:52:31.725Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","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/aichbauer.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-22T17:08:18.000Z","updated_at":"2021-11-22T17:13:14.000Z","dependencies_parsed_at":"2023-03-11T01:45:22.597Z","dependency_job_id":null,"html_url":"https://github.com/aichbauer/database","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/aichbauer/database","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aichbauer%2Fdatabase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aichbauer%2Fdatabase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aichbauer%2Fdatabase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aichbauer%2Fdatabase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aichbauer","download_url":"https://codeload.github.com/aichbauer/database/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aichbauer%2Fdatabase/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267772816,"owners_count":24142095,"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","status":"online","status_checked_at":"2025-07-29T02:00:12.549Z","response_time":2574,"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":[],"created_at":"2024-11-15T03:47:44.412Z","updated_at":"2025-07-29T22:38:08.321Z","avatar_url":"https://github.com/aichbauer.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Database\n\n\u003e This Repo educates about the usage of Data Access Objects and Repositories\n\nThe DAO (Data Access Object) and the Repository Pattern tend to be interchangeable in data centric applications, but there are differences especially if you focus on solving business use cases.\n\nA DAO is an abstraction of the data persistence layer on a low level. A DAO often matches database tables and focus on a single Entity or Model.\n\nA Repository on the other hand is also an abstraction of the data persistence layer but on a higher level. A Repository often matches multiple database tables and focus on the relation between multiple Entities or Models. \n\n## Start the DB\n \n\u003e**!!! NEVER COMMIT DATABASE CREDENTIALS TO A GIT REPOSITORY !!!**\n\nMake sure to have Docker installed and running.\n\n```sh\n# --rm - delete the container when stopped\n# --detach - start the db in a background process\n# --name - name of the container\n# -e - environment variables (we set user and pw)\n# -p - port mapping hostport:containerport\n# -v - cerate a volume to persist data between container starts and removing containers\n# nameofthevolume:/path/in/the/container/we/want/persisted\n# postgres is the image\n$ docker run --rm --detach --name swe1db -e POSTGRES_USER=swe1user -e POSTGRES_PASSWORD=swe1pw -v data:/var/lib/postgresql/data -p 5431:5432 postgres\n#\n# open a terminal within a container\n# exec - run a command in a container (e.g. bash)\n# -i - interactive means to keep STDIN open\n# -t - allocate a pseudo-TTY, add a terminal driver\n# - it basically makes the container start look like a terminal connection session\n# bash - the command that is executed inside the container  \n$ docker exec -it swe1db bash\n# inside the container connect to the postgresql\n# -p - port, -h - host, -U - user\n$ psql -p 5431 -h localhost -U swe1user\n# inside postgresql\n# list all databases\n$ \\l\n# create new db\n$ CREATE DATABASE swe1db;\n# list all databases and confirm that new db exists\n$ \\l\n# add privledges (in production you should really carefully select which privledges arre allowed) we simply add everything\n$ GRANT ALL PRIVILEGES ON DATABASE swe1db TO swe1user;\n# connect to db\n$ \\c swe1db\n# create a table\n# https://www.postgresql.org/docs/9.5/datatype.html\n# https://www.postgresql.org/docs/9.4/ddl-constraints.html\n$ CREATE TABLE users (\n\tid serial PRIMARY KEY,\n\tpassword VARCHAR (50) NOT NULL,\n\tfirst_name VARCHAR (255) NOT NULL,\n\tlast_name VARCHAR (255) NOT NULL,\n\tuser_name VARCHAR(255) UNIQUE NOT NULL,\n\temail VARCHAR(255) UNIQUE NOT NULL,\n\tcreated_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP\n);\n# list all tables in db\n$ \\dt\n# create a table\n# https://www.postgresql.org/docs/9.5/datatype.html\n# https://www.postgresql.org/docs/9.4/ddl-constraints.html\n$ CREATE TABLE tweets (\n\tid serial PRIMARY KEY,\n\tmessage VARCHAR (144) NOT NULL,\n\tuser_id INT,\n\tcreated_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\n\tCONSTRAINT fk_user\n\t  FOREIGN KEY(user_id)\n\t    REFERENCES users(id)\n);\n# list all tables in db\n$ \\dt\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faichbauer%2Fdatabase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faichbauer%2Fdatabase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faichbauer%2Fdatabase/lists"}