...

Source file src/github.com/doug-martin/goqu/v9/goqu.go

Documentation: github.com/doug-martin/goqu/v9

     1  /*
     2  goqu an idiomatch SQL builder, and query package.
     3  
     4        __ _  ___   __ _ _   _
     5       / _` |/ _ \ / _` | | | |
     6      | (_| | (_) | (_| | |_| |
     7       \__, |\___/ \__, |\__,_|
     8       |___/          |_|
     9  
    10  
    11  Please see https://github.com/doug-martin/goqu for an introduction to goqu.
    12  */
    13  package goqu
    14  
    15  import (
    16  	"time"
    17  
    18  	"github.com/doug-martin/goqu/v9/internal/util"
    19  	"github.com/doug-martin/goqu/v9/sqlgen"
    20  )
    21  
    22  type DialectWrapper struct {
    23  	dialect string
    24  }
    25  
    26  // Creates a new DialectWrapper to create goqu.Datasets or goqu.Databases with the specified dialect.
    27  func Dialect(dialect string) DialectWrapper {
    28  	return DialectWrapper{dialect: dialect}
    29  }
    30  
    31  // Create a new dataset for creating SELECT sql statements
    32  func (dw DialectWrapper) From(table ...interface{}) *SelectDataset {
    33  	return From(table...).WithDialect(dw.dialect)
    34  }
    35  
    36  // Create a new dataset for creating SELECT sql statements
    37  func (dw DialectWrapper) Select(cols ...interface{}) *SelectDataset {
    38  	return newDataset(dw.dialect, nil).Select(cols...)
    39  }
    40  
    41  // Create a new dataset for creating UPDATE sql statements
    42  func (dw DialectWrapper) Update(table interface{}) *UpdateDataset {
    43  	return Update(table).WithDialect(dw.dialect)
    44  }
    45  
    46  // Create a new dataset for creating INSERT sql statements
    47  func (dw DialectWrapper) Insert(table interface{}) *InsertDataset {
    48  	return Insert(table).WithDialect(dw.dialect)
    49  }
    50  
    51  // Create a new dataset for creating DELETE sql statements
    52  func (dw DialectWrapper) Delete(table interface{}) *DeleteDataset {
    53  	return Delete(table).WithDialect(dw.dialect)
    54  }
    55  
    56  // Create a new dataset for creating TRUNCATE sql statements
    57  func (dw DialectWrapper) Truncate(table ...interface{}) *TruncateDataset {
    58  	return Truncate(table...).WithDialect(dw.dialect)
    59  }
    60  
    61  func (dw DialectWrapper) DB(db SQLDatabase) *Database {
    62  	return newDatabase(dw.dialect, db)
    63  }
    64  
    65  func New(dialect string, db SQLDatabase) *Database {
    66  	return newDatabase(dialect, db)
    67  }
    68  
    69  // Set the behavior when encountering struct fields that do not have a db tag.
    70  // By default this is false; if set to true any field without a db tag will not
    71  // be targeted by Select or Scan operations.
    72  func SetIgnoreUntaggedFields(ignore bool) {
    73  	util.SetIgnoreUntaggedFields(ignore)
    74  }
    75  
    76  // Set the column rename function. This is used for struct fields that do not have a db tag to specify the column name
    77  // By default all struct fields that do not have a db tag will be converted lowercase
    78  func SetColumnRenameFunction(renameFunc func(string) string) {
    79  	util.SetColumnRenameFunction(renameFunc)
    80  }
    81  
    82  // Set the location to use when interpolating time.Time instances. See https://golang.org/pkg/time/#LoadLocation
    83  // NOTE: This has no effect when using prepared statements.
    84  func SetTimeLocation(loc *time.Location) {
    85  	sqlgen.SetTimeLocation(loc)
    86  }
    87  

View as plain text