Documentation ¶
Overview ¶
Package sqlutil provides SQL utility functions. It includes functions for quoting identifiers and values in SQL queries.
Index ¶
- type Option
- type SQLQuoteFunc
- type SQLUtil
- func (c *SQLUtil) BuildInClauseInt(field string, values []int) string
- func (c *SQLUtil) BuildInClauseString(field string, values []string) string
- func (c *SQLUtil) BuildInClauseUint(field string, values []uint64) string
- func (c *SQLUtil) BuildNotInClauseInt(field string, values []int) string
- func (c *SQLUtil) BuildNotInClauseString(field string, values []string) string
- func (c *SQLUtil) BuildNotInClauseUint(field string, values []uint64) string
- func (c *SQLUtil) QuoteID(s string) string
- func (c *SQLUtil) QuoteValue(s string) string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*SQLUtil)
Option is a type alias for a function that configures the DB connector.
func WithQuoteIDFunc ¶
func WithQuoteIDFunc(fn SQLQuoteFunc) Option
WithQuoteIDFunc replaces the default QuoteID function.
Example ¶
package main import ( "fmt" "log" "github.com/Vonage/gosrvlib/pkg/sqlutil" ) func main() { // define custom quote function fn := func(s string) string { return "TEST-" + s } q, err := sqlutil.New( sqlutil.WithQuoteIDFunc(fn), ) if err != nil { log.Fatal(err) } o := q.QuoteID("6971") fmt.Println(o) }
Output: TEST-6971
func WithQuoteValueFunc ¶
func WithQuoteValueFunc(fn SQLQuoteFunc) Option
WithQuoteValueFunc replaces the default QuoteValue function.
Example ¶
package main import ( "fmt" "log" "github.com/Vonage/gosrvlib/pkg/sqlutil" ) func main() { // define custom quote function fn := func(s string) string { return "TEST-" + s } q, err := sqlutil.New( sqlutil.WithQuoteValueFunc(fn), ) if err != nil { log.Fatal(err) } o := q.QuoteValue("4987") fmt.Println(o) }
Output: TEST-4987
type SQLQuoteFunc ¶
SQLQuoteFunc is the type of function called to quote a string (ID or value).
type SQLUtil ¶
type SQLUtil struct {
// contains filtered or unexported fields
}
SQLUtil is the structure that helps to manage a SQL DB connection.
func (*SQLUtil) BuildInClauseInt ¶
BuildInClauseInt prepares a SQL IN clause with the given list of integer values.
func (*SQLUtil) BuildInClauseString ¶
BuildInClauseString prepares a SQL IN clause with the given list of string values.
func (*SQLUtil) BuildInClauseUint ¶
BuildInClauseUint prepares a SQL IN clause with the given list of integer values.
func (*SQLUtil) BuildNotInClauseInt ¶
BuildNotInClauseInt prepares a SQL NOT IN clause with the given list of integer values.
func (*SQLUtil) BuildNotInClauseString ¶
BuildNotInClauseString prepares a SQL NOT IN clause with the given list of string values.
func (*SQLUtil) BuildNotInClauseUint ¶
BuildNotInClauseUint prepares a SQL NOT IN clause with the given list of integer values.
func (*SQLUtil) QuoteID ¶
QuoteID quotes identifiers such as schema, table, or column names.
Example ¶
package main import ( "fmt" "log" "github.com/Vonage/gosrvlib/pkg/sqlutil" ) func main() { q, err := sqlutil.New() if err != nil { log.Fatal(err) } o := q.QuoteID("7919") fmt.Println(o) }
Output: `7919`
func (*SQLUtil) QuoteValue ¶
QuoteValue quotes database string values. The returned value will include all surrounding quotes.
Example ¶
package main import ( "fmt" "log" "github.com/Vonage/gosrvlib/pkg/sqlutil" ) func main() { q, err := sqlutil.New() if err != nil { log.Fatal(err) } o := q.QuoteValue("5867") fmt.Println(o) }
Output: '5867'