blob: 5f8b60b714b2156d3b63ed9a36a2f50f39aab65c [file] [log] [blame]
:mod:`airflow.providers.google.leveldb.hooks.leveldb`
=====================================================
.. py:module:: airflow.providers.google.leveldb.hooks.leveldb
.. autoapi-nested-parse::
Hook for Level DB
Module Contents
---------------
.. py:exception:: LevelDBHookException
Bases: :class:`airflow.exceptions.AirflowException`
Exception specific for LevelDB
.. py:class:: LevelDBHook(leveldb_conn_id: str = default_conn_name)
Bases: :class:`airflow.hooks.base.BaseHook`
Plyvel Wrapper to Interact With LevelDB Database
`LevelDB Connection Documentation <https://plyvel.readthedocs.io/en/latest/>`__
.. attribute:: conn_name_attr
:annotation: = leveldb_conn_id
.. attribute:: default_conn_name
:annotation: = leveldb_default
.. attribute:: conn_type
:annotation: = leveldb
.. attribute:: hook_name
:annotation: = LevelDB
.. method:: get_conn(self, name: str = '/tmp/testdb/', create_if_missing: bool = False, **kwargs)
Creates `Plyvel DB <https://plyvel.readthedocs.io/en/latest/api.html#DB>`__
:param name: path to create database e.g. `/tmp/testdb/`)
:type name: str
:param create_if_missing: whether a new database should be created if needed
:type create_if_missing: bool
:param kwargs: other options of creation plyvel.DB. See more in the link above.
:type kwargs: Dict[str, Any]
:returns: DB
:rtype: plyvel.DB
.. method:: close_conn(self)
Closes connection
.. method:: run(self, command: str, key: bytes, value: bytes = None, keys: List[bytes] = None, values: List[bytes] = None)
Execute operation with leveldb
:param command: command of plyvel(python wrap for leveldb) for DB object e.g.
``"put"``, ``"get"``, ``"delete"``, ``"write_batch"``.
:type command: str
:param key: key for command(put,get,delete) execution(, e.g. ``b'key'``, ``b'another-key'``)
:type key: bytes
:param value: value for command(put) execution(bytes, e.g. ``b'value'``, ``b'another-value'``)
:type value: bytes
:param keys: keys for command(write_batch) execution(List[bytes], e.g. ``[b'key', b'another-key'])``
:type keys: List[bytes]
:param values: values for command(write_batch) execution e.g. ``[b'value'``, ``b'another-value']``
:type values: List[bytes]
:returns: value from get or None
:rtype: Optional[bytes]
.. method:: put(self, key: bytes, value: bytes)
Put a single value into a leveldb db by key
:param key: key for put execution, e.g. ``b'key'``, ``b'another-key'``
:type key: bytes
:param value: value for put execution e.g. ``b'value'``, ``b'another-value'``
:type value: bytes
.. method:: get(self, key: bytes)
Get a single value into a leveldb db by key
:param key: key for get execution, e.g. ``b'key'``, ``b'another-key'``
:type key: bytes
:returns: value of key from db.get
:rtype: bytes
.. method:: delete(self, key: bytes)
Delete a single value in a leveldb db by key.
:param key: key for delete execution, e.g. ``b'key'``, ``b'another-key'``
:type key: bytes
.. method:: write_batch(self, keys: List[bytes], values: List[bytes])
Write batch of values in a leveldb db by keys
:param keys: keys for write_batch execution e.g. ``[b'key', b'another-key']``
:type keys: List[bytes]
:param values: values for write_batch execution e.g. ``[b'value', b'another-value']``
:type values: List[bytes]