db

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

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

Go to latest
Published: Apr 27, 2024 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Assets embed.FS
View Source
var DbConnectionId int64

DbConnectionId holds the current database connection

View Source
var DbEngine string

DbEngine holds the current database engine in use (e.g., "sqlite", "mysql").

View Source
var DbHandler *sql.DB

DbHandler is the database handler representing the open database connection.

Functions

func Close

func Close() error

Close closes the open database connection.

func Cols

func Cols(query string, args ...interface{}) ([]string, error)

Cols executes a query with optional parameters and returns the column names of the result set.

func CommandExists

func CommandExists(commands []TypeCommand, commandName string) bool

CommandExists checks if a given command exists in the provided list of commands.

func Del

func Del(ownerId int64, moduleId, ejaId int64) error

Del deletes a row from the specified module table based on ownerId, moduleId, and ejaId.

func FieldAdd

func FieldAdd(tableName string, fieldName string, fieldType string) error

FieldAdd adds a new field to the specified table with the given name and type.

func FieldExists

func FieldExists(tableName string, fieldName string) (bool, error)

FieldExists checks whether a field with the given name already exists in the specified table.

func FieldNameIsValid

func FieldNameIsValid(name string) error

FieldNameIsValid checks the validity of a field name based on the current database engine.

func FieldNameList

func FieldNameList(moduleId int64, actionType string) (fields []string)

FieldNameList retrieves a list of field names based on the provided module ID and action type.

func FieldType

func FieldType(name string) string

FieldType returns the corresponding SQL type for a given field type.

func FieldTypeGet

func FieldTypeGet(moduleId int64, fieldName string) string

FieldTypeGet retrieves the field type for a specific field in a module based on module ID and field name.

func Float

func Float(nameValue interface{}) float64

Float converts a value to a float64. It handles various numeric types and attempts to parse a string as a float64. If parsing fails, it returns 0.0.

func IncludeList

func IncludeList(query string, args ...interface{}) ([]int64, error)

IncludeList executes a query and returns a slice of int64 values from the first column of the result.

func LinkAdd

func LinkAdd(ownerId int64, moduleId int64, fieldId int64, linkModuleId int64, linkFieldId int64) error

LinkAdd adds a new link between modules and fields.

func LinkDel

func LinkDel(ownerId int64, moduleId int64, fieldId int64, linkModuleId int64, linkFieldId int64) error

LinkDel deletes a link between modules and fields.

func ModuleGetIdByName

func ModuleGetIdByName(name string) int64

ModuleGetIdByName retrieves the module ID based on the given module name. If an error occurs during the database operation or table name is not valid, it returns 0.

func ModuleGetNameById

func ModuleGetNameById(id int64) string

ModuleGetNameById retrieves the module name based on the given module ID. If an error occurs during the database operation or table name is not valid, it returns an empty string.

func ModuleImport

func ModuleImport(module TypeModule, moduleName string) error

ModuleImport imports a module into the database based on the provided TypeModule and module name.

func New

func New(ownerId int64, moduleId int64) (int64, error)

New creates a new entry in the specified module table with the given ownerId and moduleId.

func Now

func Now() string

Now returns the current timestamp in the format "2006-01-02 15:04:05".

func Number

func Number(nameValue interface{}) int64

Number converts a value to an int64. It handles various numeric types and attempts to parse a string as an int64. If parsing fails, it returns 0.

func NumbersToCsv

func NumbersToCsv(slice []int64) string

NumbersToCsv converts a slice of int64 numbers into a comma-separated string.

func Open

func Open(engine string, database string, username string, password string, host string, port int) error

Open initializes a connection to the specified database using the provided parameters.

func Owners

func Owners(ownerId int64, moduleId int64) (result []int64)

Owners retrieves a list of user IDs who are owners of the specified module ID and have certain group associations. The function recursively checks group memberships up to a certain depth.

func OwnersCsv

func OwnersCsv(ownerId int64, moduleId int64) string

OwnersCsv retrieves a comma-separated string of user IDs who are owners of the specified module ID and have certain group associations.

func Password

func Password(value string) string

Generate an hashed password

func PermissionAdd

func PermissionAdd(userId int64, moduleId int64, commandName string) int64

PermissionAdd adds a permission for the specified user, module, and command.

func PermissionAddDefault

func PermissionAddDefault(userId int64, moduleId int64) int64

PermissionAddDefault adds default permissions for the specified user and module.

func PermissionCount

func PermissionCount(moduleId int64) int64

PermissionCount returns the count of permissions associated with the specified module.

func Put

func Put(ownerId int64, moduleId int64, ejaId int64, fieldName string, fieldValue string) error

Put updates a specific field in a row of the specified module table based on ownerId, moduleId, ejaId, fieldName, and fieldValue.

func SearchCount

func SearchCount(query string, args []interface{}) int64

SearchCount calculates the number of records for a given search query and arguments.

