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