db

package
v0.0.0-...-657596a Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2020 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const RootCategory = "00000000-0000-0000-0000-000000000000"

The UUID of the root of the category tree.

View Source
const (
	UnassignedUUID = "00000000-0000-0000-0000-000000000000"
)

The UUID of the root of the 'unassigned' user.

Variables

View Source
var (
	CategoryErrorParentNotFound   = status.Error(codes.NotFound, "parent not found")
	CategoryErrorDuplicateName    = status.Error(codes.AlreadyExists, "duplicate category name")
	CategoryErrorNotFound         = status.Error(codes.NotFound, "category not found")
	CategoryErrorCannotDeleteRoot = status.Error(codes.InvalidArgument, "cannot delete root category")
	CategoryErrorNotEmpty         = status.Error(codes.FailedPrecondition, "category has dependent data")
)
View Source
var (
	UserErrorNoSuchUsername    = status.Error(codes.NotFound, "no such username")
	UserErrorNoSuchUser        = status.Error(codes.NotFound, "no such user")
	UserErrorDuplicateUsername = status.Error(codes.AlreadyExists, "duplicate username")
)
View Source
var (
	IssueErrorNotFound = status.Error(codes.NotFound, "issue not found")
)

Functions

This section is empty.

Types

type Category

type Category struct {
	UUID       string `db:"id"`
	ParentUUID string `db:"parent_id"`

	Name        string `db:"name"`
	Description string `db:"description"`
}

An issue category.

type CategoryError

type CategoryError error

type CategoryGetter

type CategoryGetter interface {
	// Get retrieves a database category by UUID.
	Get(uuid string) (*Category, error)
	// GetTree returns a (sub)tree of categories starting at a given category
	// UUID.
	// At most `levels`  category tree levels. Level 0 means only the requested
	// node, level 1 the node and its children, level 2 the node, it's children
	// and it's grandchildren, etc.
	GetTree(rootUUID string, levels uint) (*CategoryNode, error)
	// New creates a new database category from an in-memroy category.  UUID
	// must be unset. ParentUUID should either point to an existing category
	// (if the category is a chuild category) or be blank (if the category
	// should be to-level).
	New(new *Category) (*Category, error)
	// Update saves a given category. All fields can be updated apart from the
	// current UUID.
	Update(cat *Category) error
	// Delete removes a category. It must not contain any child categories or
	// issues.
	Delete(uuid string) error
}

type CategoryNode

type CategoryNode struct {
	*Category

	Children []*CategoryNode
}

A category that's part of a retrieved category tree.

type Database

type Database interface {
	Migrate() error

	// Begin returns a database Session that must be commited, but can also be rolled back
	Begin(ctx context.Context) Session
	// Do returns a database Session that will automatically commit on every object access
	Do(ctx context.Context) Session
}

func Connect

func Connect(ctx context.Context, dsn string) (Database, error)

type ErrorConverter

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

func NewErrorConverter

func NewErrorConverter() *ErrorConverter

func (*ErrorConverter) Convert

func (c *ErrorConverter) Convert(err error) error

func (*ErrorConverter) WithForeignKeyViolation

func (c *ErrorConverter) WithForeignKeyViolation(err error) *ErrorConverter

func (*ErrorConverter) WithSyntaxError

func (c *ErrorConverter) WithSyntaxError(err error) *ErrorConverter

func (*ErrorConverter) WithUniqueConstraintViolation

func (c *ErrorConverter) WithUniqueConstraintViolation(err error) *ErrorConverter

type Issue

type Issue struct {
	// Constant columns
	ID       int64  `db:"id"`
	AuthorID string `db:"author_id"`
	Created  int64  `db:"created"`

	// Bumped when a new update is added
	LastUpdated int64 `db:"last_updated"`

	// Denormalized data
	Title      string `db:"title"`
	AssigneeID string `db:"assignee_id"`
	Type       int64  `db:"type"`
	Priority   int64  `db:"priority"`
	Status     int64  `db:"status"`
}

func (*Issue) Proto

func (i *Issue) Proto() *cpb.Issue

func (*Issue) ProtoWithUsers

func (i *Issue) ProtoWithUsers(s Session) (*cpb.Issue, error)

ProtoWithUsers returns a proto representation of the Issue database object like .Proto, but with full user data. If an error is returned, the .Proto result is returned (without full user data) alongside the error.

type IssueError

type IssueError error

type IssueFilter

type IssueFilter struct {
	// The filter passes when all the set fields match an issue.
	Author   string
	Assignee string
	Status   int64
}

type IssueFilterOpts

type IssueFilterOpts struct {
	Start int64
	Count int64
}

type IssueGetHistoryOpts

type IssueGetHistoryOpts struct {
	Start int64
	Count int64
}

type IssueGetter

type IssueGetter interface {
	Get(id int64) (*Issue, error)
	Filter(filter IssueFilter, order IssueOrderBy, opts *IssueFilterOpts) ([]*Issue, error)
	GetHistory(id int64, opts *IssueGetHistoryOpts) ([]*IssueUpdate, error)
	New(new *Issue) (*Issue, error)
	Update(update *IssueUpdate) error
}

type IssueOrder

type IssueOrder int
const (
	IssueOrderCreated IssueOrder = iota
	IssueOrderUpdated
)

type IssueOrderBy

type IssueOrderBy struct {
	Ascending bool
	By        IssueOrder
}

type IssueUpdate

type IssueUpdate struct {
	IssueID  int64          `db:"issue_id"`
	UpdateID int64          `db:"id"`
	Created  int64          `db:"created"`
	AuthorID string         `db:"author_id"`
	Comment  sql.NullString `db:"comment"`

	Title      sql.NullString `db:"title"`
	AssigneeID sql.NullString `db:"assignee_id"`
	Type       sql.NullInt64  `db:"type"`
	Priority   sql.NullInt64  `db:"priority"`
	Status     sql.NullInt64  `db:"status"`
}

func (*IssueUpdate) Proto

func (u *IssueUpdate) Proto() *cpb.Update

func (*IssueUpdate) ProtoWithUsers

func (u *IssueUpdate) ProtoWithUsers(s Session) (*cpb.Update, error)

type Session

type Session interface {
	Category() CategoryGetter
	Issue() IssueGetter
	User() UserGetter
	Commit() error
	Rollback() error
}

type User

type User struct {
	ID          string `db:"id"`
	Username    string `db:"username"`
	Preferences []byte `db:"preferences"`

	Email       sql.NullString `db:"email"`
	DisplayName sql.NullString `db:"display_name"`
}

func (*User) Proto

func (u *User) Proto() *cpb.User

type UserError

type UserError error

type UserGetter

type UserGetter interface {
	New(new *User) (*User, error)
	// ResolveUsername resolves a username to its UUID.
	ResolveUsername(username string) (uuid string, err error)
	Get(uuid string) (*User, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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