func SearchLinks(ownerId int64, srcModuleId int64, srcFieldId int64, dstModuleId int64) []string

SearchLinks searches for links associated with a specified module, field, and owner ID.

func SearchQuery

func SearchQuery(ownerId int64, tableName string, values map[string]string) (string, []interface{}, error)

SearchQuery generates a SQL query for searching records in a specified table based on provided criteria.

func SearchQueryLinks(ownerId, srcModuleId, srcFieldId, dstModuleId int64) string

SearchQueryLinks generates a condition for searching based on related links.

func SearchQueryOrderAndLimit

func SearchQueryOrderAndLimit(order string, limit int64, offset int64) string

SearchQueryOrderAndLimit generates an ORDER BY, LIMIT, and OFFSET clause for search queries.

func SessionCleanLink(userId int64) error

SessionCleanLink removes specific session variables related to links for a specified user.

func SessionCleanSearch

func SessionCleanSearch(userId int64) error

SessionCleanSearch removes specific session variables related to searches for a specified user.

func SessionInit

func SessionInit(userId int64) string

SessionInit generates a new session for the specified user and updates the database.

func SessionPut

func SessionPut(userId int64, name string, value string, subName ...string) (err error)

SessionPut stores a session variable for a specified user in the database.

func SessionReset

func SessionReset(userId int64) error

SessionReset removes all session variables for a specified user from the database.

func Setup

func Setup(setupPath string) error

Setup initializes the database with modules, fields, and commands. It reads JSON files from the specified setupPath or embeded assets, and populates the database accordingly. The admin user credentials are used for setup.

func SetupAdmin

func SetupAdmin(setupUser string, setupPass string) error

func Sha256

func Sha256(value string) string

Sha256 generates the SHA256 hash of a given string value.

func String

func String(nameValue interface{}) string

String converts a value to a string. It handles various types, including string, int, int64, float32, float64, and []uint8.

func TableAdd

func TableAdd(name string, tmp ...bool) error

TableAdd creates a new table with the specified name in the database. If the table already exists, it does nothing. The optional 'tmp' parameter specifies whether the table is temporary.

func TableDel

func TableDel(name string) error

TableDel deletes the table with the specified name from the database. If the table does not exist, it returns an error.

func TableExists

func TableExists(name string) (bool, error)

TableExists checks if a table with the specified name exists in the database.

func TableNameIsValid

func TableNameIsValid(name string) error

TableNameIsValid checks if a table name is valid according to the current database engine's conventions.

func Translate

func Translate(value string, user ...int64) string

Translate retrieves the translation for the specified word based on the current session's language and module context. If a translation is not found, it returns a placeholder string indicating that the translation is missing.

func UserGroupCsv

func UserGroupCsv(userId int64) string

UserGroupCsv returns a comma-separated string of group IDs associated with a user.

func UserGroupList

func UserGroupList(userId int64) []int64

UserGroupList retrieves the list of group IDs associated with a user.

func UserPermissionCopy

func UserPermissionCopy(userId int64, moduleId int64)

UserPermissionCopy copies user permissions from one module to another.

func Value

func Value(query string, args ...interface{}) (result string, err error)

Value executes a query with optional parameters and returns a single result as a string.

Types

type TypeCommand

type TypeCommand struct {
	Name   string
	Label  string
	Linker bool
}

TypeCommand represents a command with its properties.

func Commands

func Commands(userId int64, moduleId int64, actionType string) ([]TypeCommand, error)

Commands retrieves a list of commands based on user and module information. It checks permissions and builds the command list accordingly.

type TypeField

type TypeField struct {
	Type    string
	Name    string
	Label   string
	Value   string
	Options []TypeSelect
}

TypeField represents a field in a database with metadata.

func Fields

func Fields(ownerId int64, moduleId int64, actionType string, values map[string]string) ([]TypeField, error)

Fields retrieves a list of TypeField objects based on the provided module ID, action type, and field values.

type TypeLink struct {
	Label       string `json:"Label,omitempty"`
	ModuleId    int64  `json:"ModuleId,omitempty"`
	ModuleLabel string `json:"ModuleLabel,omitempty"`
	FieldId     int64  `json:"FieldId,omitempty"`
}

TypeLink represents a link between modules and fields.

func ModuleLinks(ownerId int64, moduleId int64) (result []TypeLink)

ModuleLinks retrieves a list of links associated with a specified module.

type TypeModule

type TypeModule struct {
	Module      TypeModuleModule         `json:"module"`
	Command     []string                 `json:"command"`
	Field       []TypeModuleField        `json:"field"`
	Translation []TypeModuleTranslation  `json:"translation"`
	Name        string                   `json:"name"`
	Data        []map[string]interface{} `json:"data"`
}

TypeModule represents a modular structure containing information about modules, fields, translations, and data.

func ModuleExport

func ModuleExport(moduleId int64, data bool) (module TypeModule, err error)

ModuleExport exports a module.

type TypeModuleField

type TypeModuleField struct {
	Value       string `json:"value"`
	PowerEdit   int64  `json:"powerEdit"`
	PowerList   int64  `json:"powerList"`
	Type        string `json:"type"`
	Translate   int64  `json:"translate"`
	PowerSearch int64  `json:"powerSearch"`
	Name        string `json:"name"`
}

TypeModuleField represents metadata about a field within a TypeModule.

type TypeModuleModule

type TypeModuleModule struct {
	ParentName  string `json:"parentName,omitempty"`
	Power       int64  `json:"power"`
	SearchLimit int64  `json:"searchLimit"`
	SqlCreated  int64  `json:"sqlCreated"`
	SortList    string `json:"sortList,omitempty"`
}

TypeModuleModule represents metadata about a module within a TypeModule.

type TypeModulePath

type TypeModulePath struct {
	Id    int64
	Name  string
	Label string
}

TypeModulePath represents a node in the module hierarchy with its ID, name, and translated label.

func ModulePath

func ModulePath(ownerId int64, moduleId int64) (result []TypeModulePath)

ModulePath retrieves the path of module hierarchy from the specified module to its root for a given user.

type TypeModuleTranslation

type TypeModuleTranslation struct {
	EjaLanguage   string `json:"ejaLanguage"`
	EjaModuleName string `json:"ejaModuleName,omitempty"`
	Word          string `json:"word"`
	Translation   string `json:"translation"`
}

TypeModuleTranslation represents translation information within a TypeModule.

type TypeModuleTree

type TypeModuleTree struct {
	Id    int64
	Name  string
	Label string
}

TypeModuleTree represents a node in the module tree.

func ModuleTree

func ModuleTree(ownerId int64, moduleId int64, modulePath []TypeModulePath) (result []TypeModuleTree)

ModuleTree generates a tree structure of modules accessible to a user based on permissions and ownership.

type TypeRow

type TypeRow map[string]string

TypeRow is a map representing a single row of data in the database.

func Get

func Get(ownerId int64, moduleId int64, ejaId int64) (TypeRow, error)

Get retrieves a row from the specified module table based on ownerId, moduleId, and ejaId.

func Row

func Row(query string, args ...interface{}) (result TypeRow, err error)

Row executes a query with optional parameters and returns a single row of results as a TypeRow.

func TableGetAllById

func TableGetAllById(tableName string, ejaId int64) TypeRow

TableGetAllById retrieves a row from the specified table based on the ejaId field.

func UserGetAllById

func UserGetAllById(userId int64) TypeRow

UserGetAllById retrieves all user information based on the provided user ID.

func UserGetAllBySession

func UserGetAllBySession(session string) TypeRow

UserGetAllBySession retrieves user information based on the provided session.

func UserGetAllByUserAndPass

func UserGetAllByUserAndPass(username string, password string) TypeRow

UserGetAllByUserAndPass retrieves user information based on the provided username and hashed password.

type TypeRows

type TypeRows []map[string]string

TypeRows is a slice of maps representing multiple rows of data in the database.

func Rows

func Rows(query string, args ...interface{}) (result TypeRows, err error)

Rows executes a query with optional parameters and returns multiple rows of results as a TypeRows.

func SearchMatrix

func SearchMatrix(ownerId int64, moduleId int64, query string, queryArgs []interface{}) (resultRows TypeRows, resultCols []string, resultLabels map[string]string, err error)

SearchMatrix performs a search on a specified database module using a dynamic SQL query.

func SessionLoad

func SessionLoad(userId int64, moduleId int64) (TypeRows, error)

SessionLoad loads session data for a specified user and module from the database.

type TypeRun

type TypeRun struct {
	Changes int64
	LastId  int64
}

TypeRun represents the result of a database operation, including the number of changes and the last inserted ID.

func LinkCopy

func LinkCopy(userId int64, dstFieldNew int64, dstModule int64, dstFieldOriginal int64) (TypeRun, error)

LinkCopy duplicates a link from the original field to a new field in a different module.

func Run

func Run(query string, args ...interface{}) (result TypeRun, err error)

Run executes a query with optional parameters and returns a TypeRun containing information about the execution.

type TypeSearchColumn

type TypeSearchColumn map[string]map[string]interface{}

TypeSearchColumn represents a mapping of column names to their properties and values.

type TypeSelect

type TypeSelect struct {
	Key   string
	Value string
}

TypeSelect represents a key-value pair used for dropdowns or selection lists.

func SelectSqlToRows

func SelectSqlToRows(query string) []TypeSelect

SelectSqlToRows executes a SQL query and converts the result into a slice of TypeSelect structures.

func SelectToRows

func SelectToRows(value string) []TypeSelect

SelectToRows converts a pipe-separated or newline-separated string into a slice of TypeSelect structures.

Jump to

Keyboard shortcuts

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