예제 #1
0
func TestToken(t *testing.T) {
	tokenTest := &models.Token{"token1", "writeToken", "readToken"}
	var o orm.Ormer = orm.NewOrm()
	result := []orm.ParamsList{}

	Convey("Check save token", t, func() {
		success := tokenTest.Save()
		So(success, ShouldEqual, nil)
	})

	Convey("Check write token", t, func() {

		r, _ := o.Raw("select write_token from token where document_id = ?", tokenTest.DocumentId).ValuesList(&result)
		_ = r
		e := result[0][0]
		So(e, ShouldEqual, tokenTest.WriteToken)
	})

	Convey("Check read token", t, func() {

		r, _ := o.Raw("select read_token from token where document_id = ?", tokenTest.DocumentId).ValuesList(&result)
		_ = r
		e := result[0][0]
		So(e, ShouldEqual, tokenTest.ReadToken)
	})

}
예제 #2
0
파일: utils.go 프로젝트: naokij/gotalk
func NumOfRows(o orm.Ormer, sql string) (int64, error) {
	type tableRows struct {
		Rows int64
	}
	var rows tableRows
	if err := o.Raw(sql).QueryRow(&rows); err != nil {
		return 0, err
	}
	return rows.Rows, nil
}
예제 #3
0
func (c *CSVDataFile) LoadToMySQL(o orm.Ormer) error {
	sql := fmt.Sprintf(`load data infile '%s' into table %s FIELDS TERMINATED BY '%s' ENCLOSED BY '"' (%s)`, c.File, c.Table, string(c.FieldsTerminatedBy), strings.Join(c.Fields, ", "))
	//fmt.Println(sql)
	_, err := o.Raw(sql).Exec()
	if err != nil {
		c.hasImportError = true
		return fmt.Errorf("datafile %s: %s", c.File, err.Error())
	}
	return nil
}
예제 #4
0
파일: dao_test.go 프로젝트: vmware/harbor
func execUpdate(o orm.Ormer, sql string, params ...interface{}) error {
	p, err := o.Raw(sql).Prepare()
	if err != nil {
		return err
	}
	defer p.Close()
	_, err = p.Exec(params...)
	if err != nil {
		return err
	}
	return nil
}
예제 #5
0
파일: utils.go 프로젝트: naokij/gotalk
func RunPreImportMySQLSettings(o orm.Ormer) {
	const sql = `/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;`
	var cmds = strings.Split(sql, "\n")
	for _, cmd := range cmds {
		if _, err := o.Raw(cmd).Exec(); err != nil {
			fmt.Println("PreImportSettings: ", err)
		}
	}
}
예제 #6
0
파일: utils.go 프로젝트: naokij/gotalk
func Map2InsertSql(o orm.Ormer, table string, data map[string]interface{}) error {
	var values []interface{}
	var keys []string
	var valuesPlaceHolders []string
	for k, v := range data {
		valuesPlaceHolders = append(valuesPlaceHolders, "? ")
		keys = append(keys, fmt.Sprintf("`%s`", k))
		values = append(values, v) //
	}
	sql := fmt.Sprintf("INSERT INTO `%s` (%s) VALUES(%s)", table, strings.Join(keys, ","), strings.Join(valuesPlaceHolders, ","))
	_, err := o.Raw(sql, values...).Exec()
	if err != nil {
		return err
	}
	return nil
}
예제 #7
0
func TestCreateDoc(t *testing.T) {
	var o orm.Ormer = orm.NewOrm()
	docNew := &models.Documents{"testid", "test_content", "D", "test@gmail"}
	// Only pass t into top-level Convey calls
	err := docNew.Save()
	if err == nil {
		fmt.Println("***************************************")
	}
	Convey("Test Create Doc in database", t, func() {
		var lists []orm.ParamsList

		num, _ := o.Raw(" select Id from documents where id = ?", "testid").ValuesList(&lists)

		num = num + 1
		So(lists[0][0], ShouldEqual, "testid")
	})
}
예제 #8
0
func insertEvent(q orm.Ormer, eve *coommonModel.Event) (res interface{}, err error) {
	var status int
	if status = 0; eve.Status == "OK" {
		status = 1
	}
	sqltemplete := `INSERT INTO events (
		event_caseId,
		step,
		cond,
		status,
		timestamp
	) VALUES(?,?,?,?,?)`
	res, err = q.Raw(
		sqltemplete,
		eve.Id,
		eve.CurrentStep,
		fmt.Sprintf("%v %v %v", eve.LeftValue, eve.Operator(), eve.RightValue()),
		status,
		time.Unix(eve.EventTime, 0),
	).Exec()
	return
}