Пример #1
0
 async def _do_insert(self):
     connection = get_connection()
     data = self.dump(self._data)
     self.validate(data)
     table = self.get_table()
     result = await table.insert(data, return_changes=True).run(connection)
     return result
Пример #2
0
 async def _do_update(self):
     conn = get_connection()
     data = self.dump(self._data)
     self.validate(data)
     table = self.get_table()
     result = await table.get(data['id']
                              ).update(data, return_changes=True).run(conn)
     return result
Пример #3
0
 async def delete(self):
     conn = get_connection()
     table = self.get_table()
     data = self.dump(self._data)
     try:
         res = await table.get(data['id']).delete(return_changes=True
                                                  ).run(conn)
     except errors.ReqlOpFailedError:
         return res
     self._saved = False
     return res
Пример #4
0
 async def get(cls, _id, raw=False):
     connection = get_connection()
     table = cls.get_table()
     result = await table.get(_id).run(connection)
     if raw:
         return result
     else:
         if result is None:
             return result
         else:
             return cls(saved=True, **result)
Пример #5
0
 async def all(cls, raw=False):
     connection = get_connection()
     table = cls.get_table()
     try:
         users = await table.run(connection)
     except errors.ReqlOpFailedError as err:
         yield None
     async for user in users:
         if raw:
             yield user
         else:
             yield cls(saved=True, **user)
Пример #6
0
 async def drop(cls):
     conn = get_connection()
     table = cls.get_table()
     result = await table.delete().run(conn)
     return result
Пример #7
0
 async def create_table(cls):
     connection = get_connection()
     result = await r.table_create(cls._table).run(connection)
     return result