dbEntities

package
v0.36.0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

README

dbEntities Package

This package contains database entity mapping structs that convert PostgreSQL query results to domain models.

Purpose

The dbEntities package provides a centralized location for database-to-model conversion logic, separating data mapping concerns from the business logic in the postgres package.

Exported Types

User (and UserProvider)

The User type is exported so it can be used across packages:

import "github.com/getfider/fider/app/services/sqlstore/dbEntities"

var user dbEntities.User
err := trx.Get(&user, "SELECT id, name, email... FROM users WHERE id = $1", userID)
if err != nil {
    return err
}

// Convert to entity.User
entityUser := user.ToModel(ctx)

Unexported Types

All other types (comment, post, tag, tenant, etc.) are unexported (lowercase) and only used internally by the postgres package. They can be exported later if needed by simply capitalizing the type name and its toModel method.

Testing

The package includes unit tests for the exported User type. Run them with:

godotenv -f .test.env go test ./app/services/sqlstore/dbEntities/...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Comment

type Comment struct {
	ID             int            `db:"id"`
	Content        string         `db:"content"`
	CreatedAt      time.Time      `db:"created_at"`
	User           *User          `db:"user"`
	Attachments    []string       `db:"attachment_bkeys"`
	EditedAt       dbx.NullTime   `db:"edited_at"`
	EditedBy       *User          `db:"edited_by"`
	ReactionCounts dbx.NullString `db:"reaction_counts"`
	IsApproved     bool           `db:"is_approved"`
}

func (*Comment) ToModel

func (c *Comment) ToModel(ctx context.Context) *entity.Comment

type EmailVerification

type EmailVerification struct {
	ID         int                        `db:"id"`
	Name       string                     `db:"name"`
	Email      string                     `db:"email"`
	Key        string                     `db:"key"`
	Code       dbx.NullString             `db:"code"`
	Kind       enum.EmailVerificationKind `db:"kind"`
	UserID     dbx.NullInt                `db:"user_id"`
	CreatedAt  time.Time                  `db:"created_at"`
	ExpiresAt  time.Time                  `db:"expires_at"`
	VerifiedAt dbx.NullTime               `db:"verified_at"`
	Attempts   int                        `db:"attempts"`
}

func (*EmailVerification) ToModel

type OAuthConfig

type OAuthConfig struct {
	ID                int            `db:"id"`
	Provider          string         `db:"provider"`
	DisplayName       string         `db:"display_name"`
	LogoBlobKey       string         `db:"logo_bkey"`
	Status            int            `db:"status"`
	IsTrusted         bool           `db:"is_trusted"`
	ClientID          string         `db:"client_id"`
	ClientSecret      string         `db:"client_secret"`
	AuthorizeURL      string         `db:"authorize_url"`
	TokenURL          string         `db:"token_url"`
	Scope             string         `db:"scope"`
	ProfileURL        string         `db:"profile_url"`
	JSONUserIDPath    string         `db:"json_user_id_path"`
	JSONUserNamePath  string         `db:"json_user_name_path"`
	JSONUserEmailPath string         `db:"json_user_email_path"`
	JSONUserRolesPath sql.NullString `db:"json_user_roles_path"`
	AllowedRoles      sql.NullString `db:"allowed_roles"`
}

func (*OAuthConfig) ToModel

func (m *OAuthConfig) ToModel() *entity.OAuthConfig

type Post

type Post struct {
	ID             int            `db:"id"`
	Number         int            `db:"number"`
	Title          string         `db:"title"`
	Slug           string         `db:"slug"`
	Description    string         `db:"description"`
	CreatedAt      time.Time      `db:"created_at"`
	Search         []byte         `db:"search"`
	User           *User          `db:"user"`
	HasVoted       bool           `db:"has_voted"`
	VotesCount     int            `db:"votes_count"`
	CommentsCount  int            `db:"comments_count"`
	RecentVotes    int            `db:"recent_votes_count"`
	RecentComments int            `db:"recent_comments_count"`
	Status         int            `db:"status"`
	Response       dbx.NullString `db:"response"`
	RespondedAt    dbx.NullTime   `db:"response_date"`
	ResponseUser   *User          `db:"response_user"`
	OriginalNumber dbx.NullInt    `db:"original_number"`
	OriginalTitle  dbx.NullString `db:"original_title"`
	OriginalSlug   dbx.NullString `db:"original_slug"`
	OriginalStatus dbx.NullInt    `db:"original_status"`
	Tags           pq.StringArray `db:"tags"`
	IsApproved     bool           `db:"is_approved"`
}

