db

package
v0.0.0-...-19bbfc4 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2021 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Conn *sql.DB
View Source
var SchemaName string

Functions

func Close

func Close()

func Connect

func Connect(dbType DBType, dbRoute string, schemaName string)

Connect connects to database

func CreateTestData

func CreateTestData()

CreateTestData fill database with known test data for development/testing purposes

func Heartbeat

func Heartbeat()

func Setup

func Setup()

Setup constructs all the tables etc.,

func Wipe

func Wipe() error

Wipe drops all database tables

Types

type AuthSession

type AuthSession struct {
	Authsessionid      int    `tbl:"AI" json:"authsessionid"`
	CreatedDateTime    int64  `json:"createddatetime"`
	LastActiveDateTime int64  `json:"lastactivedatetime"`
	UserUUID           string `json:"userUUID"`
	SessionUUID        string `json:"sessionUUID"`
}

func (*AuthSession) BuildFields

func (as *AuthSession) BuildFields() []Field

func (*AuthSession) TableName

func (as *AuthSession) TableName() string

func (*AuthSession) Validate

func (as *AuthSession) Validate() bool

type AuthSessionsTable

type AuthSessionsTable struct {
	Authsessionid      int    `tbl:"PKNNAIUI"`
	CreatedDateTime    int64  `tbl:"NNDT"`
	LastActiveDateTime int64  `tbl:"NNDT"`
	UserUUID           string `tbl:"NNUI"`
	SessionUUID        string `tbl:"NNUI"`
}

func (*AuthSessionsTable) Delete

func (ast *AuthSessionsTable) Delete(db *sql.DB, whereClause string) error

func (*AuthSessionsTable) DeleteBySessionUUID

func (ast *AuthSessionsTable) DeleteBySessionUUID(db *sql.DB, sessionUUID string) error

func (*AuthSessionsTable) Init

func (ast *AuthSessionsTable) Init(db *sql.DB)

func (*AuthSessionsTable) Insert

func (ast *AuthSessionsTable) Insert(db *sql.DB, as *AuthSession) error

func (*AuthSessionsTable) Name

func (ast *AuthSessionsTable) Name() string

func (*AuthSessionsTable) Select

func (ast *AuthSessionsTable) Select(db *sql.DB, whatToSelect string, whereClause string) (*sql.Rows, error)

func (*AuthSessionsTable) SelectBySessionUUID

func (ast *AuthSessionsTable) SelectBySessionUUID(db *sql.DB, sessionUUID string) (*AuthSession, error)

func (*AuthSessionsTable) SelectByUserUUID

func (ast *AuthSessionsTable) SelectByUserUUID(db *sql.DB, userUUID string) (*AuthSession, error)

func (*AuthSessionsTable) Update

func (ast *AuthSessionsTable) Update(db *sql.DB, as *AuthSession) error

Update - Takes auth session to update existing user session entry session UUID

type DBType

type DBType int
const (
	VERSION = "v0.0.1a"

	MySQL  DBType = iota
	SQLITE DBType = iota
)
var Type DBType

func (*DBType) DriverName

func (dt *DBType) DriverName() string

type Field

type Field struct {
	AutoIncrement bool
	PrimaryKey    bool
	UniqueIndex   bool
	IsDateTime    bool
	NotNull       bool
	Name          string
	Type          string
	Value         interface{}
	// contains filtered or unexported fields
}

Field interface to describe a table field and all of its attributes

type Group

type Group struct {
	Groupid         int    `tbl:"AI" json:"groupid"`
	CreatedDateTime int64  `json:"createddatetime"`
	UUID            string `json:"UUID"`
	Title           string `json:"title"`
}

func (*Group) BuildFields

func (g *Group) BuildFields() []Field

func (*Group) TableName

func (g *Group) TableName() string

func (*Group) Validate

func (g *Group) Validate() bool

type GroupMembership

type GroupMembership struct {
	Groupmembershipid int    `tbl:"AI" json:"groupmembershipid"`
	CreatedDateTime   int64  `json:"createddatetime"`
	GroupUUID         string `json:"GroupUUID"`
	UserUUID          string `json:"UserUUID"`
}

func (*GroupMembership) BuildFields

func (gm *GroupMembership) BuildFields() []Field

func (*GroupMembership) TableName

func (gm *GroupMembership) TableName() string

type GroupMembershipTable

type GroupMembershipTable struct {
	GroupMembershipid int    `tbl:"PKNNAIUI"`
	CreatedDateTime   int64  `tbl:"NN"`
	GroupUUID         string `tbl:"NN"`
	UserUUID          string `tbl:"NN"`
}

