PostgreSQL Repository
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:
einar install postgresqlThis will generate the following files and directories within your project, setting up the necessary infrastructure for PostgreSQL interaction:
/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:
einar generate postgresql-repository save-customerHere’s an example of how the generated code will look:
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 }}