database

package
v0.0.0-...-cc64782 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CT_Line    string = "line"
	CT_Area    string = "area"
	CT_Column  string = "column"
	CT_Bar     string = "bar"
	CT_Treemap string = "treemap"
	CT_Heatmap string = "heatmap"
	CT_Pie     string = "pie"
	CT_Radar   string = "radar"
	CT_Polar   string = "polar"
	CT_Scatter string = "scatter"
)

Variables

This section is empty.

Functions

func GetConnectionString

func GetConnectionString(testPath PathType) (string, error)

Construct database connection string using `.env` variables. Sets up `.env` path for testing when testPath is true.

func GetQuerySearchSuffix

func GetQuerySearchSuffix(query_name string) string

func GetSearchSuffix

func GetSearchSuffix(key string, table string, stringColumn string, intColumn string) string

Parse the 'key'. If it parses to an integer, use the 'table'.'intColumn' to compare against 'key'. Otherwise use the 'table'.'stringColumn' to compare against 'key'

func GetUserSearchSuffix

func GetUserSearchSuffix(user_name string) string

Types

type Chart

type Chart struct {
	Id    int    `json:"id,omitempty"`
	Title string `json:"title"`
	Type  string `json:"type"`
	Xname string `json:"x_axis"`
	Yname string `json:"y_axis"`
}

type ChartSeries

type ChartSeries struct {
	Name    string `json:"name"`
	Id      int    `json:"id,omitempty"`
	ChartID int    `json:"chart_id"`
	QueryID int    `json:"query_id"`
	XCol    string `json:"x_col_name"`
	YCol    string `json:"y_col_name"`
}

type Dashboard

type Dashboard struct {
	Id      int    `json:"id,omitempty"`
	Title   string `json:"title"`
	Content string `json:"content"`
}

type DashboardGraphs

type DashboardGraphs struct {
	DashId  int `json:"dash_id"`
	ChartId int `json:"chart_id"`
	SizeX   int `json:"size_x"`
	SizeY   int `json:"size_y"`
	Order   int `json:"order"`
}

type DbManager

type DbManager struct {
	Connection *pgxpool.Pool
	Context    context.Context
	// contains filtered or unexported fields
}

func NewDbManager

func NewDbManager(connectionString string, ctx context.Context) (*DbManager, error)

func (*DbManager) AddDashboardRolePermission

func (d *DbManager) AddDashboardRolePermission(dashId int, roleId int, permissionId int) error

Associate a dashboard, role, and permission

func (*DbManager) AddRole

func (d *DbManager) AddRole(role Role) (int, error)

Add a new role to the database

func (*DbManager) AddUserRole

func (d *DbManager) AddUserRole(userID string, roleID string) error

Add a role to a user

func (*DbManager) AppendChartToDashboard

func (d *DbManager) AppendChartToDashboard(dashID, chartID, sizeX, sizeY int) error

func (*DbManager) ConnectToDatabase

func (d *DbManager) ConnectToDatabase() error

Connect to database using set connection string

func (*DbManager) DeleteAllChartSeries

func (d *DbManager) DeleteAllChartSeries(chart_id int) error

func (*DbManager) DeleteChart

func (d *DbManager) DeleteChart(chart_id int) error

func (*DbManager) DeleteChartSeries

func (d *DbManager) DeleteChartSeries(series_id int) error

func (*DbManager) DeleteCustomQuery

func (d *DbManager) DeleteCustomQuery(query_name string) error

Delete a custom query based on ID

func (*DbManager) DeleteDashboard

func (d *DbManager) DeleteDashboard(dashID int) error

Delete a dashboard by ID

func (*DbManager) DeleteDashboardRolePermission

func (d *DbManager) DeleteDashboardRolePermission(dashId int, roleId int, permissionId int) error

Delete an association between a dashboard, role, and permission

func (*DbManager) DeleteRole

func (d *DbManager) DeleteRole(roleId int) error

Delete a role

func (*DbManager) DeleteUser

func (d *DbManager) DeleteUser(username string) error

Delete a user from the database by username

func (*DbManager) DeleteUserRole

func (d *DbManager) DeleteUserRole(userID string, roleID string) error

Delete a role from a user

func (*DbManager) DumpSchema

func (d *DbManager) DumpSchema() (string, error)

func (*DbManager) ExecuteCustomQuery

func (d *DbManager) ExecuteCustomQuery(query string) ([]map[string]string, error)

func (*DbManager) GetAllUsers

func (d *DbManager) GetAllUsers() ([]User, error)

func (*DbManager) GetChart

func (d *DbManager) GetChart(chart_id int) (Chart, error)

func (*DbManager) GetChartSeries

func (d *DbManager) GetChartSeries(series_id int) (ChartSeries, error)

func (*DbManager) GetCustomQuery

func (d *DbManager) GetCustomQuery(idName string) (string, string, error)

Get the custom query string saved as some ID

func (*DbManager) GetDashboard

func (d *DbManager) GetDashboard(dashID int) (Dashboard, error)

