sql

package
v0.0.0-...-f6da3f2 Latest Latest
Warning

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

Go to latest
Published: May 13, 2023 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package sql implements the SQL storage layer.

Index

Constants

View Source
const (
	ErrRemoteBlog    = errors.Sentinel("blog is remote")
	ErrUsernameTaken = errors.Sentinel("username or blog name is taken")

	ErrNotFound = errors.Sentinel("not found")
)
View Source
const PasswordCost = 15

Variables

This section is empty.

Functions

func Get

func Get[T any](ctx context.Context, querier Querier, query *sqlf.Query) (T, error)

func Migrate

func Migrate(dsn string) error

func Select

func Select[T any](ctx context.Context, querier Querier, query *sqlf.Query) ([]T, error)

Types

type AccountStore

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

AccountStore is the interface to accounts in the database.

func NewAccountStore

func NewAccountStore(q Querier) *AccountStore

NewAccountStore creates a new AccountStore instance.

func (*AccountStore) ByID

func (s *AccountStore) ByID(ctx context.Context, id ulid.ULID) (a database.Account, err error)

ByID gets an account by its ID.

func (*AccountStore) ByUsername

func (s *AccountStore) ByUsername(ctx context.Context, username string) (a database.Account, err error)

ByUsername gets an account by its username.

func (*AccountStore) Create

func (s *AccountStore) Create(ctx context.Context, username, email string, password []byte) (a database.Account, err error)

type Base

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

Base is the base database pool used by storage layers.

func NewBase

func NewBase(ctx context.Context, connString string) (*Base, error)

NewBase creates a new instance of Base with the specified connection string.

func (*Base) Acquire

func (base *Base) Acquire(ctx context.Context) (ReleaseableQuerier, error)

Acquire acquires a connection from the database pool. It is the caller's responsibility to call the Release method.

func (*Base) BeginTx

func (base *Base) BeginTx(ctx context.Context) (Tx, error)

func (*Base) PoolQuerier

func (base *Base) PoolQuerier() Querier

type BlogStore

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

BlogStore is the interface to blogs in the database.

func NewBlogStore

func NewBlogStore(q Querier) *BlogStore

NewBlogStore creates a new BlogStore instance.

func (*BlogStore) ByID

func (s *BlogStore) ByID(ctx context.Context, id ulid.ULID) (b database.Blog, err error)

ByID gets a blog by its ID.

func (*BlogStore) ByName

func (s *BlogStore) ByName(ctx context.Context, name, domain string) (b database.Blog, err error)

ByName gets a blog by name. If domain is empty, it gets a local blog.

func (*BlogStore) CreateLocal

func (s *BlogStore) CreateLocal(ctx context.Context, accountID ulid.ULID, name string) (b database.Blog, err error)

CreateLocal creates a local blog, which is required to have an account attached to it.

func (*BlogStore) LocalCount

func (s *BlogStore) LocalCount(ctx context.Context) (count int64, err error)

type PostStore

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

PostStore is the interface to posts in the database.

func NewPostStore

func NewPostStore(q Querier) *PostStore

NewPostStore creates a new PostStore instance.

func (*PostStore) ByID

func (s *PostStore) ByID(ctx context.Context, id ulid.ULID) (p database.Post, err error)

ByID gets a post by its ID.

func (*PostStore) Create

func (s *PostStore) Create(ctx context.Context, blog database.Blog, content string) (p database.Post, err error)

func (*PostStore) LocalCount

func (s *PostStore) LocalCount(ctx context.Context) (count int64, err error)

type Querier

type Querier interface {
	Query(ctx context.Context, query string, args ...interface{}) (pgx.Rows, error)
	QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
	Exec(ctx context.Context, sql string, arguments ...any) (pgconn.CommandTag, error)
}

type ReleaseableQuerier

type ReleaseableQuerier interface {
	Querier

	Release()
}

type Tx

type Tx interface {
	Querier

	Commit(ctx context.Context) error
	Rollback(ctx context.Context) error
}

Jump to

Keyboard shortcuts

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