sqlite

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2021 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Storage

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

Storage stores restaurant data in a sqlite3 database

func NewStorage

func NewStorage(dbPath string) (Storage, error)

NewStorage returns a new database/sql instance initialized with sqlite3

func (Storage) AddCity

func (s Storage) AddCity(cityName string, stateName string) int64

AddCity adds a city to the city table and returns the primary key id. Must call Commit() to commit transaction

func (Storage) AddGmapsPlace

func (s Storage) AddGmapsPlace(g adder.GmapsPlace) int64

AddGmapsPlace adds a Google Maps Place to the database and returns the primary key id. Must call Commit() to commit the transaction

func (Storage) AddRestaurant

func (s Storage) AddRestaurant(r adder.Restaurant) int64

AddRestaurant adds the given restaurant to the sqlite database. Must call Commit() to commit transaction

func (Storage) AddUser added in v1.0.0

func (s Storage) AddUser(u adder.User) int64

AddUser adds a given user to the database and returns the new user id. Caller must call Commit() to commit the transaction.

func (Storage) AddVisit

func (s Storage) AddVisit(v adder.Visit) int64

AddVisit adds the given visit to the sqlite database. Must call Commit() to commit transaction

func (Storage) AddVisitUser

func (s Storage) AddVisitUser(vu adder.VisitUser) int64

AddVisitUser adds the given visit to the sqlite database. Must call Commit() to commit transaction

func (*Storage) Begin

func (s *Storage) Begin()

Begin starts a transaction

func (Storage) CloseStorage

func (s Storage) CloseStorage()

CloseStorage closes the database by calling db.Close()

func (Storage) Commit

func (s Storage) Commit()

Commit "saves" the transaction to the database

func (Storage) GetCityIDByNameAndState

func (s Storage) GetCityIDByNameAndState(cityName string, stateName string) int64

GetCityIDByNameAndState queries the database for a given city name and state name, returns the id of the row if it exists

func (Storage) GetDistinct added in v1.0.0

func (s Storage) GetDistinct(columnName string, tableName string) []string

GetDistinct returns a list of distinct values for a given column from a given table

func (Storage) GetRestaurant

func (s Storage) GetRestaurant(id int64) lister.Restaurant

GetRestaurant queries the restaurant table for the given id. If the returned restaurant has ID = 0 then it is not in the database

func (Storage) GetRestaurantAvgRatingByUser added in v1.0.0

func (s Storage) GetRestaurantAvgRatingByUser(restaurantID int64) []lister.AvgUserRating

GetRestaurantAvgRatingByUser gets a given restaurants average rating group by user. If the returned value for a user is 0 then the restaurant has no ratings for that user.

func (Storage) GetRestaurants

func (s Storage) GetRestaurants(sortOps []lister.SortOperation, filterOps []lister.FilterOperation) []lister.Restaurant

GetRestaurants queries the restaurant table for all restaurants.

func (Storage) GetRestaurantsByCity

func (s Storage) GetRestaurantsByCity(cityID int64) []lister.Restaurant

GetRestaurantsByCity gives you all the restaurants with a given city id.

func (Storage) GetUser

func (s Storage) GetUser(id int64) lister.User

GetUser queries the user table for a given user id. If the returned user has ID = 0 then it is not in the db.

func (Storage) GetUserAuthByEmail added in v1.0.0

func (s Storage) GetUserAuthByEmail(email string) auther.User

GetUserAuthByEmail returns the password and remember hashes of a given email. If the returned user has ID = 0 then it is not in the db.

func (Storage) GetUserAuthByID added in v1.0.0

func (s Storage) GetUserAuthByID(id int64) auther.User

GetUserAuthByID returns the password and remember hashes of a given email. If the returned user has ID = 0 then it is not in the db.

func (Storage) GetUserBy added in v1.0.0

func (s Storage) GetUserBy(field string, value string) lister.User

GetUserBy queries the user table for a given user by field and value. Do not pass field arguments from untrusted sources. If the returned user has ID = 0 then it is not in the db.

func (Storage) GetUserCount added in v1.0.0

func (s Storage) GetUserCount() int64

GetUserCount returns the number of users in the db.

