Пример #1
0
/*
finds a user
Usage: FindUser("testuser")
*/
func (self *CassandraMetaStore) findUser(user string) (*MetaUser, error) {
	var mu MetaUser
	q := self.client.Query("select * from users where username = ?", user)
	b := cqlr.BindQuery(q)
	b.Scan(&mu)
	if mu.Name == "" {
		return nil, errUserNotFound
	}
	return &mu, nil
}
Пример #2
0
func (self *CassandraMetaStore) findOid(oid string) (*MetaObject, error) {
	q := self.client.Query("select oid, size from oids where oid = ? limit 1", oid)
	b := cqlr.BindQuery(q)
	var mo MetaObject
	b.Scan(&mo)
	defer b.Close()
	if mo.Oid == "" {
		return nil, errObjectNotFound
	}
	return &mo, nil
}
Пример #3
0
/*
returns all users, only for use when not using ldap
*/
func (self *CassandraMetaStore) Users() ([]*MetaUser, error) {
	if Config.Ldap.Enabled {
		return []*MetaUser{}, errNotImplemented
	}
	var mu MetaUser
	users := make([]*MetaUser, 0)
	q := self.client.Query("select username from users")
	b := cqlr.BindQuery(q)
	for b.Scan(&mu) {
		users = append(users, &mu)
	}
	return users, nil
}
Пример #4
0
func (self *CassandraMetaStore) findProject(projectName string) (*MetaProject, error) {
	if projectName == "" {
		return nil, errProjectNotFound
	}
	q := self.client.Query("select * from projects where name = ?", projectName)
	b := cqlr.BindQuery(q)
	var ct MetaProject
	b.Scan(&ct)
	defer b.Close()
	if ct.Name == "" {
		return nil, errProjectNotFound
	}
	return &ct, nil
}
Пример #5
0
func GetAllTweetsForTimeLine(timeLine string) ([]Tweet, error) {
	session, err := dao.GetSession()
	if err != nil {
		return nil, err
	}

	q := session.Query(`SELECT text, id, timeline FROM tweet WHERE timeline = ?`, timeLine)
	bind := cqlr.BindQuery(q)
	defer bind.Close()

	var tweets []Tweet
	t := Tweet{}
	for bind.Scan(&t) {
		tweets = append(tweets, t)
	}
	return tweets, nil
}
Пример #6
0
func TestKitchenSink(t *testing.T) {

	s := setup(t, "kitchen_sink")

	var buf bytes.Buffer
	fmt.Fprint(&buf, "INSERT INTO kitchen_sink (")

	colFragments := kitchenSinkColumns

	colClause := strings.Join(colFragments, ", ")
	fmt.Fprint(&buf, colClause)

	fmt.Fprint(&buf, ") VALUES (")

	placeHolderFragments := make([]string, len(colFragments))
	for i, _ := range placeHolderFragments {
		placeHolderFragments[i] = "?"
	}

	placeHolderClause := strings.Join(placeHolderFragments, ",")
	fmt.Fprint(&buf, placeHolderClause)
	fmt.Fprint(&buf, ")")

	insert := buf.String()

	if err := cqlr.Bind(insert, k).Exec(s); err != nil {
		t.Fatal(err)
	}

	buf.Reset()

	q := s.Query("SELECT * FROM kitchen_sink WHERE id = ?", k.Id)
	b := cqlr.BindQuery(q)

	var nk KitchenSink
	count := 0
	for b.Scan(&nk) {
		count++
	}

	assert.Equal(t, 1, count)
	assert.Equal(t, k, nk)
}