func (qi *inserter) statement() *exql.Statement { stmt := &exql.Statement{ Type: exql.Insert, Table: exql.TableWithName(qi.table), } values, arguments := qi.processValues() qi.arguments = arguments if len(qi.columns) > 0 { stmt.Columns = exql.JoinColumns(qi.columns...) } if len(values) > 0 { stmt.Values = exql.JoinValueGroups(values...) } if len(qi.returning) > 0 { stmt.Returning = exql.ReturningColumns(qi.returning...) } stmt.SetAmendment(qi.amendFn) return stmt }
// Truncate deletes all rows from the table. func (c *collection) Truncate() error { stmt := exql.Statement{ Type: exql.Truncate, Table: exql.TableWithName(c.p.Name()), } if _, err := c.p.Database().Exec(&stmt); err != nil { return err } return nil }
func (qd *deleter) statement() *exql.Statement { stmt := &exql.Statement{ Type: exql.Delete, Table: exql.TableWithName(qd.table), } if qd.Where != nil { stmt.Where = qd.where } if qd.limit != 0 { stmt.Limit = exql.Limit(qd.limit) } stmt.SetAmendment(qd.amendFn) return stmt }
func (qu *updater) statement() *exql.Statement { stmt := &exql.Statement{ Type: exql.Update, Table: exql.TableWithName(qu.table), ColumnValues: qu.columnValues, } if qu.Where != nil { stmt.Where = qu.where } if qu.limit != 0 { stmt.Limit = exql.Limit(qu.limit) } stmt.SetAmendment(qu.amendFn) return stmt }
func (qs *selector) pushJoin(t string, tables []interface{}) Selector { tableNames := make([]string, len(tables)) for i := range tables { tableNames[i] = fmt.Sprintf("%s", tables[i]) } qs.mu.Lock() if qs.joins == nil { qs.joins = []*exql.Join{} } qs.joins = append(qs.joins, &exql.Join{ Type: t, Table: exql.TableWithName(strings.Join(tableNames, ", ")), }, ) qs.mu.Unlock() return qs }