Documentation ¶
Overview ¶
Package strmangle is a collection of string manipulation functions. Primarily used by boil and templates for code generation. Because it is focused on pipelining inside templates you will see some odd parameter ordering.
Index ¶
- func CamelCase(name string) string
- func ContainsAny(a []string, finds ...string) bool
- func GenerateIgnoreTags(tags []string) string
- func GenerateTags(tags []string, columnName string) string
- func GetBuffer() *bytes.Buffer
- func IdentQuote(lq byte, rq byte, s string) string
- func IdentQuoteSlice(lq byte, rq byte, s []string) []string
- func Identifier(in int) string
- func InsertColumnSet(cols, defaults, noDefaults, nonZeroDefaults, whitelist []string) ([]string, []string)
- func IsEnumNormal(values []string) bool
- func JoinSlices(sep string, a, b []string) []string
- func MakeStringMap(types map[string]string) string
- func ParseEnumName(s string) string
- func ParseEnumVals(s string) []string
- func Placeholders(indexPlaceholders bool, count int, start int, group int) string
- func Plural(name string) string
- func PrefixStringSlice(str string, strs []string) []string
- func PutBuffer(buf *bytes.Buffer)
- func QuoteCharacter(q byte) string
- func ReplaceReservedWords(word string) string
- func SchemaTable(lq, rq string, driver string, schema string, table string) string
- func SetComplement(a []string, b []string) []string
- func SetInclude(str string, slice []string) bool
- func SetMerge(a []string, b []string) []string
- func SetParamNames(lq, rq string, start int, columns []string) string
- func ShouldTitleCaseEnum(value string) bool
- func Singular(name string) string
- func SortByKeys(keys []string, strs []string) []string
- func StringMap(modifier func(string) string, strs []string) []string
- func StringSliceMatch(a []string, b []string) bool
- func TitleCase(n string) string
- func TitleCaseIdentifier(id string) string
- func UpdateColumnSet(allColumns, pkeyCols, whitelist []string) []string
- func WhereClause(lq, rq string, start int, cols []string) string
- func WhereClauseRepeated(lq, rq string, start int, cols []string, count int) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CamelCase ¶
CamelCase takes a variable name in the format of "var_name" and converts it into a go styled variable name of "varName". camelCase also fully uppercases "ID" components of names, for example "var_name_id" to "varNameID".
func ContainsAny ¶
ContainsAny returns true if any of the passed in strings are found in the passed in string slice
func GenerateIgnoreTags ¶
GenerateIgnoreTags converts a slice of tag strings into ignore tags that can be passed onto the end of a struct, for example: tags: ["xml", "db"] convert to: xml:"-" db:"-"
func GenerateTags ¶
GenerateTags converts a slice of tag strings into tags that can be passed onto the end of a struct, for example: tags: ["xml", "db"] convert to: xml:"column_name" db:"column_name"
func IdentQuote ¶
IdentQuote attempts to quote simple identifiers in SQL tatements
func IdentQuoteSlice ¶
IdentQuoteSlice applies IdentQuote to a slice.
func Identifier ¶
Identifier is a base conversion from Base 10 integers to Base 26 integers that are represented by an alphabet from a-z See tests for example outputs.
func InsertColumnSet ¶
func InsertColumnSet(cols, defaults, noDefaults, nonZeroDefaults, whitelist []string) ([]string, []string)
InsertColumnSet generates the set of columns to insert and return for an insert statement the return columns are used to get values that are assigned within the database during the insert to keep the struct in sync with what's in the db. with a whitelist: - the whitelist is used for the insert columns - the return columns are the result of (columns with default values - the whitelist) without a whitelist: - start with columns without a default as these always need to be inserted - add all columns that have a default in the database but that are non-zero in the struct - the return columns are the result of (columns with default values - the previous set)
func IsEnumNormal ¶
IsEnumNormal checks a set of eval values to see if they're "normal"
func JoinSlices ¶
JoinSlices merges two string slices of equal length
func MakeStringMap ¶
MakeStringMap converts a map[string]string into the format: "key": "value", "key": "value"
func ParseEnumName ¶
ParseEnumName returns the name portion of an enum if it exists
Postgres and MySQL drivers return different values psql: enum.enum_name('values'...) mysql: enum('values'...) In the case of mysql, the name will never return anything
func ParseEnumVals ¶
ParseEnumVals returns the values from an enum string
Postgres and MySQL drivers return different values psql: enum.enum_name('values'...) mysql: enum('values'...)
func Placeholders ¶
Placeholders generates the SQL statement placeholders for in queries. For example, ($1,$2,$3),($4,$5,$6) etc. It will start counting placeholders at "start". If indexPlaceholders is false, it will convert to ? instead of $1 etc.
func PrefixStringSlice ¶
PrefixStringSlice with the given str.
func QuoteCharacter ¶
QuoteCharacter returns a string that allows the quote character to be embedded into a Go string that uses double quotes:
func ReplaceReservedWords ¶
ReplaceReservedWords takes a word and replaces it with word_ if it's found in the list of reserved words.
func SchemaTable ¶
SchemaTable returns a table name with a schema prefixed if using a database that supports real schemas, for example, for Postgres: "schema_name"."table_name", for MS SQL: [schema_name].[table_name], versus simply "table_name" for MySQL (because it does not support real schemas)
func SetComplement ¶
SetComplement subtracts the elements in b from a
func SetInclude ¶
SetInclude checks to see if the string is found in the string slice
func SetParamNames ¶
SetParamNames takes a slice of columns and returns a comma separated list of parameter names for a template statement SET clause. eg: "col1"=$1, "col2"=$2, "col3"=$3
func ShouldTitleCaseEnum ¶
ShouldTitleCaseEnum checks a value to see if it's title-case-able
func SortByKeys ¶
SortByKeys returns a new ordered slice based on the keys ordering
func StringSliceMatch ¶
StringSliceMatch returns true if the length of both slices is the same, and the elements of both slices are the same. The elements can be in any order.
func TitleCase ¶
TitleCase changes a snake-case variable name into a go styled object variable name of "ColumnName". titleCase also fully uppercases "ID" components of names, for example "column_name_id" to "ColumnNameID".
Note: This method is ugly because it has been highly optimized, we found that it was a fairly large bottleneck when we were using regexp.
func TitleCaseIdentifier ¶
TitleCaseIdentifier splits on dots and then titlecases each fragment. map titleCase (split c ".")
func UpdateColumnSet ¶
UpdateColumnSet generates the set of columns to update for an update statement. if a whitelist is supplied, it's returned if a whitelist is missing then we begin with all columns then we remove the primary key columns
func WhereClause ¶
WhereClause returns the where clause using start as the $ flag index For example, if start was 2 output would be: "colthing=$2 AND colstuff=$3"
func WhereClauseRepeated ¶
WhereClauseRepeated returns the where clause repeated with OR clause using start as the $ flag index For example, if start was 2 output would be: "(colthing=$2 AND colstuff=$3) OR (colthing=$4 AND colstuff=$5)"
Types ¶
This section is empty.