gorm

package
v0.7.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package gorm provides a GORM-based implementation of the UsersService. It supports any database that GORM supports (PostgreSQL, MySQL, SQLite, etc.) and is suitable for production deployments requiring relational database storage.

Database Schema

The service uses auto-migration to create/update the users table:

CREATE TABLE users (
    id VARCHAR PRIMARY KEY,
    created_at TIMESTAMP,
    updated_at TIMESTAMP,
    name VARCHAR,
    description TEXT,
    tags JSON,           -- Stored as JSON array
    image_url VARCHAR,
    email VARCHAR,
    extras JSON          -- App-specific data as JSON
);

Generated Code

This package uses protoc-gen-dal-gorm generated code:

  • UserGORM: GORM model with proper tags
  • UserGORMToUser/UserToUserGORM: conversion functions
  • UserGORMDAL: data access layer with CRUD operations

Usage

db, _ := gorm.Open(postgres.Open(dsn), &gorm.Config{})
userService := gormbe.NewUsersService(db)
resp, err := userService.CreateUser(ctx, &v1.CreateUserRequest{
    User: &v1.User{Name: "John Doe", Email: "john@example.com"},
})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type UsersService

type UsersService struct {
	services.BaseUsersService

	MaxPageSize int
	UserDAL     v1dal.UserGORMDAL
	// contains filtered or unexported fields
}

UsersService implements services.UsersService using GORM. It embeds BaseUsersService to inherit caching and shared operations.

func NewUsersService

func NewUsersService(db *gorm.DB) *UsersService

NewUsersService creates a new GORM-backed UsersService. It automatically runs database migrations to ensure the schema is up to date.

func (*UsersService) CreateUser

CreateUser creates a new user profile.

func (*UsersService) DeleteFromStorage

func (s *UsersService) DeleteFromStorage(ctx context.Context, id string) error

DeleteFromStorage implements UserStorageProvider.

func (*UsersService) ListAllUsers

func (s *UsersService) ListAllUsers(ctx context.Context) ([]*v1.User, error)

ListAllUsers implements UserStorageProvider.

func (*UsersService) LoadUser

func (s *UsersService) LoadUser(ctx context.Context, id string) (*v1.User, error)

LoadUser implements UserStorageProvider.

func (*UsersService) SaveUser

func (s *UsersService) SaveUser(ctx context.Context, id string, user *v1.User) error

SaveUser implements UserStorageProvider.

func (*UsersService) UpdateUser

UpdateUser updates an existing user profile.

func (*UsersService) UserExists

func (s *UsersService) UserExists(ctx context.Context, id string) bool

UserExists implements UserStorageProvider.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL