pg

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithTx

func WithTx(ctx context.Context, tx *sql.Tx) context.Context

Types

type AdminRepository

type AdminRepository struct {
	Repository[model.Admin, int64]
}

func NewAdminRepository

func NewAdminRepository(db *sql.DB) *AdminRepository

func (*AdminRepository) FindByEmail

func (r *AdminRepository) FindByEmail(ctx context.Context, email string) (model.Admin, error)

type ConfigurationRepository

type ConfigurationRepository struct {
	// contains filtered or unexported fields
}

func NewConfigurationRepository

func NewConfigurationRepository(db *sql.DB) *ConfigurationRepository

func (*ConfigurationRepository) Load

func (*ConfigurationRepository) Save

type MenuRepository struct {
	Repository[model.Menu, int64]
}

func NewMenuRepository

func NewMenuRepository(db *sql.DB) *MenuRepository
func (r *MenuRepository) Create(ctx context.Context, m *model.Menu) error
func (r *MenuRepository) FindByHandle(ctx context.Context, handle string) (model.Menu, error)
func (r *MenuRepository) Update(ctx context.Context, m *model.Menu) error

type Metas

type Metas []model.Meta

func NewMetas

func NewMetas(metas []model.Meta) Metas

func (*Metas) Scan

func (m *Metas) Scan(src any) error

func (*Metas) Value

func (m *Metas) Value() (driver.Value, error)

type NodeRepository

type NodeRepository struct {
	Repository[model.Node, int64]
	// contains filtered or unexported fields
}

func NewNodeRepository

func NewNodeRepository(db *sql.DB) *NodeRepository

func (*NodeRepository) Create

func (r *NodeRepository) Create(ctx context.Context, m *model.Node) error

func (*NodeRepository) Delete

func (r *NodeRepository) Delete(ctx context.Context, ids ...int64) error

func (*NodeRepository) FindWithChildren

func (r *NodeRepository) FindWithChildren(ctx context.Context, id int64) ([]model.Node, error)

func (*NodeRepository) Update

func (r *NodeRepository) Update(ctx context.Context, m *model.Node) error

type PageRepository

type PageRepository struct {
	Repository[model.Page, int64]
}

func NewPageRepository

func NewPageRepository(db *sql.DB) *PageRepository

func (*PageRepository) Create

func (r *PageRepository) Create(ctx context.Context, m *model.Page) error

func (*PageRepository) FindByAlias

func (r *PageRepository) FindByAlias(ctx context.Context, siteID int64, alias string, now time.Time) (model.Page, error)

func (*PageRepository) FindByParentID

func (r *PageRepository) FindByParentID(ctx context.Context, parentID int64, now time.Time) ([]model.Page, error)

func (*PageRepository) FindByPattern

func (r *PageRepository) FindByPattern(ctx context.Context, siteID int64, pattern string, now time.Time) (model.Page, error)

func (*PageRepository) FindByURL

func (r *PageRepository) FindByURL(ctx context.Context, siteID int64, url string, now time.Time) (model.Page, error)

func (*PageRepository) Update

func (r *PageRepository) Update(ctx context.Context, m *model.Page) error

type Repository

type Repository[T interface{ GetID() ID }, ID any] struct {
	DB            *sql.DB
	Table         string
	SelectColumns []string
	RowScan       func(interface{ Scan(dest ...any) error }, *T) error
	InsertValues  func(*T) map[string]any
	UpdateValues  func(*T) map[string]any
	OnError       func(error) error
}

func (Repository[T, ID]) Create

func (r Repository[T, ID]) Create(ctx context.Context, m *T) error

func (Repository[T, ID]) Delete

func (r Repository[T, ID]) Delete(ctx context.Context, ids ...ID) error

func (Repository[T, ID]) Find

func (r Repository[T, ID]) Find(ctx context.Context, criteria *cr.Criteria) ([]T, error)

func (Repository[T, ID]) FindAndCount

func (r Repository[T, ID]) FindAndCount(ctx context.Context, criteria *cr.Criteria) ([]T, int, error)

func (Repository[T, ID]) FindBy

func (r Repository[T, ID]) FindBy(ctx context.Context, column string, value any) (m T, err error)

func (Repository[T, ID]) FindByID

func (r Repository[T, ID]) FindByID(ctx context.Context, id ID) (T, error)

func (Repository[T, ID]) Update

func (r Repository[T, ID]) Update(ctx context.Context, m *T) error

type Roles

type Roles []string

func NewRoles

func NewRoles(roles []string) Roles

func (*Roles) Scan

func (r *Roles) Scan(src any) error

func (*Roles) Value

func (r *Roles) Value() (driver.Value, error)

type SessionRepository added in v0.0.9

type SessionRepository struct {
	// contains filtered or unexported fields
}

func NewSessionRepository added in v0.0.9

func NewSessionRepository(db *sql.DB, cleanupInterval time.Duration) *SessionRepository

NewSessionRepository returns a new PostgresStore instance. The cleanupInterval parameter controls how frequently expired session data is removed by the background cleanup goroutine. Setting it to 0 prevents the cleanup goroutine from running (i.e. expired sessions will not be removed).

func (*SessionRepository) All added in v0.0.9

func (p *SessionRepository) All() (map[string][]byte, error)

All returns a map containing the token and data for all active (i.e. not expired) sessions in the PostgresStore instance.

func (*SessionRepository) Commit added in v0.0.9

func (p *SessionRepository) Commit(token string, b []byte, expiry time.Time) error

Commit adds a session token and data to the PostgresStore instance with the given expiry time. If the session token already exists, then the data and expiry time are updated.

func (*SessionRepository) Delete added in v0.0.9

func (p *SessionRepository) Delete(token string) error

Delete removes a session token and corresponding data from the PostgresStore instance.

func (*SessionRepository) Find added in v0.0.9

func (p *SessionRepository) Find(token string) (b []byte, exists bool, err error)

Find returns the data for a given session token from the PostgresStore instance. If the session token is not found or is expired, the returned exists flag will be set to false.

func (*SessionRepository) StopCleanup added in v0.0.9

func (p *SessionRepository) StopCleanup()

StopCleanup terminates the background cleanup goroutine for the PostgresStore instance. It's rare to terminate this; generally PostgresStore instances and their cleanup goroutines are intended to be long-lived and run for the lifetime of your application.

There may be occasions though when your use of the PostgresStore is transient. An example is creating a new PostgresStore instance in a test function. In this scenario, the cleanup goroutine (which will run forever) will prevent the PostgresStore object from being garbage collected even after the test function has finished. You can prevent this by manually calling StopCleanup.

type SiteRepository

type SiteRepository struct {
	Repository[model.Site, int64]
}

func NewSiteRepository

func NewSiteRepository(db *sql.DB) *SiteRepository

func (*SiteRepository) FindByHosts

func (r *SiteRepository) FindByHosts(ctx context.Context, hosts []string, now time.Time) ([]model.Site, error)

type StrMap

type StrMap map[string]string

func NewStrMap

func NewStrMap(strMap map[string]string) StrMap

func (*StrMap) Scan

func (m *StrMap) Scan(src any) error

func (*StrMap) Value

func (m *StrMap) Value() (driver.Value, error)

type TemplateRepository

type TemplateRepository struct {
	Repository[model.Template, int64]
}

func NewTemplateRepository

func NewTemplateRepository(db *sql.DB) *TemplateRepository

func (*TemplateRepository) FindByName

func (r *TemplateRepository) FindByName(ctx context.Context, name string) (model.Template, error)

Jump to

Keyboard shortcuts

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