Exemple #1
0
func (r *Repository) Delete(db *mysql551.Mysql, mInfo *model551.ModelInformation, model interface{}) {

	// Delete
	sql := mInfo.SqlInformation.Delete
	idModel, ok := model.(model551.PrimaryInterface)
	if !ok {
		panic(errors.New("Not found: 'T.SetId(int64)', 'T.Id() int64' method"))
	}
	db.Exec(sql, idModel.GetId())

	if !mInfo.TableInformation.DeleteTable {
		return
	}

	// Logical Delete( Insert into delete table.)
	sql = mInfo.SqlInformation.LogicalDelete
	sqlValueModel, ok := model.(model551.ValuesInterface)
	if !ok {
		panic(errors.New("Not found: 'T.SqlValues(sqlType SqlType) []interface{}' method"))
	}
	param := sqlValueModel.SqlValues(model551.SQL_LOGICAL_DELETE)

	db.Exec(sql, param...)

}
Exemple #2
0
func (r *Repository) Update(db *mysql551.Mysql, mInfo *model551.ModelInformation, model interface{}) interface{} {

	sql := mInfo.SqlInformation.Update
	if iUpdate, ok := model.(model551.SqlUpdateInterface); ok {
		sql = iUpdate.SqlUpdate()
	}

	sqlValueModel, ok := model.(model551.ValuesInterface)
	if !ok {
		panic(errors.New("Not found: 'T.SqlValues(sqlType SqlType) []interface{}' method"))
	}
	param := sqlValueModel.SqlValues(model551.SQL_UPDATE)

	db.Exec(sql, param...)

	return model
}
Exemple #3
0
func (r *Repository) Create(db *mysql551.Mysql, mInfo *model551.ModelInformation, model interface{}) interface{} {

	sql := mInfo.SqlInformation.Insert
	if iInsert, ok := model.(model551.SqlInsertInterface); ok {
		sql = iInsert.SqlInsert()
	}

	sqlValueModel, ok := model.(model551.ValuesInterface)
	if !ok {
		panic(errors.New("Not found: 'T.SqlValues(sqlType SqlType) []interface{}' method"))
	}
	param := sqlValueModel.SqlValues(model551.SQL_INSERT)

	_, lastInsertId := db.Exec(sql, param...)

	idModel, ok := model.(model551.PrimaryInterface)
	if !ok {
		panic(errors.New("Not found: 'T.SetId(int64)', 'T.Id() int64' method"))
	}

	idModel.SetId(lastInsertId)

	return model
}