Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

setup.py 1.0KB

123456789101112131415161718192021222324
  1. from settings import cassandra_addresses, cassandra_port, setup_db_dir, setup_tables_dir
  2. from cassandra.cluster import Cluster
  3. import os
  4. print(" == DB SETUP SCRIPT == ")
  5. print(f"Attempting Cassandra connection @ {cassandra_addresses}:{cassandra_port}")
  6. cluster = Cluster(cassandra_addresses, port=cassandra_port)
  7. session = cluster.connect()
  8. print(f"Connection OK")
  9. with open(f"{setup_db_dir}/keyspace/CREATE.sql") as keyspace_create:
  10. session.execute(keyspace_create.read())
  11. with open(f"{setup_db_dir}/keyspace/USE.sql") as keyspace_use:
  12. session.execute(keyspace_use.read())
  13. for folder_name in os.listdir(setup_tables_dir):
  14. with open(f'{setup_tables_dir}/{folder_name}/CREATE.sql') as sql_create:
  15. session.execute(sql_create.read())
  16. session.execute("INSERT INTO transactions (tx_id,address,value,tx_hash,block_id,timestamp) VALUES(1697,'t1KmCvfPMgfQXeNosFqzAmvYdEoYfdnxnVA',15701,'18c23345908f5097456c5f0014411381fd9866790aa65b863aab24ee17453732',818,1477724947)")
  17. res = session.execute('SELECT * FROM transactions')
  18. print(res.one())