libQuery

package
v0.10.17 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	APP                      = "request.APP"
	USER                     = "request.USER"
	MODULE                   = "request.MODULE"
	METHOD                   = "request.METHOD"
	SetCommandError          = "error in Dml->SetTrxVariable(%s,%s,%s)"
	ErrorExecuteDML          = "ERROR_EXECUTE_DML"
	OracleSetVariableCommand = `--sql
		BEGIN 
			CARD_ISSUE.AUDIT_TRAIL.SET_MODIF_ARGS(:1, :2);
		END;`
	PostgresSetVariableCommand = "SELECT set_config($1,$2,true);"
)
View Source
const (
	PREPARE_ERROR = -1
	QUERY_ERROR   = -2
	PARSE_ERROR   = -3
	SCAN_ERROR    = -4
)
View Source
const (
	NO_DATA_FOUND        = "NO_DATA_FOUND"
	NO_DATA_FOUND_DESC   = "رکوردی یافت نشد"
	DUPLICATE_FOUND      = "DUPLICATE_FOUND"
	DUPLICATE_FOUND_DESC = "رکورد تکراری است"
	DB_READ_ERROR        = "DB_READ_ERROR"
	PARSE_DB_RESP_ERROR  = "PARSE_DB_RESP_ERROR"
)
View Source
const (
	ERROR_CALLING_DB_FUNCTION = "ERROR_CALLING_DB_FUNCTION"
)

Variables

This section is empty.

Functions

func CallSql

func CallSql[R any](query string,
	core QueryRunnerInterface,
	args ...any) (int, string, string, []R, error)

func ConvertJsonToStruct

func ConvertJsonToStruct[Q any](row string) (Q, error)

func DBModeStrings added in v0.6.3

func DBModeStrings() []string

DBModeStrings returns a slice of all String values of the enum

func DmlCommandTypeStrings added in v0.5.0

func DmlCommandTypeStrings() []string

DmlCommandTypeStrings returns a slice of all String values of the enum

func Fill

func Fill[Data any](
	query string,
	core QueryRunnerInterface,
	args ...any,
) ([]Data, string, string, error)

func Filler

func Filler[Data any](
	query string,
	core QueryRunnerInterface,
	args ...any,
) (Data, string, string, error)

func GetDBTagValue added in v0.9.22

func GetDBTagValue(name string, s any) (*string, *string, error)

func GetFormTagValue added in v0.9.22

func GetFormTagValue(name string, s any) (*string, *string, error)

func GetLocalArgs added in v0.9.49

func GetLocalArgs(parser webFramework.RequestParser, args []any) []any

func GetOutArgs added in v0.9.33

func GetOutArgs(parser webFramework.RequestParser, args ...any) map[string]string

func GetQuery added in v0.9.20

func GetQuery[R any](query string, core QueryRunnerInterface, args ...any) ([]R, response.ErrorState)

func GetQueryResp

func GetQueryResp[R any](query string, core QueryRunnerInterface, args ...any) (int, string, string, bool, any, error)

func GetTagValue added in v0.9.22

func GetTagValue(name, tag string, s any) (*string, *string, error)

func HandleCheckDuplicate

func HandleCheckDuplicate(code int, desc, dupDesc string, record []QueryData, err error) (int, string, error)

func HandleCheckExistence added in v0.3.6

func HandleCheckExistence(code int, desc, notExistDesc string, record []QueryData, err error) (int, string, error)

func ParseCommand

func ParseCommand(command, user, app, action, title string, value map[string]string, parser webFramework.FieldParser) string

func ParseQueryResult

func ParseQueryResult(result map[string]any, t reflect.Type, v reflect.Value)

func PrepareArgs added in v0.6.10

func PrepareArgs(args []any) []any

func Query added in v0.5.0

func Query[Result QueryResult](core QueryRunnerInterface, command QueryCommand, args ...any) (any, response.ErrorState)

func QueryCommandTypeStrings added in v0.5.0

func QueryCommandTypeStrings() []string

QueryCommandTypeStrings returns a slice of all String values of the enum

func SerializeArray added in v0.6.10

func SerializeArray(arr []any) string

func SerializeStringArray added in v0.6.10

func SerializeStringArray(arr []string) string

func SetVariable added in v0.6.1

