コード例 #1
0
ファイル: driver.go プロジェクト: harveymonster/ogonori
//
// Open returns a new connection to the database.
// The dsn (driver-specific name) is a string in a driver-specific format.
// For ogonori, the dsn should be of the format:
//   uname@passw:ip-or-host:port/dbname
//   or
//   uname@passw:ip-or-host/dbname  (default port of 2424 is used)
//
func (d *OgonoriDriver) Open(dsn string) (driver.Conn, error) {
	ogl.Debugln("** OgonoriDriver#Open")

	uname, passw, host, port, dbname, err := parseDsn(dsn)
	clientOpts := obinary.ClientOptions{ServerHost: host, ServerPort: port}
	dbc, err := obinary.NewDBClient(clientOpts)
	if err != nil {
		return nil, err
	}

	// TODO: right now assumes DocumentDB type - pass in on the dsn??
	//       NOTE: I tried a graphDB with DocumentDB type and it worked, so why is it necesary at all?
	// TODO: this maybe shouldn't happen in this method -> might do it lazily in Query/Exec methods?
	err = obinary.OpenDatabase(dbc, dbname, constants.DocumentDB, uname, passw)
	if err != nil {
		return nil, err
	}

	return &ogonoriConn{dbc}, nil
}
コード例 #2
0
ファイル: helpers_test.go プロジェクト: larryaasen/ogonori
func ConnectToDocumentDatabase() *obinary.DBClient {
	db, _ := NewDB()
	obinary.OpenDatabase(db, dbDocumentName, constants.DocumentDB, "admin", "admin")
	return db
}
コード例 #3
0
ファイル: helpers_test.go プロジェクト: larryaasen/ogonori
func ConnectToGraphDatabase() *obinary.DBClient {
	db, _ := NewDB()
	obinary.OpenDatabase(db, dbGraphName, constants.GraphDB, "admin", "admin")
	return db
}
コード例 #4
0
func testConcurrentClients() {
	var (
		dbc1, dbc2, dbc3, dbc4 *obinary.DBClient
		err                    error
	)

	const nclients = 4

	runtime.GOMAXPROCS(nclients)

	dbc1, err = obinary.NewDBClient(obinary.ClientOptions{})
	Ok(err)
	defer dbc1.Close()

	dbc2, err = obinary.NewDBClient(obinary.ClientOptions{})
	Ok(err)
	defer dbc2.Close()

	dbc3, err = obinary.NewDBClient(obinary.ClientOptions{})
	Ok(err)
	defer dbc3.Close()

	dbc4, err = obinary.NewDBClient(obinary.ClientOptions{})
	Ok(err)
	defer dbc4.Close()

	err = obinary.OpenDatabase(dbc1, dbDocumentName, constants.DocumentDB, "admin", "admin")
	Ok(err)
	defer obinary.CloseDatabase(dbc1)

	err = obinary.OpenDatabase(dbc2, dbDocumentName, constants.DocumentDB, "admin", "admin")
	Ok(err)
	defer obinary.CloseDatabase(dbc2)

	err = obinary.OpenDatabase(dbc3, dbDocumentName, constants.DocumentDB, "admin", "admin")
	Ok(err)
	defer obinary.CloseDatabase(dbc3)

	err = obinary.OpenDatabase(dbc4, dbDocumentName, constants.DocumentDB, "admin", "admin")
	Ok(err)
	defer obinary.CloseDatabase(dbc4)

	/* ---[ queries and insertions concurrently ]--- */

	var wg sync.WaitGroup
	wg.Add(nclients)

	sql := `select count(*) from Cat where caretaker like 'Eva%'`
	docs, err := obinary.SQLQuery(dbc1, sql, "")
	Ok(err)
	beforeCount := toInt(docs[0].GetField("count").Value)

	go doQueriesAndInsertions(&wg, dbc1, 1)
	go doQueriesAndInsertions(&wg, dbc2, 2)
	go doQueriesAndInsertions(&wg, dbc3, 3)
	go doQueriesAndInsertions(&wg, dbc4, 4)

	wg.Wait()

	sql = `select count(*) from Cat where caretaker like 'Eva%'`
	docs, err = obinary.SQLQuery(dbc1, sql, "")
	Ok(err)
	afterCount := toInt(docs[0].GetField("count").Value)
	Equals(beforeCount, afterCount)

	fmt.Println(afterCount)
}