def get_multiple(index, data=None): """ Get multiple records by ID """ try: serverClient = FaunaClient( secret=os.environ.get("FAUNA_SERVER_SECRET")) res_arr = [] if data is None: res = serverClient.query( q.map_(q.lambda_("data", q.get(q.var("data"))), q.paginate(q.match(q.index(index))))) res_arr.extend(res["data"]) elif isinstance(data, list): for x in data: res = serverClient.query( q.map_(q.lambda_("data", q.get(q.var("data"))), q.paginate(q.match(q.index(index), q.casefold(x))))) res_arr.extend(res["data"]) else: res = serverClient.query( q.map_(q.lambda_("data", q.get(q.var("data"))), q.paginate(q.match(q.index(index), q.casefold(data))))) res_arr.extend(res["data"]) arr = [] for x in res_arr: x["data"]["ref_id"] = x["ref"].id() arr.append(x["data"]) return arr except Exception as ex: raise ex
def test_casefold(self): self.assertEqual(self._q(query.casefold("Hen Wen")), "hen wen") # https://unicode.org/reports/tr15/ self.assertEqual(self._q(query.casefold(u'\u212B', "NFD")), u'A\u030A') self.assertEqual(self._q(query.casefold(u'\u212B', "NFC")), u'\u00C5') self.assertEqual(self._q(query.casefold(u'\u1E9B\u0323', "NFKD")), u'\u0073\u0323\u0307') self.assertEqual(self._q(query.casefold(u'\u1E9B\u0323', "NFKC")), u'\u1E69') self.assertEqual(self._q(query.casefold(u'\u212B', "NFKCCaseFold")), u'\u00E5')
def test_casefold(self): self.assertJson(query.casefold("a string"), '{"casefold":"a string"}') self.assertJson(query.casefold("a string", "NFD"), '{"casefold":"a string","normalizer":"NFD"}')