Get a single dashboard by ID

func (*DbManager) GetPermissions

func (d *DbManager) GetPermissions() ([]Permission, error)

Get all permissions

func (*DbManager) GetRoles

func (d *DbManager) GetRoles() ([]Role, error)

Get count of users per role

func (*DbManager) GetScopedPermissions

func (d *DbManager) GetScopedPermissions(scope ScopeType) ([]Permission, error)

Get all permissions with a specific scope (e.g. 'global', 'dashboard')

func (*DbManager) GetSetting

func (d *DbManager) GetSetting(key string) (string, error)

Get key-value pair from settings table in database

func (*DbManager) GetSingleUser

func (d *DbManager) GetSingleUser(name string) (User, error)

Return a user based on username. Return error if no user found.

func (*DbManager) InsertChart

func (d *DbManager) InsertChart(chart Chart) (int, error)

func (*DbManager) InsertChartSeries

func (d *DbManager) InsertChartSeries(series []ChartSeries) (int, error)

func (*DbManager) InsertCustomQuery

func (d *DbManager) InsertCustomQuery(query_name string, query_string string) (int, error)

Insert a custom query into the database

func (*DbManager) InsertDashboard

func (d *DbManager) InsertDashboard(dash Dashboard) (int, error)

Insert a new dashboard, returns new dashboard ID

func (*DbManager) InsertUser

func (d *DbManager) InsertUser(username string, password string) (User, error)

Insert user into the database. Expects the password to be hashed using the auth module.

func (*DbManager) IsUserAdmin

func (d *DbManager) IsUserAdmin(user User) (bool, error)

Check if a user has the admin role.

func (*DbManager) ListAllCharts

func (d *DbManager) ListAllCharts() ([]Chart, error)

func (*DbManager) ListAllDashboards

func (d *DbManager) ListAllDashboards() ([]Dashboard, error)

List all dashboards

func (*DbManager) ListChartSeries

func (d *DbManager) ListChartSeries(chart_id int) ([]ChartSeries, error)

func (*DbManager) ListCustomQueries

func (d *DbManager) ListCustomQueries() ([]Query, error)

List the available queries

func (*DbManager) ListDashboardCharts

func (d *DbManager) ListDashboardCharts(dashID int) ([]DashboardGraphs, error)

List all charts for a dashboard

func (*DbManager) RemoveChartFromDashboard

func (d *DbManager) RemoveChartFromDashboard(dashID, chartID int) error

Remove a chart from a dashboard

func (*DbManager) SetConnectionString

func (d *DbManager) SetConnectionString(conStr string)

Set connection string

func (*DbManager) SetSetting

func (d *DbManager) SetSetting(key string, value string) error

Set or update a key-value pair in the settings table in the database

func (*DbManager) UpdateChart

func (d *DbManager) UpdateChart(chart Chart) error

func (*DbManager) UpdateChartSeries

func (d *DbManager) UpdateChartSeries(series ChartSeries) error

func (*DbManager) UpdateCustomQueryLiteral

func (d *DbManager) UpdateCustomQueryLiteral(queryId int, newLiteral string) error

Update a custom query in the database

func (*DbManager) UpdateCustomQueryName

func (d *DbManager) UpdateCustomQueryName(queryId int, newName string) error

func (*DbManager) UpdateRole

func (d *DbManager) UpdateRole(role Role) error

Update a role.

func (*DbManager) UpdateRoleColor

func (d *DbManager) UpdateRoleColor(roleId int, newColor string) error

Update a role color

func (*DbManager) UpdateRoleName

func (d *DbManager) UpdateRoleName(roleId int, newName string) error

Update a role name

func (*DbManager) UpdateUser

func (d *DbManager) UpdateUser(userid int, name string, password string) error

Update a user, expects pre-hashed password (do not give this plaintext pls)

type PathType

type PathType bool
const (
	DefaultPath PathType = false
	TestPath    PathType = true
)

type Permission

type Permission struct {
	Id    int       `json:"id"`
	Name  string    `json:"name"`
	Scope ScopeType `json:"scope,omitempty"`
}

type Query

type Query struct {
	Id      int    `json:"id"`
	Name    string `json:"name"`
	Literal string `json:"literal"`
}

type Role

type Role struct {
	Id          int          `json:"id,omitempty"`
	Name        string       `json:"name"`
	Color       string       `json:"color"`
	Permissions []Permission `json:"permissions,omitempty"`
	UserCount   int          `json:"usercount,omitempty"`
}

type ScopeType

type ScopeType string
const (
	GlobalScope    ScopeType = "global"
	DashboardScope ScopeType = "dashboard"
	EmptyScope     ScopeType = ""
)

func StringToScopeType

func StringToScopeType(s string) ScopeType

type Settings

type Settings struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

type User

type User struct {
	Id       int    `json:"id,omitempty"`
	Name     string `json:"username"`
	Password string `json:"password,omitempty"`
	Roles    []int  `json:"role"`
}

Jump to

Keyboard shortcuts

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