示例#1
0
文件: insert.go 项目: upper/db
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
}
示例#2
0
文件: collection.go 项目: upper/db
// 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
}
示例#3
0
文件: delete.go 项目: upper/db
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
}
示例#4
0
文件: update.go 项目: upper/db
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
}
示例#5
0
文件: select.go 项目: upper/db
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
}