strmangle

package
v0.0.0-...-cc80eb7 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2024 License: BSD-3-Clause Imports: 7 Imported by: 1

Documentation

Overview

Package strmangle is a collection of string manipulation functions. Primarily used by bunny and templates for code generation. Because it is focused on pipelining inside templates you will see some odd parameter ordering.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CamelCase

func CamelCase(name string) string

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

func ContainsAny(a []string, finds ...string) bool

ContainsAny returns true if any of the passed in strings are found in the passed in string slice

func GenerateIgnoreTags

func GenerateIgnoreTags(tags []string) string

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 GetBuffer

func GetBuffer() *bytes.Buffer

GetBuffer retrieves a buffer from the buffer pool

func IdentQuote

func IdentQuote(lq byte, rq byte, s string) string

IdentQuote attempts to quote simple identifiers in SQL statements

func IdentQuoteSlice

func IdentQuoteSlice(lq byte, rq byte, s []string) []string

IdentQuoteSlice applies IdentQuote to a slice.

func JoinSlices

func JoinSlices(sep string, a, b []string) []string

JoinSlices merges two string slices of equal length

func MakeStringMap

func MakeStringMap(types map[string]string) string

MakeStringMap converts a map[string]string into the format: "key": "value", "key": "value"

func Placeholders

func Placeholders(indexPlaceholders bool, count int, start int, group int) string

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 Plural

func Plural(name string) string

Plural converts singular words to plural words (eg: person to people)

func PrefixStringSlice

func PrefixStringSlice(str string, strs []string) []string

PrefixStringSlice with the given str.

func PutBuffer

func PutBuffer(buf *bytes.Buffer)

PutBuffer back into the buffer pool

func QuoteCharacter

func QuoteCharacter(q byte) string

QuoteCharacter returns a string that allows the quote character to be embedded into a Go string that uses double quotes:

func ReplaceReservedWords

func ReplaceReservedWords(word string) string

ReplaceReservedWords takes a word and replaces it with word_ if it's found in the list of reserved words.

func SchemaModel

func SchemaModel(lq, rq string, model string) string

SchemaModel returns a model name with a schema prefixed if using a database that supports real schemas, for example, for Postgres: "schema_name"."model_name", for MS SQL: [schema_name].[model_name], versus simply "model_name" for MySQL (because it does not support real schemas)

func SetComplement

func SetComplement(a []string, b []string) []string

SetComplement subtracts the elements in b from a

func SetInclude

func SetInclude(str string, slice []string) bool

SetInclude checks to see if the string is found in the string slice

func SetMerge

func SetMerge(a []string, b []string) []string

SetMerge will return a merged slice without duplicates

func SetParamNames

func SetParamNames(lq, rq string, start int, fields []string) string

SetParamNames takes a slice of fields and returns a comma separated list of parameter names for a template statement SET clause. eg: "col1"=$1, "col2"=$2, "col3"=$3

func Singular

func Singular(name string) string

Singular converts plural words to singular words (eg: people to person)

func SortByKeys

func SortByKeys(keys []string, strs []string) []string

SortByKeys returns a new ordered slice based on the keys ordering

func StringMap

func StringMap(modifier func(string) string, strs []string) []string

StringMap maps a function over a slice of strings.

func StringSliceMatch

func StringSliceMatch(a []string, b []string) bool

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

func TitleCase(n string) string

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 "field_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 WhereClause

func WhereClause(lq, rq string, start int, cols []string) string

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

func WhereClauseRepeated(lq, rq string, start int, cols []string, count int) string

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.

Jump to

Keyboard shortcuts

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