func SetVariable(ctx context.Context, tx *sql.Tx, command, key, value string) error

Types

type ContextKey added in v0.6.1

type ContextKey string

type DBMode added in v0.6.3

type DBMode int
const (
	Oracle DBMode = iota
	Postgres
	MockDB
)

func DBModeString added in v0.6.3

func DBModeString(s string) (DBMode, error)

DBModeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func DBModeValues added in v0.6.3

func DBModeValues() []DBMode

DBModeValues returns all values of the enum

func (DBMode) IsADBMode added in v0.6.3

func (i DBMode) IsADBMode() bool

IsADBMode returns "true" if the value is listed in the enum definition. "false" otherwise

func (DBMode) MarshalJSON added in v0.6.3

func (i DBMode) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for DBMode

func (DBMode) String added in v0.6.3

func (i DBMode) String() string

func (*DBMode) UnmarshalJSON added in v0.6.3

func (i *DBMode) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for DBMode

type DmlCommand added in v0.4.21

type DmlCommand struct {
	Name        string
	Command     string
	Args        []any
	Type        DmlCommandType
	CustomError response.ErrorState
}

func (DmlCommand) Execute added in v0.4.21

func (command DmlCommand) Execute(core QueryRunnerInterface, moduleName, methodName string) (any, response.ErrorState)

func (DmlCommand) ExecuteWithContext added in v0.6.1

func (command DmlCommand) ExecuteWithContext(parser webFramework.RequestParser, ctx context.Context, moduleName, methodName string, core QueryRunnerInterface) (any, response.ErrorState)

type DmlCommandType added in v0.5.0

type DmlCommandType int
const (
	QueryCheckNotExists DmlCommandType = iota
	QueryCheckExists
	Insert
	Update
	Delete
)

func DmlCommandTypeString added in v0.5.0

func DmlCommandTypeString(s string) (DmlCommandType, error)

DmlCommandTypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func DmlCommandTypeValues added in v0.5.0

func DmlCommandTypeValues() []DmlCommandType

DmlCommandTypeValues returns all values of the enum

func (DmlCommandType) IsADmlCommandType added in v0.5.0

func (i DmlCommandType) IsADmlCommandType() bool

IsADmlCommandType returns "true" if the value is listed in the enum definition. "false" otherwise

func (DmlCommandType) MarshalJSON added in v0.5.0

func (i DmlCommandType) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for DmlCommandType

func (DmlCommandType) String added in v0.5.0

func (i DmlCommandType) String() string

func (*DmlCommandType) UnmarshalJSON added in v0.5.0

func (i *DmlCommandType) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for DmlCommandType

type DmlModel added in v0.4.21

type DmlModel interface {
	PreControlCommands() map[string][]DmlCommand
	DmlCommands() map[string][]DmlCommand
	FinalizeCommands() map[string][]DmlCommand
}

type DmlResult

type DmlResult struct {
	Rows         map[string]string `json:"rows" form:"rows"`
	LastInsertId int64             `json:"lastId" form:"lastId"`
	RowsAffected int64             `json:"rowsAffected" form:"rowsAffected"`
}

func GetDmlResult added in v0.8.5

func GetDmlResult(resultDb sql.Result, rows map[string]string) DmlResult

func (*DmlResult) LoadFromMap

func (c *DmlResult) LoadFromMap(m any) error

type QueryCommand added in v0.5.0

type QueryCommand struct {
	Name    string
	Command string
	Type    QueryCommandType
	Args    []string
}

func (QueryCommand) GetDriverArgs added in v0.9.21

func (q QueryCommand) GetDriverArgs(req any) []driver.Value

type QueryCommandType added in v0.5.0

type QueryCommandType int
const (
	QuerySingle QueryCommandType = iota
	QueryAll
	QueryMap
)

func QueryCommandTypeString added in v0.5.0

func QueryCommandTypeString(s string) (QueryCommandType, error)

QueryCommandTypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func QueryCommandTypeValues added in v0.5.0

func QueryCommandTypeValues() []QueryCommandType

QueryCommandTypeValues returns all values of the enum

func (QueryCommandType) IsAQueryCommandType added in v0.5.0

func (i QueryCommandType) IsAQueryCommandType() bool

IsAQueryCommandType returns "true" if the value is listed in the enum definition. "false" otherwise