func (*Post) ToModel

func (i *Post) ToModel(ctx context.Context) *entity.Post

type StripeBillingState

type StripeBillingState struct {
	StripeCustomerID     dbx.NullString `db:"stripe_customer_id"`
	StripeSubscriptionID dbx.NullString `db:"stripe_subscription_id"`
	PaddleSubscriptionID dbx.NullString `db:"paddle_subscription_id"`
}

type Tag

type Tag struct {
	ID       int    `db:"id"`
	Name     string `db:"name"`
	Slug     string `db:"slug"`
	Color    string `db:"color"`
	IsPublic bool   `db:"is_public"`
}

func (*Tag) ToModel

func (t *Tag) ToModel() *entity.Tag

type Tenant

type Tenant struct {
	ID                    int          `db:"id"`
	Name                  string       `db:"name"`
	Subdomain             string       `db:"subdomain"`
	CNAME                 string       `db:"cname"`
	Invitation            string       `db:"invitation"`
	WelcomeMessage        string       `db:"welcome_message"`
	WelcomeHeader         string       `db:"welcome_header"`
	DescriptionTemplate   string       `db:"description_template"`
	Status                int          `db:"status"`
	Locale                string       `db:"locale"`
	IsPrivate             bool         `db:"is_private"`
	LogoBlobKey           string       `db:"logo_bkey"`
	CustomCSS             string       `db:"custom_css"`
	AllowedSchemes        string       `db:"allowed_schemes"`
	IsEmailAuthAllowed    bool         `db:"is_email_auth_allowed"`
	IsFeedEnabled         bool         `db:"is_feed_enabled"`
	PreventIndexing       bool         `db:"prevent_indexing"`
	IsModerationEnabled   bool         `db:"is_moderation_enabled"`
	IsPro                 bool         `db:"is_pro"`
	HasPaddleSubscription bool         `db:"has_paddle_subscription"`
	ScheduledDeletionAt   dbx.NullTime `db:"scheduled_deletion_at"`
}

func (*Tenant) ToModel

func (t *Tenant) ToModel() *entity.Tenant

type User

type User struct {
	ID            sql.NullInt64  `db:"id"`
	Name          sql.NullString `db:"name"`
	Email         sql.NullString `db:"email"`
	Tenant        *Tenant        `db:"tenant"`
	Role          sql.NullInt64  `db:"role"`
	Status        sql.NullInt64  `db:"status"`
	AvatarType    sql.NullInt64  `db:"avatar_type"`
	AvatarBlobKey sql.NullString `db:"avatar_bkey"`
	IsTrusted     sql.NullBool   `db:"is_trusted"`
	SecurityStamp sql.NullString `db:"security_stamp"`
	Providers     []*UserProvider
}

User is the database mapping for users table

func (*User) ToModel

func (u *User) ToModel(ctx context.Context) *entity.User

type UserProvider

type UserProvider struct {
	Name sql.NullString `db:"provider"`
	UID  sql.NullString `db:"provider_uid"`
}

type UserSetting

type UserSetting struct {
	Key   string `db:"key"`
	Value string `db:"value"`
}

type Vote

type Vote struct {
	User *struct {
		ID            int    `db:"id"`
		Name          string `db:"name"`
		Email         string `db:"email"`
		AvatarType    int64  `db:"avatar_type"`
		AvatarBlobKey string `db:"avatar_bkey"`
	} `db:"user"`
	CreatedAt time.Time `db:"created_at"`
}

func (*Vote) ToModel

func (v *Vote) ToModel(ctx context.Context) *entity.Vote

Jump to

Keyboard shortcuts

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