Advertisement
mutchuloko

Função filter rethindb

Jan 31st, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.85 KB | None | 0 0
  1. def filter(self,
  2.                table_name: str,
  3.                row: str = None,
  4.                value: str = None,
  5.                read_mode: str = 'outdated',
  6.                time_format: str = 'native',
  7.                profile: bool = False,
  8.                durability: str = 'soft',
  9.                group_format: str = 'native',
  10.                noreply: bool = False,
  11.                array_limit: int = 100000,
  12.                binary_format: str = 'native',
  13.                min_batch_rows: int = 8,
  14.                max_batch_rows: int = 10,
  15.                max_batch_bytes: int = 1,
  16.                max_batch_seconds: float = 0.5,
  17.                fbsf: int = 8,
  18.                ) -> r.net.DefaultCursor:
  19.         try:
  20.             if row and value:
  21.                 """Return a list of specific data.
  22.  
  23.                row must be the same name of the table's row desired to filter.
  24.                value is the compare value desired to filter.
  25.  
  26.                Example:
  27.                row='name' and value='John'.
  28.                """
  29.                 return (
  30.                     r.table(table_name).filter(r.row[row] == value)
  31.                     .run(self.__conn,
  32.                          read_mode=read_mode,
  33.                          time_format=time_format,
  34.                          profile=profile,
  35.                          durability=durability,
  36.                          group_format=group_format,
  37.                          noreply=noreply,
  38.                          array_limit=array_limit,
  39.                          binary_format=binary_format,
  40.                          min_batch_rows=min_batch_rows,
  41.                          max_batch_rows=max_batch_rows,
  42.                          max_batch_bytes=max_batch_bytes,
  43.                          max_batch_seconds=max_batch_bytes,
  44.                          first_batch_scaledown_factor=fbsf
  45.                          )
  46.                 )
  47.             else:
  48.                 """Return a single JSON result or a cursor."""
  49.                 return (
  50.                     r.table(table_name)
  51.                     .run(self.__conn,
  52.                          read_mode=read_mode,
  53.                          time_format=time_format,
  54.                          profile=profile,
  55.                          durability=durability,
  56.                          group_format=group_format,
  57.                          noreply=noreply,
  58.                          array_limit=array_limit,
  59.                          binary_format=binary_format,
  60.                          min_batch_rows=min_batch_rows,
  61.                          max_batch_rows=max_batch_rows,
  62.                          max_batch_bytes=max_batch_bytes,
  63.                          max_batch_seconds=max_batch_bytes,
  64.                          first_batch_scaledown_factor=fbsf
  65.                          )
  66.                 )
  67.         except errors.ReqlError as error:
  68.             print('Error: ', error)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement