github.com/gocaveman/caveman@v0.0.0-20191211162744-0ddf99dbdf6e/ddl/formatter.go (about)

     1  package ddl
     2  
     3  import "strings"
     4  
     5  // Formatter knows how to format a Stmt into one or more SQL strings.
     6  // Most calls to Format() will return a single SQL string, but it is
     7  // also possible that functionality unavailable in a particular database
     8  // will need to be emulated with multiple statements.
     9  type Formatter interface {
    10  	Format(stmt Stmt) ([]string, error) // do formatting on a statement
    11  	DriverName() string                 // get the driver name for this formatter, e.g. "mysql", "sqlite3"
    12  }
    13  
    14  type FormatterList []Formatter
    15  
    16  func quoteIdent(s, quote string) string {
    17  	part := strings.SplitN(s, ".", 2)
    18  	if len(part) == 2 {
    19  		return quoteIdent(part[0], quote) + "." + quoteIdent(part[1], quote)
    20  	}
    21  	return quote + s + quote
    22  }