database

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyMarked = errors.New("database: chapter already marked")
View Source
var ErrItemAlreadyExists = errors.New("database: item already exists")
View Source
var ErrItemNotFound = errors.New("database: item not found")

Functions

func ApiTokenQuery added in v0.10.0

func ApiTokenQuery() *goqu.SelectDataset

func ChapterQuery added in v0.10.0

func ChapterQuery() *goqu.SelectDataset

func SerieQuery added in v0.10.0

func SerieQuery() *goqu.SelectDataset

func UserQuery added in v0.10.0

func UserQuery() *goqu.SelectDataset

func UserSettingsQuery added in v0.10.0

func UserSettingsQuery() *goqu.SelectDataset

Types

type ApiToken added in v0.10.0

type ApiToken struct {
	Id     string `db:"id"`
	UserId string `db:"user_id"`

	Name string `db:"name"`

	Created int64 `db:"created"`
	Updated int64 `db:"updated"`
}

type Bookmark

type Bookmark struct {
	UserId    string
	SerieId   string
	ChapterId string
}

type Chapter

type Chapter struct {
	Id   string `db:"id"`
	Name string `db:"name"`

	SerieId string `db:"serie_id"`

	Pages    string         `db:"pages"`
	Number   int64          `db:"number"`
	CoverArt sql.NullString `db:"cover_art"`

	Created int64 `db:"created"`
	Updated int64 `db:"updated"`
}

type ChapterChanges added in v0.10.0

type ChapterChanges struct {
	Name types.Change[string]

	SerieId types.Change[string]

	Pages    types.Change[string]
	Number   types.Change[int64]
	CoverArt types.Change[sql.NullString]

	Created types.Change[int64]
}

type Config added in v0.3.0

type Config struct {
	OwnerId string
}

type Connection added in v0.3.0

type Connection interface {
	Query(query string, args ...any) (*sql.Rows, error)
	QueryRow(query string, args ...any) *sql.Row
	Exec(query string, args ...any) (sql.Result, error)
}

type CreateApiTokenParams added in v0.10.0

type CreateApiTokenParams struct {
	Id     string
	UserId string
	Name   string

	Created int64
	Updated int64
}

type CreateChapterParams added in v0.10.0

type CreateChapterParams struct {
	Id   string
	Name string

	SerieId string

	Pages    string
	Number   int64
	CoverArt sql.NullString

	Created int64
	Updated int64
}

type CreateSerieParams added in v0.10.0

type CreateSerieParams struct {
	Id   string
	Name string

	CoverArt sql.NullString

	MalId     sql.NullString
	AnilistId sql.NullString

	Created int64
	Updated int64
}

type CreateUserParams added in v0.10.0

type CreateUserParams struct {
	Id       string
	Username string
	Password string
	Role     string

	Created int64
	Updated int64
}

type Database

type Database struct {
	NewRawConn *sqlx.DB
	RawConn    *sql.DB
	Conn       Connection
}

func New

func New(conn *sql.DB) *Database

func Open

func Open(workDir types.WorkDir) (*Database, error)

func (*Database) Begin added in v0.3.0

func (db *Database) Begin() (*Database, *sqlx.Tx, error)

func (*Database) CreateApiToken added in v0.10.0

func (db *Database) CreateApiToken(ctx context.Context, params CreateApiTokenParams) (ApiToken, error)

func (*Database) CreateBookmark

func (db *Database) CreateBookmark(ctx context.Context, userId, serieId, chapterId string) error

func (*Database) CreateChapter

func (db *Database) CreateChapter(ctx context.Context, params CreateChapterParams) (Chapter, error)

func (*Database) CreateConfig added in v0.3.0

func (db *Database) CreateConfig(ctx context.Context, ownerId string) (Config, error)

func (*Database) CreateSerie

func (db *Database) CreateSerie(ctx context.Context, params CreateSerieParams) (Serie, error)

func (*Database) CreateUser

func (db *Database) CreateUser(ctx context.Context, params CreateUserParams) (User, error)

func (*Database) DeleteSerie added in v0.10.0

func (db *Database) DeleteSerie(ctx context.Context, id string) error

func (*Database) Exec

func (db *Database) Exec(ctx context.Context, s ToSQL) (sql.Result, error)

func (*Database) Get added in v0.10.0

func (db *Database) Get(dest any, s ToSQL) error

func (*Database) GetAllApiTokensForUser added in v0.10.0

func (db *Database) GetAllApiTokensForUser(ctx context.Context, userId string) ([]ApiToken, error)

func (*Database) GetAllChapters

func (db *Database) GetAllChapters(ctx context.Context) ([]Chapter, error)

func (*Database) GetAllMarkedChapters

func (db *Database) GetAllMarkedChapters(ctx context.Context, userId, serieId string) ([]string, error)

func (*Database) GetAllSeries

func (db *Database) GetAllSeries(ctx context.Context, nameFilter string) ([]Serie, error)

TODO(patrik): nameFilter is temporary

func (*Database) GetAllUsers added in v0.10.0

func (db *Database) GetAllUsers(ctx context.Context) ([]User, error)

func (*Database) GetApiTokenById added in v0.10.0

func (db *Database) GetApiTokenById(ctx context.Context, id string) (ApiToken, error)

func (*Database) GetBookmark

func (db *Database) GetBookmark(ctx context.Context, userId, serieId string) (Bookmark, error)

func (*Database) GetChapterById added in v0.10.0

func (db *Database) GetChapterById(ctx context.Context, id string) (Chapter, error)

func (*Database) GetConfig added in v0.3.0

func (db *Database) GetConfig(ctx context.Context) (*Config, error)

func (*Database) GetSerieById

func (db *Database) GetSerieById(ctx context.Context, id string) (Serie, error)

func (*Database) GetSerieChapters added in v0.10.0

func (db *Database) GetSerieChapters(ctx context.Context, serieId string) ([]Chapter, error)

func (*Database) GetUserById

func (db *Database) GetUserById(ctx context.Context, id string) (User, error)

func (*Database) GetUserByUsername

func (db *Database) GetUserByUsername(ctx context.Context, username string) (User, error)

func (*Database) GetUserSettingsById added in v0.10.0

func (db *Database) GetUserSettingsById(ctx context.Context, id string) (UserSettings, error)

func (*Database) HasBookmark

func (db *Database) HasBookmark(ctx context.Context, userId, serieId string) (bool, error)

func (*Database) IsChapterMarked

func (db *Database) IsChapterMarked(ctx context.Context, userId, chapterId string) (bool, error)

func (*Database) MarkChapter

func (db *Database) MarkChapter(ctx context.Context, userId, chapterId string) error

TODO(patrik): Fix

func (*Database) Query

func (db *Database) Query(ctx context.Context, s ToSQL) (*sql.Rows, error)

func (*Database) QueryRow

func (db *Database) QueryRow(ctx context.Context, s ToSQL) (*sql.Row, error)

func (*Database) RecalculateNumberForSerie added in v0.10.0

func (db *Database) RecalculateNumberForSerie(ctx context.Context, serieId string) error

func (*Database) RemoveApiToken added in v0.10.0

func (db *Database) RemoveApiToken(ctx context.Context, id string) error

func (*Database) RemoveChapter added in v0.10.0

func (db *Database) RemoveChapter(ctx context.Context, id string) error

func (*Database) RunMigrateDown added in v0.10.0

func (db *Database) RunMigrateDown() error

func (*Database) RunMigrateUp added in v0.9.0

func (db *Database) RunMigrateUp() error

func (*Database) Select added in v0.10.0

func (db *Database) Select(dest any, s ToSQL) error

func (*Database) UnmarkChapter

func (db *Database) UnmarkChapter(ctx context.Context, userId, chapterId string) error

func (*Database) UpdateBookmark

func (db *Database) UpdateBookmark(ctx context.Context, userId, serieId, chapterId string) error

func (*Database) UpdateChapter added in v0.10.0

func (db *Database) UpdateChapter(ctx context.Context, id string, changes ChapterChanges) error

func (*Database) UpdateSerie added in v0.10.0

func (db *Database) UpdateSerie(ctx context.Context, id string, changes SerieChanges) error

func (*Database) UpdateUser added in v0.10.0

func (db *Database) UpdateUser(ctx context.Context, id string, changes UserChanges) error

func (*Database) UpdateUserSettings added in v0.10.0

func (db *Database) UpdateUserSettings(ctx context.Context, settings UserSettings) error

type Serie

type Serie struct {
	Id   string `db:"id"`
	Name string `db:"name"`

	CoverArt sql.NullString `db:"cover_art"`

	MalId     sql.NullString `db:"mal_id"`
	AnilistId sql.NullString `db:"anilist_id"`

	Created int64 `db:"created"`
	Updated int64 `db:"updated"`

	ChapterCount int64 `db:"chapter_count"`
}

type SerieChanges added in v0.10.0

type SerieChanges struct {
	Name types.Change[string]

	CoverArt types.Change[sql.NullString]

	MalId     types.Change[sql.NullString]
	AnilistId types.Change[sql.NullString]

	Created types.Change[int64]
}

type ToSQL

type ToSQL interface {
	ToSQL() (string, []interface{}, error)
}

type User

type User struct {
	Id       string `db:"id"`
	Username string `db:"username"`
	Password string `db:"password"`
	Role     string `db:"role"`

	Created int64 `db:"created"`
	Updated int64 `db:"updated"`

	// NOTE(patrik): This needs to match UserSettings
	DisplayName   sql.NullString `db:"display_name"`
	QuickPlaylist sql.NullString `db:"quick_playlist"`
}

func (User) ToUserSettings added in v0.10.0

func (u User) ToUserSettings() UserSettings

type UserChanges added in v0.10.0

type UserChanges struct {
	Username types.Change[string]
	Password types.Change[string]

	Created types.Change[int64]
}

type UserSettings added in v0.10.0

type UserSettings struct {
	Id            string         `db:"id"`
	DisplayName   sql.NullString `db:"display_name"`
	QuickPlaylist sql.NullString `db:"quick_playlist"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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