utility

package
v0.0.0-...-dc7d88a Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2022 License: GPL-3.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildInsertStatement

func BuildInsertStatement(tableName string, columnValues map[string]interface{}) (string, []interface{})

BuildInsertStatement is a helper function that builds an SQL INSERT statement dynamically.

func BuildUpdateStatement

func BuildUpdateStatement(tableName string, columnValues map[string]interface{},
	whereColumn string, whereValue interface{}) (string, []interface{})

BuildUpdateStatement is a helper function that builds an SQL UPDATE statement dynamically.

func GetString

func GetString(v interface{}, path string) string

GetString lets you specify a path to the value that you want (e.g. "aaa.bbb.ccc") and have it extracted from the data structure.

func IsEqualJSON

func IsEqualJSON(s1, s2 string) (bool, error)

IsEqualJSON returns true if the 2 supplied strings contain JSON data that is semantically equal.

func RandomStringID

func RandomStringID() string

RandomStringID returns a string of 32 characters, Each character is from the set [A-Za-z0-9].

func RemoveDuplicateStrings

func RemoveDuplicateStrings(array []string) []string

RemoveDuplicateStrings returns a new slice with the unique strings from the original array, i.e. duplicate elements have been removed.

func RunInTransaction

func RunInTransaction(db *sql.DB, txFunc func(*sql.Tx) error) (err error)

RunInTransaction runs the given function inside a database transaction. Does rollback if the function returns an error or panics. Otherwise, does commit.

func RunStatementsInTransaction

func RunStatementsInTransaction(db *sql.DB, statements []string, args ...interface{}) error

RunStatementsInTransaction runs all the given statements inside a database transaction. If a statement fails, the transaction is rolled back. That way either all of them take effect or none of them do.

Types

This section is empty.

Jump to

Keyboard shortcuts

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