return self.value['email'] @email.setter def email(self, value): self.value['email'] = value cb = Bucket('couchbase://localhost/default') single_player = Player.create("bob", "*****@*****.**", cb) single_player.score += 100 single_player.save(cb) # Let's try multiple players players = ItemSequence([Player(x, create_structure=True) for x in ("joe", "jim", "bill", "larry")]) # Save them all cb.upsert_multi(players) # Give them all some points for p, options in players: p.score += randint(20, 2000) # also set the email? if not p.email: p.email = "{0}@{0}.notspecified.com".format(p.name) cb.replace_multi(players) all_players = ItemSequence([x[0] for x in players] + [single_player]) INDENT = " " * 3 for player in all_players.sequence: print "Name:", player.name print INDENT , player
if options.create_design: bm = c.bucket_manager() bm.design_create('search_keywords', DESIGN, use_devmode=False, syncwait=5) NOUNS = ['cow', 'cat', 'dog', 'computer', 'WMD'] ADJECTIVES = ['happy', 'sad', 'thoughtful', 'extroverted'] kv = {} for x in range(options.number_of_terms): n = random.choice(NOUNS) a = random.choice(ADJECTIVES) kv[" ".join([a, n])] = random.randint(1, 100000) c.upsert_multi(kv) vret = c.query('search_keywords', 'top_keywords', limit=10, descending=True) for row in vret: pprint.pprint(row, indent=4) # Sample output: #[ { u'id': u'WMD sad', u'key': 92772, u'value': None}, # { u'id': u'WMD thoughtful', u'key': 76222, u'value': None}, # { u'id': u'cow happy', u'key': 71984, u'value': None}, # { u'id': u'computer sad', u'key': 68849, u'value': None}, # { u'id': u'cat thoughtful', u'key': 68417, u'value': None},