Example #1
0
func cacheSqlLogicalDelete(tInfo *TableInformation) string {
	sql := ""

	if tInfo.DeleteTable == false {
		return sql
	}

	sql = string551.Join(sql, "INSERT INTO `"+tInfo.TableName+"_delete` ")
	sql = string551.Join(sql, "(")
	for i := 0; i < len(tInfo.Fields); i++ {
		if i == 0 {
			sql = string551.Join(sql, "`"+tInfo.Fields[i]+"`")
		} else {
			sql = string551.Join(sql, ", `"+tInfo.Fields[i]+"`")
		}
	}
	sql = string551.Join(sql, ", `"+tInfo.DeletedAtField+"`) VALUES (")
	for i := 0; i < len(tInfo.Fields); i++ {
		if i == 0 {
			sql = string551.Join(sql, "?")
		} else {
			sql = string551.Join(sql, ", ?")
		}
	}
	sql = string551.Join(sql, ", ?)")

	return sql
}
Example #2
0
func cacheSqlInsert(tInfo *TableInformation) string {
	sql := ""
	var append int = 0

	sql = string551.Join(sql, "INSERT INTO `"+tInfo.TableName+"` ")
	sql = string551.Join(sql, "(")
	for i := 0; i < len(tInfo.Fields); i++ {
		if tInfo.Fields[i] == tInfo.PrimaryKey {
			continue
		}
		if append == 0 {
			sql = string551.Join(sql, "`"+tInfo.Fields[i]+"`")
		} else {
			sql = string551.Join(sql, ", `"+tInfo.Fields[i]+"`")
		}
		append++
	}

	append = 0
	sql = string551.Join(sql, ") VALUES (")
	for i := 0; i < len(tInfo.Fields); i++ {
		if tInfo.Fields[i] == tInfo.PrimaryKey {
			continue
		}
		if append == 0 {
			sql = string551.Join(sql, "?")
		} else {
			sql = string551.Join(sql, ", ?")
		}
		append++
	}
	sql = string551.Join(sql, ")")

	return sql
}
Example #3
0
func cacheSqlSelect(tInfo *TableInformation) string {
	sql := ""

	sql = string551.Join(sql, "SELECT ")
	for i := 0; i < len(tInfo.Fields); i++ {
		if i == 0 {
			sql = string551.Join(sql, "`"+tInfo.Fields[i]+"`")
		} else {
			sql = string551.Join(sql, ", `"+tInfo.Fields[i]+"`")
		}
	}
	sql = string551.Join(sql, " FROM `"+tInfo.TableName+"` WHERE 1 = 1")

	return sql
}
Example #4
0
func (r *Repository) FindOneBy(db *mysql551.Mysql, mInfo *model551.ModelInformation, param map[string]interface{}) interface{} {

	sql := mInfo.SqlInformation.Select
	var values []interface{}
	for key, value := range param {
		sql = string551.Join(sql, " AND `"+key+"` = ?")
		values = append(values, value)
	}

	rows := db.Query(sql, values...)
	defer rows.Close()

	var model interface{} = nil

	for rows.Next() {
		if model != nil {
			panic(errors.New("Extraction result there is more than one."))
		}
		model = mInfo.NewFuncPointer()
		modelScan, ok := model.(model551.ScanInterface)
		if !ok {
			panic(errors.New("Not found: 'T.Scan(rows *sql.rows) error' method"))
		}

		err := modelScan.Scan(rows)
		if err != nil {
			panic(err)
		}

	}

	return model

}
Example #5
0
func cacheSqlDelete(tInfo *TableInformation) string {
	sql := ""

	sql = string551.Join(sql, "DELETE FROM `"+tInfo.TableName+"` WHERE `"+tInfo.PrimaryKey+"` = ?")

	return sql
}
Example #6
0
func cacheSqlUpdate(tInfo *TableInformation) string {
	sql := ""
	var append int = 0

	sql = string551.Join(sql, "UPDATE `"+tInfo.TableName+"` SET ")
	for i := 0; i < len(tInfo.Fields); i++ {
		if tInfo.Fields[i] == tInfo.PrimaryKey {
			continue
		}
		if append == 0 {
			sql = string551.Join(sql, "`"+tInfo.Fields[i]+"` = ?")
		} else {
			sql = string551.Join(sql, ", `"+tInfo.Fields[i]+"` = ?")
		}
		append++
	}
	sql = string551.Join(sql, " WHERE `"+tInfo.PrimaryKey+"` = ?")

	return sql
}