postgres

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommentRepository

type CommentRepository struct {
	DB *sqlx.DB
}

CommentRepository implements taskforge.CommentService for a Postgres database

func (*CommentRepository) Create

func (cr *CommentRepository) Create(user taskforge.User, comment taskforge.Comment) (taskforge.Comment, error)

Create validates and creates the given comment, the comment.Author is ignored and the caller user is always set as the Author.

func (*CommentRepository) Delete

func (cr *CommentRepository) Delete(user taskforge.User, id uuid.UUID) error

Delete deletes the comment corresponding to id if the calling user is the author of it.

func (*CommentRepository) Get

Get retrieves a comment from the database by id if the calling user is the Author of the comment.

func (*CommentRepository) List

func (cr *CommentRepository) List(user taskforge.User, object uuid.UUID) ([]taskforge.Comment, error)

List retrieves all comment from the database by id if the calling user is the Author of the comment.

func (*CommentRepository) Update

func (cr *CommentRepository) Update(user taskforge.User, updated taskforge.Comment) (taskforge.Comment, error)

Update will update the body of updated in the database if the calling user is the author of it

type Compiler

type Compiler struct {
	Query  string
	Values []interface{}
}

Compiler compiles TQL ASTs into a Postgres WHERE clause with corresponding value array

func (*Compiler) Compile

func (c *Compiler) Compile(ast tql.AST) error

Compile populats this Compiler's fields with the WHERE clause and Values array for the given AST

type ContextRepository

type ContextRepository struct {
	DB *sqlx.DB
}

ContextRepository implements taskforge.ContextService for a Postgres database

func (*ContextRepository) Create

func (cr *ContextRepository) Create(user taskforge.User, context taskforge.Context) (taskforge.Context, error)

Create will validate and populate default fields on context then persist it to the Postgres database. Note: the calling user is always set as the Owner of context and the passed value of Owner for context is ignored.

func (*ContextRepository) Default

func (cr *ContextRepository) Default() (taskforge.Context, error)

Default returns the default context for all users, it is named 'default'

func (*ContextRepository) Delete

func (cr *ContextRepository) Delete(user taskforge.User, id uuid.UUID) error

Delete deletes the Context with the given id if it's owned by the calling user

func (*ContextRepository) Get

Get retrieves a Context with the given id if it's owned by the calling user

func (*ContextRepository) GetByName

func (cr *ContextRepository) GetByName(user taskforge.User, name string) (taskforge.Context, error)

GetByName retrieves a Context with the given name if it's owned by the calling user

func (*ContextRepository) List

func (cr *ContextRepository) List(user taskforge.User) ([]taskforge.Context, error)

List returns all context owned by the calling user

func (*ContextRepository) Update

func (cr *ContextRepository) Update(user taskforge.User, updated taskforge.Context) (taskforge.Context, error)

Update updates the Context updated in the database if it's owned by the calling user

type Repository

type Repository struct {
	DB *sqlx.DB

	Migrator migrations.SQLMigrator
	// contains filtered or unexported fields
}

Repository managages database connections and migrations for Postgres, it implements methods returning the appropriate model services of the same name for the models in Taskforge.

func New

func New(connection string) (Repository, error)

New creates a Repository and databse connection using the given connection string

func (Repository) AssignRefreshToken added in v0.2.0

func (pr Repository) AssignRefreshToken(user taskforge.User, identifier uuid.UUID) error

AssignRefreshToken will assign the refresh identifier to user

func (Repository) Comments

func (pr Repository) Comments() taskforge.CommentService

Comments returns a taskforge.CommentService that operates on this database

func (Repository) Contexts

func (pr Repository) Contexts() taskforge.ContextService

Contexts returns a taskforge.ContextService that operates on this database

func (Repository) InvalidateRefreshToken added in v0.2.0

func (pr Repository) InvalidateRefreshToken(identifier uuid.UUID) error

InvalidateRefreshToken will find the token for identifier and make it no longer valid

func (*Repository) Migrate

func (pr *Repository) Migrate() error

Migrate runs all of the SQL migrations on this postgres database

func (Repository) Sources

func (pr Repository) Sources() taskforge.SourceService

Sources returns a taskforge.SourceService that operates on this database

func (Repository) Tasks

func (pr Repository) Tasks() taskforge.TaskService

Tasks returns a taskforge.TaskService that operates on this database

func (Repository) Users

func (pr Repository) Users() taskforge.UserService

Users returns a taskforge.UserService that operates on this database

func (Repository) ValidateRefreshToken added in v0.2.0

func (pr Repository) ValidateRefreshToken(userID uuid.UUID, identifier uuid.UUID) (taskforge.User, error)

ValidateRefreshToken will find the token with the identifier, if it belongs to the given userID and has not expired it will return the attached user instance, otherwise an error will be returned indicating what kind of failure occurred.