func (*GroupMembershipTable) AddUserToGroup

func (gmt *GroupMembershipTable) AddUserToGroup(db *sql.DB, u *User, groupTitle string) error

func (*GroupMembershipTable) DeleteAllUsersFromGroup

func (gmt *GroupMembershipTable) DeleteAllUsersFromGroup(db *sql.DB, g *Group) (int64, error)

func (*GroupMembershipTable) DeleteUserFromGroup

func (gmt *GroupMembershipTable) DeleteUserFromGroup(db *sql.DB, u *User, g *Group) (int64, error)

func (*GroupMembershipTable) Init

func (gmt *GroupMembershipTable) Init(db *sql.DB)

Init initialise table to include default memeberships

func (*GroupMembershipTable) Insert

func (gmt *GroupMembershipTable) Insert(db *sql.DB, gm *GroupMembership) error

func (*GroupMembershipTable) Name

func (gmt *GroupMembershipTable) Name() string

func (*GroupMembershipTable) Select

func (gmt *GroupMembershipTable) Select(db *sql.DB, whatToSelect string, whereClause string) (*sql.Rows, error)

type GroupTable

type GroupTable struct {
	Groupid         int    `tbl:"PKNNAIUI"`
	CreatedDateTime int64  `tbl:"NNDT"`
	UUID            string `tbl:"NNUI"`
	Title           string `tbl:"NNUI"`
}

func (*GroupTable) DeleteByUUID

func (gt *GroupTable) DeleteByUUID(db *sql.DB, groupUUID string) (int64, error)

func (*GroupTable) Init

func (gt *GroupTable) Init(db *sql.DB)

func (*GroupTable) Insert

func (gt *GroupTable) Insert(db *sql.DB, g *Group) error

func (*GroupTable) Name

func (gt *GroupTable) Name() string

func (*GroupTable) Select

func (gt *GroupTable) Select(db *sql.DB, whatToSelect string, whereClause string) (*sql.Rows, error)

func (*GroupTable) SelectByTitle

func (gt *GroupTable) SelectByTitle(db *sql.DB, groupTitle string) (*Group, error)

func (*GroupTable) SelectByUUID

func (gt *GroupTable) SelectByUUID(db *sql.DB, groupUUID string) (*Group, error)

func (*GroupTable) Update

func (gt *GroupTable) Update(db *sql.DB, g *Group) error

type Model

type Model interface {
	TableName() string
	BuildFields() []Field
}

Model describes the structure of a model

type Page

type Page struct {
	PageId          int    `tbl:"AI" json:"pageid"`
	CreatedDateTime int64  `json:"createddatetime"`
	UUID            string `json:"UUID"`
	Roleprotected   bool   `json:"roleprotected"`
	AuthorUUID      string `json:"authoruuid"`
	Title           string `json:"title"`
	Route           string `json:"route"`
	Content         string `json:"content"`
}

func (*Page) BuildFields

func (p *Page) BuildFields() []Field

func (*Page) TableName

func (p *Page) TableName() string

type PagesTable

type PagesTable struct {
	Pageid          int    `tbl:"PKNNAIUI"`
	CreatedDateTime int64  `tbl:"NNDT"`
	UUID            string `tbl:"NNUI"`
	Roleprotected   bool   `tbl:"NN"`
	AuthorUUID      string `tbl:"NN"`
	Title           string `tbl:"NNUI"`
	Route           string `tbl:"NNUI"`
	Content         string `tbl:"NN"`
}

func (*PagesTable) DeleteByUUID

func (pt *PagesTable) DeleteByUUID(db *sql.DB, uuid string) (int64, error)

func (*PagesTable) Init

func (pt *PagesTable) Init(db *sql.DB)

func (*PagesTable) Insert

func (pt *PagesTable) Insert(db *sql.DB, p *Page) error

func (*PagesTable) Name

func (pt *PagesTable) Name() string

func (*PagesTable) Select

func (pt *PagesTable) Select(db *sql.DB, whatToSelect string, whereClause string) (*sql.Rows, error)

func (*PagesTable) SelectByRoute

func (pt *PagesTable) SelectByRoute(db *sql.DB, route string) (*Page, error)

TODO: Should really consider changing this to call the existing select func

func (*PagesTable) SelectByUUID

func (pt *PagesTable) SelectByUUID(db *sql.DB, uuid string) (*Page, error)

func (*PagesTable) Update

func (pt *PagesTable) Update(db *sql.DB, p *Page) error

type SystemInfo

type SystemInfo struct {
	Version string `json:"version"`
}

