Exemple #1
0
// NewUpdate builds an update from the Model and Fields
func NewUpdate(s Session, m Model, fields field.Names) *dbr.UpdateBuilder {
	if fields == nil {
		fields = ModelFields(m)
	}
	fields = fields.Remove(m.PrimaryKey().Fields())
	setMap := defaultUpdate(m, fields)
	return s.Update(ModelTableName(s, m)).SetMap(setMap)
}
Exemple #2
0
// NewInsert create an insert from the Model and Fields
func NewInsert(s Session, m Model, fields field.Names) *dbr.InsertBuilder {
	if fields == nil {
		fields = ModelFields(m)
	}
	pk := m.PrimaryKey()
	fields = fields.Remove(pk.Fields())
	// TODO do not eat this error
	setFields, _ := pk.Generator(m)
	fields = fields.Add(setFields)
	return s.InsertInto(ModelTableName(s, m)).Columns(fields.SnakeCase()...)
}