diff --git a/INSTALL b/INSTALL index 65d0a8eb..2df17677 100644 --- a/INSTALL +++ b/INSTALL @@ -16,3 +16,5 @@ mkdir /opt/oracle # unzip instanclient in folder. sudo sh -c "echo /opt/oracle/instantclient_19_16 > /etc/ld.so.conf.d/oracle-instantclient.conf" sudo ldconfig +# For Cassandra: +sudo apt-get install libev4 libev-dev diff --git a/asyncdb/drivers/cassandra.py b/asyncdb/drivers/cassandra.py index 10e8c5cc..97e65500 100644 --- a/asyncdb/drivers/cassandra.py +++ b/asyncdb/drivers/cassandra.py @@ -17,6 +17,8 @@ from cassandra import ReadTimeout from cassandra.cluster import Cluster, EXEC_PROFILE_DEFAULT, ExecutionProfile, NoHostAvailable, ResultSet from cassandra.io.asyncorereactor import AsyncoreConnection +from cassandra.io.asyncioreactor import AsyncioConnection + try: from cassandra.io.libevreactor import LibevConnection LIBEV = True diff --git a/examples/cassandra_aio.py b/examples/cassandra_aio.py new file mode 100644 index 00000000..fea09b42 --- /dev/null +++ b/examples/cassandra_aio.py @@ -0,0 +1,82 @@ +import asyncio +from cassandra.cluster import Cluster, EXEC_PROFILE_DEFAULT, ExecutionProfile, NoHostAvailable, ResultSet +from cassandra.io.asyncioreactor import AsyncioConnection +from cassandra.auth import PlainTextAuthProvider +from cassandra.query import ( + dict_factory, + ordered_dict_factory, + named_tuple_factory, + ConsistencyLevel, + PreparedStatement, + BatchStatement, + SimpleStatement, + BatchType +) +from cassandra.policies import ( + DCAwareRoundRobinPolicy, + DowngradingConsistencyRetryPolicy, + # RetryPolicy +) +try: + from cassandra.io.libevreactor import LibevConnection + LIBEV = True +except ImportError: + LIBEV = False + + +def main(): + params = { + "host": "127.0.0.1", + "port": "9042", + "username": 'cassandra', + "password": 'cassandra' + } + _auth = { + "username": params["username"], + "password": params["password"], + } + policy = DCAwareRoundRobinPolicy() + defaultprofile = ExecutionProfile( + load_balancing_policy=policy, + retry_policy=DowngradingConsistencyRetryPolicy(), + request_timeout=60, + row_factory=dict_factory, + consistency_level=ConsistencyLevel.LOCAL_QUORUM, + serial_consistency_level=ConsistencyLevel.LOCAL_SERIAL, + ) + profiles = { + EXEC_PROFILE_DEFAULT: defaultprofile + } + params = { + "port": params["port"], + "compression": True, + "connection_class": AsyncioConnection, + "protocol_version": 4, + "connect_timeout": 60, + "idle_heartbeat_interval": 0 + } + auth_provider = PlainTextAuthProvider(**_auth) + _cluster = Cluster( + ["127.0.0.1"], + auth_provider=auth_provider, + execution_profiles=profiles, + **params, + ) + print(_cluster) + try: + connection = _cluster.connect(keyspace=None) + print('CONNECTION > ', connection) + response = connection.execute("SELECT release_version FROM system.local") + result = [row for row in response] + print(result) + except NoHostAvailable as ex: + raise RuntimeError( + f'Not able to connect to any of the Cassandra contact points: {ex}' + ) from ex + + +if __name__ == "__main__": + try: + main() + finally: + pass diff --git a/setup.py b/setup.py index 34b9a6a8..e3266528 100644 --- a/setup.py +++ b/setup.py @@ -94,7 +94,7 @@ def readme(): ], author=__author__, author_email=__author_email__, - packages=find_packages(exclude=["contrib", "docs", "tests", "examples"]), + packages=find_packages(exclude=["bin", "contrib", "docs", "tests", "examples", "libraries"]), package_data={"asyncdb": ["py.typed"]}, license=__license__, setup_requires=[