func (Storage) GetUsers added in v1.0.0

func (s Storage) GetUsers() []lister.User

GetUsers queries the user table for all the users.

func (Storage) GetVisit

func (s Storage) GetVisit(id int64, resID int64) lister.Visit

GetVisit queries the visit table for a given visit id and restaurant id. If the returned visit has ID = 0 then it is not in the database

func (Storage) GetVisitUsersByVisitID

func (s Storage) GetVisitUsersByVisitID(visitID int64) []lister.VisitUser

GetVisitUsersByVisitID queries the db for user for the given visit_id

func (Storage) GetVisitsByRestaurantID

func (s Storage) GetVisitsByRestaurantID(restaurantID int64, sortOps []lister.SortOperation) []lister.Visit

GetVisitsByRestaurantID gets all the visits for a given restaurant_id

func (Storage) IsDuplicateRestaurant

func (s Storage) IsDuplicateRestaurant(r adder.Restaurant) bool

IsDuplicateRestaurant returns true if the database already has a restaurant with the same name in the same city and state

func (Storage) RemoveCity

func (s Storage) RemoveCity(cityID int64) int64

RemoveCity deletes a given city and returns the number of rows affected. Caller must call Commit() to commit the transaction

func (Storage) RemoveGmapsPlace added in v1.0.0

func (s Storage) RemoveGmapsPlace(gmapsID int64) int64

func (Storage) RemoveRestaurant

func (s Storage) RemoveRestaurant(r remover.Restaurant) int64

RemoveRestaurant deletes a given restaurant from the database and returns the rows affected. Caller must call Commit() to commit the transaction

func (Storage) RemoveVisit

func (s Storage) RemoveVisit(visitID int64) int64

RemoveVisit deletes a given visit and returns the number of rows affected. Caller must call Commit() to commit the transaction

func (Storage) RemoveVisitUser

func (s Storage) RemoveVisitUser(visitUserID int64) int64

RemoveVisitUser deletes a given visit_user and returns the number of rows affected. Caller must call Commit() to commit the transaction

func (Storage) RestaurantFilterFields added in v1.0.0

func (s Storage) RestaurantFilterFields() map[string]lister.Field

func (Storage) RestaurantSortFields added in v1.0.0

func (s Storage) RestaurantSortFields() map[string]string

func (Storage) Rollback

func (s Storage) Rollback()

Rollback rolls the inserts/updates back

func (Storage) UpdateGmapsPlace

func (s Storage) UpdateGmapsPlace(gp updater.GmapsPlace) int64

UpdateGmapsPlace updates a given gmaps_place, returns the rows affected. Caller must call Commit() to commit the transaction

func (Storage) UpdateRestaurant

func (s Storage) UpdateRestaurant(r updater.Restaurant) int64

UpdateRestaurant updates a given restaurant, returns the rows affected. Must call Commit() to commit transaction

func (Storage) UpdateUser added in v1.0.0

func (s Storage) UpdateUser(u updater.User) int64

UpdateUser updates a given user, returns the rows affected. Caller must call Commit() to commit the transaction

func (Storage) UpdateUserPassword added in v1.0.0

func (s Storage) UpdateUserPassword(id int64, newPasswordHash string) int64

UpdateUserPassword updates the password of the user with the given id. Caller must call Commit() to commit the transaction

func (Storage) UpdateUserRememberToken added in v1.0.0

func (s Storage) UpdateUserRememberToken(u auther.User) int64

UpdateUserRememberToken updates a user's remember_hash and then returns the number of rows affected. Caller must call Commit() to commit the transaction.

func (Storage) UpdateVisit

func (s Storage) UpdateVisit(v updater.Visit) int64

UpdateVisit updates a given visit, returns the rows affected. Caller must call Commit() to commit the transaction

func (Storage) UpdateVisitUser

func (s Storage) UpdateVisitUser(vu updater.VisitUser) int64

UpdateVisitUser updates a given visit_user, returns the rows affected. Caller must call Commit() to commit the transaction

func (Storage) VisitSortFields added in v1.0.0

func (s Storage) VisitSortFields() map[string]string

Jump to

Keyboard shortcuts

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