コード例 #1
0
ファイル: main_test.go プロジェクト: larryaasen/ogonori
func CleanupSeed() {
	documentDB := ConnectToDocumentDatabase()
	defer documentDB.Close()
	obinary.SQLCommand(documentDB, "TRUNCATE Animal")
	obinary.SQLCommand(documentDB, "TRUNCATE Cat")

	graphDB := ConnectToGraphDatabase()
	defer graphDB.Close()
	obinary.SQLCommand(graphDB, "TRUNCATE Person")
	obinary.SQLCommand(graphDB, "TRUNCATE Friend")
}
コード例 #2
0
ファイル: conn.go プロジェクト: harveymonster/ogonori
func doExec(dbc *obinary.DBClient, cmd string, args []driver.Value) (driver.Result, error) {
	strargs := valuesToStrings(args)

	retval, docs, err := obinary.SQLCommand(dbc, cmd, strargs...)
	ogl.Debugf("exec1: %T: %v\n", retval, retval)
	if err != nil {
		return ogonoriResult{-1, -1}, err
	}

	if docs == nil {
		ogl.Debugln("exec2")
		nrows, err := strconv.ParseInt(retval, 10, 64)
		if err != nil {
			ogl.Debugf("exec3: %T: %v\n", err, err)
			nrows = -1
		}
		return ogonoriResult{nrows, -1}, err
	}

	lastdoc := docs[len(docs)-1]
	// sepIdx := strings.Index(lastDoc.RID, ":")
	// if sepIdx < 0 {
	// 	return ogonoriResult{len64(docs), -1}, fmt.Errorf("RID of returned doc not of expected format: %v", lastDoc.RID)
	// }
	// lastId, err := strconv.ParseInt(lastDoc.RID[sepIdx+1:], 10, 64)
	// if err != nil {
	// 	return ogonoriResult{len64(docs), -1}, fmt.Errorf("Couldn't parse ID from doc RID: %v: %v", lastDoc.RID, err)
	// }
	return ogonoriResult{len64(docs), lastdoc.RID.ClusterPos}, err
}
コード例 #3
0
func doQueriesAndInsertions(wg *sync.WaitGroup, dbc *obinary.DBClient, id int) {
	defer wg.Done()

	rnd := rand.New(rand.NewSource(time.Now().UTC().UnixNano()))
	nreps := 1000
	ridsToDelete := make([]string, 0, nreps)

	for i := 0; i < nreps; i++ {
		randInt := rnd.Intn(3)
		if randInt > 0 {
			time.Sleep(time.Duration(randInt) * time.Millisecond)
		}

		if (i+randInt)%2 == 0 {
			sql := fmt.Sprintf(`insert into Cat set name="Bar", age=%d, caretaker="Eva%d"`, 20+id, id)
			_, docs, err := obinary.SQLCommand(dbc, sql)
			Ok(err)
			Equals(1, len(docs))
			ridsToDelete = append(ridsToDelete, docs[0].RID.String())

		} else {
			sql := fmt.Sprintf(`select count(*) from Cat where caretaker="Eva%d"`, id)
			docs, err := obinary.SQLQuery(dbc, sql, "")
			Ok(err)
			Equals(toInt(docs[0].GetField("count").Value), len(ridsToDelete))
		}
	}

	fmt.Printf("records insert by goroutine %d: %v\n", id, len(ridsToDelete))

	/* ---[ clean up ]--- */

	for _, rid := range ridsToDelete {
		_, _, err := obinary.SQLCommand(dbc, `delete from Cat where @rid=`+rid)
		Ok(err)
	}
	sql := fmt.Sprintf(`select count(*) from Cat where caretaker="Eva%d"`, id)
	docs, err := obinary.SQLQuery(dbc, sql, "")
	Ok(err)
	Equals(toInt(docs[0].GetField("count").Value), 0)
}
コード例 #4
0
ファイル: main_test.go プロジェクト: larryaasen/ogonori
func Seed() {
	db := ConnectToDocumentDatabase()
	defer db.Close()

	var err error

	for _, seed := range DocumentDBSeeds {
		if _, _, err = obinary.SQLCommand(db, seed); err != nil {
			panic(err) // Programming error
		}
	}
}