Example #1
0
File: insert.go Project: 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
}
Example #2
0
File: select.go Project: upper/db
func (qs *selector) From(tables ...interface{}) Selector {
	f, args, err := columnFragments(qs.builder.t, tables)
	if err != nil {
		qs.setErr(err)
		return qs
	}
	c := exql.JoinColumns(f...)

	qs.mu.Lock()
	qs.table = c
	qs.tableArgs = args
	qs.mu.Unlock()

	return qs
}
Example #3
0
File: select.go Project: upper/db
func (qs *selector) Columns(columns ...interface{}) Selector {
	f, args, err := columnFragments(qs.builder.t, columns)
	if err != nil {
		qs.setErr(err)
		return qs
	}

	c := exql.JoinColumns(f...)

	qs.mu.Lock()
	if qs.columns != nil {
		qs.columns.Append(c)
	} else {
		qs.columns = c
	}
	qs.columnsArgs = append(qs.columnsArgs, args...)
	qs.mu.Unlock()

	return qs
}