database

package
v0.0.0-...-7b47e6d Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2024 License: AGPL-3.0-or-later Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const DELETED_USER_NAME = "deleted user"
View Source
const SYSTEM_USER_NAME = "CERCA_CMD"

Variables

This section is empty.

Functions

func CheckExists

func CheckExists(filepath string) bool

func Migration20240116_PwhashChange

func Migration20240116_PwhashChange(filepath string) (finalErr error)

func Migration20240720_ThreadPrivateChange

func Migration20240720_ThreadPrivateChange(filepath string) (finalErr error)

Types

type DB

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

func InitDB

func InitDB(filepath string) DB

func (DB) AddAdmin

func (d DB) AddAdmin(userid int) error

func (DB) AddModerationLog

func (d DB) AddModerationLog(actingid, recipientid, action int) error

func (DB) AddPost

func (d DB) AddPost(content string, threadid, authorid int) (postID int)

func (DB) AddRegistration

func (d DB) AddRegistration(userid int, verificationLink string) error

func (DB) CheckThreadExists

func (d DB) CheckThreadExists(threadid int) (bool, error)

func (DB) CheckUserExists

func (d DB) CheckUserExists(userid int) (bool, error)

func (DB) CheckUsernameExists

func (d DB) CheckUsernameExists(username string) (bool, error)

func (DB) CreateThread

func (d DB) CreateThread(title, content string, authorid, topicid int, isPrivate bool) (int, error)

func (DB) CreateTopic

func (d DB) CreateTopic(title, description string)

func (DB) CreateUser

func (d DB) CreateUser(name, hash string) (int, error)

func (DB) DeletePost

func (d DB) DeletePost(postid int) error

func (DB) DeleteThread

func (d DB) DeleteThread()

func (DB) DeleteTopic

func (d DB) DeleteTopic(topicid int)

func (DB) DemoteAdmin

func (d DB) DemoteAdmin(userid int) error

func (DB) EditPost

func (d DB) EditPost(content string, postid int)

func (DB) Exec

func (d DB) Exec(stmt string, args ...interface{}) (sql.Result, error)
goal for 2021-12-28

* in browser: reply on a thread * in browser: create a new thread

func (DB) FinalizeProposedAction

func (d DB) FinalizeProposedAction(proposalid, adminid int, decision bool) (finalErr error)

finalize a proposal by either confirming or vetoing it, logging the requisite information and then finally executing the proposed action itself

func (DB) GetAdmins

func (d DB) GetAdmins() []User

func (DB) GetModerationLogs

func (d DB) GetModerationLogs() []ModerationEntry

func (DB) GetPasswordHash

func (d DB) GetPasswordHash(username string) (string, int, error)

func (DB) GetPost

func (d DB) GetPost(postid int) (Post, error)

func (DB) GetProposedActions

func (d DB) GetProposedActions() []ModProposal

func (DB) GetSystemUserid

func (d DB) GetSystemUserid() int

func (DB) GetThread

func (d DB) GetThread(threadid int) ([]Post, error)

TODO(2021-12-28): return error if non-existent thread

func (DB) GetUserID

func (d DB) GetUserID(name string) (int, error)

func (DB) GetUsername

func (d DB) GetUsername(uid int) (string, error)

func (DB) GetUsers

func (d DB) GetUsers(includeAdmin bool) []User

func (DB) IsThreadPrivate

func (d DB) IsThreadPrivate(threadid int) (bool, error)

func (DB) IsUserAdmin

func (d DB) IsUserAdmin(userid int) (bool, error)

func (DB) ListThreads

func (d DB) ListThreads(sortByPost bool, includePrivate bool) []Thread

get a list of threads NOTE: this query is setting thread.Author not by thread creator, but latest poster. if this becomes a problem, revert its use and employ Thread.PostID to perform another query for each thread to get the post author name (wrt server.go:GenerateRSS)

func (DB) MoveThread

func (d DB) MoveThread()

func (DB) ProposeModerationAction

func (d DB) ProposeModerationAction(proposerid, recipientid, action int) (finalErr error)

func (DB) QuorumActivated

func (d DB) QuorumActivated() bool

func (DB) RemoveUser

func (d DB) RemoveUser(userid int) (finalErr error)

there are a bunch of places that reference a user's id, so i don't want to break all of those

i also want to avoid big invisible holes in a conversation's history

remove user performs the following operation: 1. checks to see if the DELETED USER exists; otherwise create it and remember its id

2. if it exists, we swap out the userid for the DELETED_USER in tables: - table threads authorid - table posts authorid - table moderation_log actingid or recipientid

the entry in registrations correlating to userid is removed if allowing deletion of post contents as well when removing account, userid should be used to get all posts from table posts and change the contents to say _deleted_

func (DB) ResetPassword

func (d DB) ResetPassword(userid int) (string, error)

func (DB) UpdateTopicDescription

func (d DB) UpdateTopicDescription(topicid int, newdesc string)

func (DB) UpdateTopicName

func (d DB) UpdateTopicName(topicid int, newname string)

func (DB) UpdateUserName

func (d DB) UpdateUserName(userid int, newname string)

func (DB) UpdateUserPasswordHash

func (d DB) UpdateUserPasswordHash(userid int, newhash string)

type ModProposal

type ModProposal struct {
	ActingUsername, RecipientUsername string
	ActingID, RecipientID             int
	ProposalID, Action                int
	Time                              time.Time
}

type ModerationEntry

type ModerationEntry struct {
	ActingUsername, RecipientUsername, QuorumUsername string
	QuorumDecision                                    bool
	Action                                            int
	Time                                              time.Time
}

type Post

type Post struct {
	ID          int
	ThreadTitle string
	ThreadID    int
	Content     string // markdown
	Author      string
	AuthorID    int
	Publish     time.Time
	LastEdit    sql.NullTime // TODO: handle json marshalling with custom type
}

c.f. https://medium.com/aubergine-solutions/how-i-handled-null-possible-values-from-database-rows-in-golang-521fb0ee267 type NullTime sql.NullTime

type Thread

type Thread struct {
	Title   string
	Author  string
	Slug    string
	Private bool
	ID      int
	Publish time.Time
	PostID  int
}

type User

type User struct {
	Name string
	ID   int
}

Jump to

Keyboard shortcuts

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