func (*SystemInfo) BuildFields

func (si *SystemInfo) BuildFields() []Field

func (*SystemInfo) TableName

func (si *SystemInfo) TableName() string

type SystemInfoTable

type SystemInfoTable struct {
	Version string `tbl:NN`
}

func (*SystemInfoTable) Init

func (sit *SystemInfoTable) Init(db *sql.DB)

func (*SystemInfoTable) Insert

func (sit *SystemInfoTable) Insert(db *sql.DB, systemInfo *SystemInfo) error

func (*SystemInfoTable) Name

func (sit *SystemInfoTable) Name() string

func (*SystemInfoTable) Update

func (sit *SystemInfoTable) Update(db *sql.DB, as *SystemInfo) error

type Table

type Table interface {
	Init(db *sql.DB)
	Name() string
	// contains filtered or unexported methods
}

Table interface to inherit from all table structs

type User

type User struct {
	UserId          int    `tbl:"AI" json:"userid"`
	CreatedDateTime int64  `json:"createddatetime"`
	UserroleId      int    `json:"userroleid"`
	UUID            string `json:"UUID"`
	Username        string `json:"username"`
	AuthHash        string `json:"authhash"`
	FirstName       string `json:"firstname"`
	LastName        string `json:"lastname"`
	Email           string `json:"email"`
}

User describes the content of a user, it should match the columns present in the users table

func (*User) BuildFields

func (u *User) BuildFields() []Field

BuildFields generates a list of fields generated from the fields of the user struct

func (*User) Login

func (u *User) Login() bool

Login takes the current username and authhash values of self and tries using them to authenticate/login. A successful login will return/generate a JWT token for further use in any subsequent API request

func (*User) TableName

func (u *User) TableName() string

TableName gets the name of the users table

func (*User) Validate

func (u *User) Validate() error

Validate makes sure that required fields have not been left blank

type UserRole

type UserRole struct {
	Userroleid int `tbl:"AI"`
	Rolename   string
}

UserRole describes the content of a userrole entry, it should match the columns present in the userrole table

func (*UserRole) BuildFields

func (ur *UserRole) BuildFields() []Field

BuildFields generates a list of fields generated from the fields of the userrole struct

func (*UserRole) TableName

func (ur *UserRole) TableName() string

TableName gets the name of the userrole table

type UsersRoleFlag

type UsersRoleFlag int
const (
	ROOT_USER UsersRoleFlag = 2
	MOD_USER  UsersRoleFlag = 3
	REG_USER  UsersRoleFlag = 4
)

type UsersTable

type UsersTable struct {
	Userid          int    `tbl:"PKNNAIUI"`
	CreatedDateTime int64  `tbl:"NNDT"`
	Userroleid      int    `tbl:"NN"`
	UUID            string `tbl:"NNUI"`
	Username        string `tbl:"NNUI"`
	Authhash        string `tbl:"NN"`
	Firstname       string `tbl:"NN"`
	Lastname        string `tbl:"NN"`
	Email           string `tbl:"NNUI"`
}

UsersTable describes the table structure for UsersTable in db

func (*UsersTable) DeleteByUUID

func (ut *UsersTable) DeleteByUUID(db *sql.DB, uuid string) (int64, error)

func (*UsersTable) Init

func (ut *UsersTable) Init(db *sql.DB)

Init carries out default data entry

func (*UsersTable) Insert

func (ut *UsersTable) Insert(db *sql.DB, u *User) error

Insert adds user struct to users table, it also sets default values

func (*UsersTable) InsertMultiple

func (ut *UsersTable) InsertMultiple(db *sql.DB, us []*User) error

InsertMultiple takes a slice of user structs and passes them all to 'Insert'

func (*UsersTable) Name

func (ut *UsersTable) Name() string

Name gets the table name, have to implement to make UsersTable inherit Table

func (*UsersTable) RootUserExists

func (ut *UsersTable) RootUserExists() bool

RootUserExists checks if at least one root user exists

func (*UsersTable) Select

func (ut *UsersTable) Select(db *sql.DB, whatToSelect string, whereClause string) (*sql.Rows, error)

Select returns table rows from a select using the passed where condition

func (*UsersTable) SelectByUUID

func (ut *UsersTable) SelectByUUID(db *sql.DB, uuid string) (*User, error)

func (*UsersTable) SelectByUsername

func (ut *UsersTable) SelectByUsername(db *sql.DB, username string) (*User, error)

func (*UsersTable) SelectRootUser

func (ut *UsersTable) SelectRootUser(db *sql.DB) (*User, error)

Jump to

Keyboard shortcuts

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