type SourceRepository

type SourceRepository struct {
	DB *sqlx.DB
}

SourceRepository implements taskforge.SourceService for a Postgres database

func (*SourceRepository) Create

func (sr *SourceRepository) Create(user taskforge.User, source taskforge.Source) (taskforge.Source, error)

Create saves given source to the Postgres database

func (*SourceRepository) Default

func (sr *SourceRepository) Default() (taskforge.Source, error)

Default returns the Default source corresponding to Taskforge

func (*SourceRepository) Delete

func (sr *SourceRepository) Delete(user taskforge.User, id uuid.UUID) error

Delete deletes the source with the given id

func (*SourceRepository) Get

Get returns the Source with the given id

func (*SourceRepository) List

func (sr *SourceRepository) List(user taskforge.User) ([]taskforge.Source, error)

List returns all sources in the Postgres database

func (*SourceRepository) Update

func (sr *SourceRepository) Update(user taskforge.User, updated taskforge.Source) (taskforge.Source, error)

Update updates the matching Source in the database

type TaskRepository

type TaskRepository struct {
	DB       *sqlx.DB
	Sources  taskforge.SourceService
	Contexts taskforge.ContextService
}

TaskRepository implements taskforge.TaskService for a Postgres database

func (*TaskRepository) Complete

func (t *TaskRepository) Complete(user taskforge.User, id uuid.UUID) error

Complete completes the task with the given id if it's owned by user

func (*TaskRepository) Create

func (t *TaskRepository) Create(user taskforge.User, task taskforge.Task) (taskforge.Task, error)

Create will validate and populate default fields on task then persist it to the Postgres database. Note: the calling user is always set as the Owner of task and the passed value of Owner for task is ignored.

func (*TaskRepository) Current

func (t *TaskRepository) Current(user taskforge.User) (taskforge.Task, error)

Current returns the current task for the given user

func (*TaskRepository) Delete

func (t *TaskRepository) Delete(user taskforge.User, id uuid.UUID) error

Delete deletes a task with the given id if it's owned by user

func (*TaskRepository) Get

func (t *TaskRepository) Get(user taskforge.User, id uuid.UUID) (taskforge.Task, error)

Get retrieves a task by the given id if it's owned by user

func (*TaskRepository) List

func (t *TaskRepository) List(user taskforge.User) ([]taskforge.Task, error)

List lists all tasks owned by user

func (*TaskRepository) Search

func (t *TaskRepository) Search(user taskforge.User, query string) ([]taskforge.Task, error)

Search will return all tasks owned by user which match the given query, the query is parsed and compiled according to the TQL spec

func (*TaskRepository) Update

func (t *TaskRepository) Update(user taskforge.User, updated taskforge.Task) (taskforge.Task, error)

Update updates the task with the same id as updated if it's owned by user

type UserRepository

type UserRepository struct {
	DB *sqlx.DB
}

UserRepository implements taskforge.UserService for a Postgres database

func (UserRepository) AssignRefreshToken added in v0.2.0

func (ur UserRepository) AssignRefreshToken(user taskforge.User, identifier uuid.UUID) error

AssignRefreshToken will assign the refresh identifier to user

func (UserRepository) Create

func (ur UserRepository) Create(user taskforge.User) (taskforge.User, error)

Create validates, and populates default data in user then persists it to the Postgres database.

func (UserRepository) Delete

func (ur UserRepository) Delete(user taskforge.User, id uuid.UUID) error

Delete deletes the user corresponding to id only if the ID matches the calling user

func (UserRepository) Get

func (ur UserRepository) Get(user taskforge.User, id uuid.UUID) (taskforge.User, error)

Get retreives a User by id from the postgres database

func (UserRepository) InvalidateRefreshToken added in v0.2.0

func (ur UserRepository) InvalidateRefreshToken(identifier uuid.UUID) error

InvalidateRefreshToken will find the token for identifier and make it no longer valid

func (UserRepository) List

func (ur UserRepository) List(user taskforge.User) ([]taskforge.User, error)

List returns a list with a single element: the calling user

func (UserRepository) Login

func (ur UserRepository) Login(email, password string) (taskforge.User, error)

Login retrieves a user and validates that password matches the bcrypted password in the database

func (UserRepository) Update

func (ur UserRepository) Update(user taskforge.User, updated taskforge.User) (taskforge.User, error)

Update updates a user if the updated user is the calling user

func (UserRepository) ValidateRefreshToken added in v0.2.0

func (ur UserRepository) ValidateRefreshToken(userID uuid.UUID, identifier uuid.UUID) (taskforge.User, error)

ValidateRefreshToken will find the token with the identifier, if it belongs to the given userID and has not expired it will return the attached user instance, otherwise an error will be returned indicating what kind of failure occurred.

Jump to

Keyboard shortcuts

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