Nothing Special   »   [go: up one dir, main page]

Skip to content

younesious/GORM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GORM Golang Project

This project demonstrates a Golang application utilizing GORM for ORM and implementing tests for the functionalities.

Introduction

GORM is a powerful ORM library for Go, designed to simplify database operations and streamline development workflows. This project demonstrates various GORM features and best practices through a simple yet comprehensive example application.

Project Structure

The project consists of the following files:

  • db.go: Contains the implementation of the database connection using the singleton design pattern.
  • main.go: Defines the main functionalities of the application.
  • main_test.go: Contains test cases for the implemented functionalities.
  • go.mod and go.sum: Files generated by Go modules to manage dependencies.

Database Setup

The project connects to a PostgreSQL database. Modify the connection parameters (user, password, host, port, dbname) in db.go according to your PostgreSQL setup.

Functionality

  • GetConnection(): Establishes a connection to the database using the singleton pattern.
  • RefreshDatabase(): Refreshes the database by dropping existing tables and recreating them.
  • SeedUser(): Seeds the database with user data, including calendars and appointments.
  • UserWithRangeAppointmentScope(): Defines a scope to retrieve users with appointments within a specified date range and calendar name.
  • UpdateAppointment(): Updates appointment start time and description based on calendar name and keyword.

Test Cases

  • TestDatabaseConnectionAndAutoMigrate(): Tests the database connection and auto-migration of tables.
  • TestUserTable(), TestCalendarTable(), TestAppointmentTable(), TestTaskListTable(): Tests the structure of each database table.
  • TestUserCalendarRelationship(), TestCalendarAppointmentRelationship(), TestTaskListAppointmentRelationship(), TestUserAppointmentRelationship(): Tests the relationships between database tables.
  • TestRefreshDatabase(): Tests the refresh database functionality.
  • TestSeedUser(): Tests the seed user functionality.
  • TestUserWithRangeAppointmentScope(): Tests the user appointment scope functionality.
  • TestUpdateAppointment(): Tests the update appointment functionality.

Database Relationships

  • Each user has a calendar, and each calendar belongs to a user.
  • Each user can have several appointments, and each appointment can have several users (through the appointment_user table).
  • Each calendar can have several appointments.
  • Each task list can have several appointments.
  • Whenever an appointment belongs to a calendar or task list.

Setup

  1. Clone the repository: git clone <repository-url>
  2. Navigate to the project directory: cd <project-directory>
  3. Modify the database connection parameters in db.go if necessary.
  4. Run the tests: go test -v

Requirements

  • Go 1.16 or higher
  • PostgreSQL database

Note

This project was inspired by the need for a practical guide to working with GORM in Golang. it's a good starting point for learning about GORM and getting familiar with its features.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages