database

package
v0.0.0-...-04e558d Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyExists = errors.New("already exists")
View Source
var ErrNotExist = errors.New("resource does not exist")

Functions

This section is empty.

Types

type Chirp

type Chirp struct {
	AuthorID int    `json:"author_id"`
	Body     string `json:"body"`
	ID       int    `json:"id"`
}

type DB

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

func NewDB

func NewDB(path string) (*DB, error)

NewDB creates a new database connection and creates the database file if it doesn't exist

func (*DB) CreateChirp

func (db *DB) CreateChirp(body string, authorID int) (Chirp, error)

CreateChirp creates a new chirp and saves it to disk

func (*DB) CreateUser

func (db *DB) CreateUser(email, hashedPassword string) (User, error)

func (*DB) DeleteChirp

func (db *DB) DeleteChirp(id int) error

func (*DB) GetChirp

func (db *DB) GetChirp(id int) (Chirp, error)

func (*DB) GetChirps

func (db *DB) GetChirps() ([]Chirp, error)

GetChirps returns all chirps in the database

func (*DB) GetUser

func (db *DB) GetUser(id int) (User, error)

func (*DB) GetUserByEmail

func (db *DB) GetUserByEmail(email string) (User, error)

func (*DB) GetUsers

func (db *DB) GetUsers() ([]User, error)

func (*DB) IsTokenRevoked

func (db *DB) IsTokenRevoked(token string) (bool, error)

func (*DB) ResetDB

func (db *DB) ResetDB() error

remove the db

func (*DB) RevokeToken

func (db *DB) RevokeToken(token string) error

func (*DB) UpdateUser

func (db *DB) UpdateUser(id int, email, hashedPassword string) (User, error)

func (*DB) UpgradeChirpyRed

func (db *DB) UpgradeChirpyRed(id int) (User, error)

type DBStructure

type DBStructure struct {
	Chirps      map[int]Chirp         `json:"chirps"`
	Users       map[int]User          `json:"users"`
	Revocations map[string]Revocation `json:"revocations"`
}

type Revocation

type Revocation struct {
	Token     string    `json:"token"`
	RevokedAt time.Time `json:"revoked_at"`
}

type User

type User struct {
	ID             int    `json:"id"`
	Email          string `json:"email"`
	HashedPassword string `json:"hashed_password"`
	IsChirpyRed    bool   `json:"is_chripy_red"`
}

Jump to

Keyboard shortcuts

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