Saltearse al contenido

PostgreSQL Repository

Esta página aún no está disponible en tu idioma.

The einar-cli allows you to install PostgreSQL GORM dependencies, include them directly in your code, and generate repositories for PostgreSQL database operations.

🗄️ PostgreSQL installation

Inside your project directory, run the following command to include PostgreSQL GORM in your project:

Terminal window
einar install postgresql

This will generate the following files and directories within your project, setting up the necessary infrastructure for PostgreSQL interaction:

Terminal window
/app
/shared
/infrastructure
/postgresql
- connection.go

👨‍💻 Generate a New Custom Repository

Inside your project directory, run the following command to create a new custom repository:

Terminal window
einar generate postgresql-repository save-customer

Here’s an example of how the generated code will look:

Terminal window
type SaveCustomer func(ctx context.Context, input interface{}) error
func init() {
ioc.Registry(
NewSaveCustomer,
postgresql.NewConnection)
}
func NewSaveCustomer(connection *gorm.DB) SaveCustomer {
return func(ctx context.Context, input interface{}) error {
return nil
}
}