postgres

package
v0.0.0-...-8ba40cc Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CamelToSnakeASCII

func CamelToSnakeASCII(s string) string

CamelToSnakeASCII converts camel case strings to snake case. It's used as a mapper for sqlx. It's a simplified version of the same name function found in https://github.com/scylladb/go-reflectx.

Types

type PostgresArticle

type PostgresArticle struct {
	Id          int
	Slug        string
	Title       string
	Description sql.NullString
	Body        sql.NullString
	Created     time.Time
	Updated     time.Time
	AuthorId    int
	AuthorName  string
	AuthorBio   string
	AuthorImage sql.NullString
	Following   bool
}

PostgresArticle is the same as app.Article but specific for articles list queries. It expands Author type to its fields and uses sql.Null* types. All of this is needed to allow scanning query result.

type PostgresProfile

type PostgresProfile struct {
	Id        int
	Name      string
	Bio       sql.NullString
	Image     sql.NullString
	Following bool
}

PostgresProfile is the same as app.Profile but suitable for StructScan method because it has sql.Null* types.

type Store

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

func NewStore

func NewStore(DSN string) (*Store, error)

func (*Store) AddUser

func (s *Store) AddUser(user *app.User) error

AddUser adds new user to the Postgres user store and returns it

func (Store) CreateArticle

func (s Store) CreateArticle(a *app.Article) error

func (Store) DeleteArticle

func (s Store) DeleteArticle(id int) error

func (Store) FollowProfile

func (s Store) FollowProfile(follower, followee *app.Profile) error

func (Store) GetArticle

func (s Store) GetArticle(slug string) (*app.Article, error)

Get returns a single article by its slug

func (*Store) GetProfile

func (s *Store) GetProfile(username string, follower *app.Profile) (*app.Profile, error)

func (*Store) GetUser

func (s *Store) GetUser(email string) (*app.User, error)

GetUser returns user by email from Postgres store

func (*Store) GetUserById

func (s *Store) GetUserById(id int) (*app.User, error)

func (Store) ListArticles

func (s Store) ListArticles(f *app.ArticleListFilter) ([]*app.Article, error)

func (Store) UnfollowProfile

func (s Store) UnfollowProfile(follower, followee *app.Profile) error

func (Store) UpdateArticle

func (s Store) UpdateArticle(a *app.Article) error

func (*Store) UpdateUser

func (s *Store) UpdateUser(user *app.User) error

UpdateUser modifies user by email and return updated user object

Jump to

Keyboard shortcuts

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