database

package
v0.0.0-...-591516b Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2024 License: Apache-2.0 Imports: 5 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"`
	Body string `json:"body"`
}

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) (Chirp, error)

CreateChirp creates a new chirp and saves it to disk

func (*DB) CreateUser

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

func (*DB) GetChirp

func (db *DB) GetChirp(chirpId 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(email string) (*User, error)

func (*DB) GetUserById

func (db *DB) GetUserById(userId int) *User

func (*DB) UpdateUser

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

type DBStructure

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

type User

type User struct {
	Id       int    `json:"id"`
	Email    string `json:"email"`
	Password string `json:"password"`
}

Jump to

Keyboard shortcuts

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