database

package
v0.0.0-...-f92707a Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chirp

type Chirp struct {
	Id       int    `json:"id"`
	AuthorId int    `json:"author_id"`
	Body     string `json:"body"`
}

type DB

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

object to read and write from database file

func NewDB

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

new database connection struct

func (*DB) CreateChirp

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

func (*DB) CreateRevokedToken

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

func (*DB) CreateUser

func (db *DB) CreateUser(email string, password string) error

func (*DB) DeleteChirp

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

func (*DB) GetChirps

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

GetChirps returns all chirps in the database

func (*DB) GetRevokedTokens

func (db *DB) GetRevokedTokens() (map[string]time.Time, error)

func (*DB) GetUsers

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

func (*DB) UpdateIsRed

func (db *DB) UpdateIsRed(id int, state bool) error

func (*DB) UpdateUser

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

type DBStructure

type DBStructure struct {
	Chirps        map[int]Chirp        `json:"chirps"`
	Users         map[int]User         `json:"users"`
	RevokedTokens map[string]time.Time `json:"revoked_tokens"`
}

data structure to hold database in memory

type User

type User struct {
	Id          int    `json:"id"`
	Email       string `json:"email"`
	Password    []byte `json:"password"`
	IsChirpyRed bool   `json:"is_chirpy_red"`
}

Jump to

Keyboard shortcuts

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