database

package
Version: v0.0.0-...-233ae75 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2016 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DB_USER     = "mappyr"  //"kpssujtcjeylzx"
	DB_PASSWORD = "mappass" //"By5bPQQibYr5KDkBu-E9nU5eaO"
	DB_NAME     = "mappyr"  //"dcnd0p0l81l0dr"
	DB_SSL      = "disable" // "require"
)

Variables

This section is empty.

Functions

func CreateTable

func CreateTable(db *sql.DB) error

CreateTable creates the database tables

func DeleteComment

func DeleteComment(db *sql.DB, id int) error

Delete

func InitDB

func InitDB() (*sql.DB, error)

InitDB Opens a new sqlite3 db in path

func LogIn

func LogIn(db *sql.DB, username, password string) (bool, int)

LogIn checks if the password and username match, if so, return TRUE

func SignUp

func SignUp(db *sql.DB, u User) (int, error)

SignUp will create a new user in the table.

func VoteComment

func VoteComment(db *sql.DB, comment_id, user_id int, up bool) error

UpVoteComment

func WriteComment

func WriteComment(db *sql.DB, c Comment) (int, error)

WriteComment

Types

type Comment

type Comment struct {
	Id          int       `json:"id"`
	Title       string    `json:"title"`
	Description string    `json:"description"`
	Lat         float64   `json:"latitude"`
	Lon         float64   `json:"longitude"`
	Upvotes     int       `json:"upvotes"`
	Downvotes   int       `json:"downvotes"`
	Date        time.Time `json:"date"`
	UserId      int       `json:"user-id"` // 0 for anon
	User        User      `json:"user"`
}

TODO: Add a place model? TODO: Description UPvote and Downvote

func ReadComment

func ReadComment(db *sql.DB, id int) (Comment, error)

ReadComment reads a comment from the datase with an id.

func ReadComments

func ReadComments(db *sql.DB) ([]Comment, error)

ReadComments returns all comments TODO: Add the USER to the Comment Struct

func ReadLocalComments

func ReadLocalComments(db *sql.DB, xRange, yRange [2]float64) ([]Comment, error)

ReadLocalComments reads comments within ranges TODO: Add the USER to the Comment Struct

func UserComments

func UserComments(user_id int, db *sql.DB) ([]Comment, error)

func (*Comment) String

func (c *Comment) String() string

type User

type User struct {
	Id       int       `json:"id"`
	Name     string    `json:"username"`
	Password string    `json:"-"`
	Date     time.Time `json:"date"`
	Email    string    `json:"email"`
}

func ReadUser

func ReadUser(db *sql.DB, id int) (User, error)

ReadUser returns a user by ID

func ReadUsers

func ReadUsers(db *sql.DB) ([]User, error)

ReadUsers returns all users

type Vote

type Vote struct {
	Comment int  `json:"comment_id"`
	User    int  `json:"user_id"`
	Up      bool `json:"up"`
}

func CommentVotes

func CommentVotes(comment_id, db *sql.DB) ([]Vote, error)

CommentVotes returns a slice of Vote structs according to a passed in comment ID

func UserVotes

func UserVotes(user_id int, db *sql.DB) ([]Vote, error)

Jump to

Keyboard shortcuts

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