github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/postgresql/helpers.go (about)

     1  package postgresql
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  )
     7  
     8  // pqQuoteLiteral returns a string literal safe for inclusion in a PostgreSQL
     9  // query as a parameter.  The resulting string still needs to be wrapped in
    10  // single quotes in SQL (i.e. fmt.Sprintf(`'%s'`, pqQuoteLiteral("str"))).  See
    11  // quote_literal_internal() in postgresql/backend/utils/adt/quote.c:77.
    12  func pqQuoteLiteral(in string) string {
    13  	in = strings.Replace(in, `\`, `\\`, -1)
    14  	in = strings.Replace(in, `'`, `''`, -1)
    15  	return in
    16  }
    17  
    18  func validateConnLimit(v interface{}, key string) (warnings []string, errors []error) {
    19  	value := v.(int)
    20  	if value < -1 {
    21  		errors = append(errors, fmt.Errorf("%s can not be less than -1", key))
    22  	}
    23  	return
    24  }