func (QueryCommandType) MarshalJSON added in v0.5.0

func (i QueryCommandType) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for QueryCommandType

func (QueryCommandType) String added in v0.5.0

func (i QueryCommandType) String() string

func (*QueryCommandType) UnmarshalJSON added in v0.5.0

func (i *QueryCommandType) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for QueryCommandType

type QueryData

type QueryData struct {
	DataRaw    string   `json:"result,omitempty" db:"result"`
	Key        string   `json:"key,omitempty" db:"key"`
	Value      string   `json:"value,omitempty" db:"value"`
	ValueArray []string `json:"valueArray,omitempty" db:"values"`
	MapList    string   `json:"mapList,omitempty" db:"map_list"`
}

type QueryRequest added in v0.5.4

type QueryRequest interface {
	QueryArgs() map[string][]any
}

type QueryResult added in v0.5.0

type QueryResult interface {
	GetID() string
	GetValue() any
}

type QueryRunnerInterface

type QueryRunnerInterface interface {
	QueryRunner(querySql string, args ...any) (int, []map[string]any, error)
	QueryToStruct(querySql string, target any, args ...any) (int, any, error)
	CallDbFunction(callString string, args ...any) (int, string, error)
	GetModule() (string, string)
	InsertRow(insert string, args ...any) (sql.Result, error)
	Dml(ctx context.Context, moduleName, methodName, command string, args ...any) (sql.Result, error)
	SetVariableCommand() string
	//Used in mock db for test
	Close()
}

type QueryRunnerModel

type QueryRunnerModel struct {
	DB          *sql.DB
	ProgramName string
	ModuleName  string
	SetVariable string
	Mode        DBMode
}

func Init added in v0.6.3

func Init(
	DB *sql.DB,
	ProgramName string,
	ModuleName string,
	mode DBMode) QueryRunnerModel

func (QueryRunnerModel) CallDbFunction

func (m QueryRunnerModel) CallDbFunction(callString string, args ...any) (int, string, error)

func (QueryRunnerModel) Close added in v0.9.1

func (m QueryRunnerModel) Close()

func (QueryRunnerModel) Dml added in v0.6.1

func (m QueryRunnerModel) Dml(ctx context.Context, moduleName, methodName, command string, args ...any) (sql.Result, error)

func (QueryRunnerModel) GetModule

func (m QueryRunnerModel) GetModule() (string, string)

func (QueryRunnerModel) InsertRow

func (m QueryRunnerModel) InsertRow(insert string, args ...any) (sql.Result, error)

func (QueryRunnerModel) QueryRunner

func (m QueryRunnerModel) QueryRunner(querySql string, args ...any) (int, []map[string]any, error)

func (QueryRunnerModel) QueryToStruct

func (m QueryRunnerModel) QueryToStruct(querySql string, target any, args ...any) (int, any, error)

func (QueryRunnerModel) SetModifVariables added in v0.6.1

func (m QueryRunnerModel) SetModifVariables(ctx context.Context, moduleName, methodName string, tx *sql.Tx) error

func (QueryRunnerModel) SetVariableCommand added in v0.6.1

func (m QueryRunnerModel) SetVariableCommand() string

type QueryWithDeps

type QueryWithDeps interface {
	GetFillable(core QueryRunnerInterface) (map[string]any, error)
}

type RecordDataDml

type RecordDataDml interface {
	SetId(string)
	CheckDuplicate(core QueryRunnerInterface) (int, string, error)
	Filler(headers map[string][]string, core QueryRunnerInterface, args ...any) (string, error)
	Post(core QueryRunnerInterface, args map[string]string) (DmlResult, int, string, error)
	CheckExistence(core QueryRunnerInterface) (int, string, error)
	PreControl(core QueryRunnerInterface) (int, string, error)
	Put(core QueryRunnerInterface, args map[string]string) (DmlResult, int, string, error)
}

type RecordDataGet

type RecordDataGet interface {
	GetId() string
	GetControlId(string) string
	GetIdList() []any
	GetSubCategory() string
	GetValue() any
}

type Updatable

type Updatable interface {
	SetParams(args map[string]string) any
	GetUniqueId() []any
	GetCountCommand() string
	GetUpdateCommand() (string, []any)
	Finalize(QueryRunnerInterface) (string, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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