예제 #1
0
파일: database.go 프로젝트: wybiral/stay
/*
Return resulting keys from a scan.
*/
func (db *Database) Keys(s *bitvec.Iterator) chan string {
	ch := make(chan string)
	go func() {
		for id := range s.Ids() {
			ch <- db.keys[id]
		}
		close(ch)
	}()
	return ch
}
예제 #2
0
파일: server.go 프로젝트: wybiral/stay
func buildQuery(ctx *Context, x interface{}) *bitvec.Iterator {
	var query *bitvec.Iterator
	switch v := x.(type) {
	case string:
		query = ctx.db.Query(v)
	case []interface{}:
		op := v[0].(string)
		query = buildQuery(ctx, v[1])
		if op == "not" {
			query = query.Not()
		} else {
			if op == "and" {
				for _, q := range v[2:] {
					query = query.And(buildQuery(ctx, q))
				}
			} else if op == "or" {
				for _, q := range v[2:] {
					query = query.Or(buildQuery(ctx, q))
				}
			} else if op == "xor" {
				for _, q := range v[2:] {
					query = query.Xor(buildQuery(ctx, q))
				}
			}
		}
	}
	return query
}