def make_dummy_db(): """ Creates inmemory SQLite database""" # Create in-memory database db = RCDBProvider("sqlite://", check_version=False) destroy_all_create_schema(db) print("Dummy memory database created!") # create conditions types event_count_type = db.create_condition_type("event_count", ConditionType.INT_FIELD, "The event count") data_value_type = db.create_condition_type("data_value", ConditionType.FLOAT_FIELD, "Some data value") tag_type = db.create_condition_type("tag", ConditionType.STRING_FIELD, "Tag... What it means... hm...") # create runs and fill values for i in range(0, 100): run = db.create_run(i) db.add_condition(run, event_count_type, i + 950) # event_count in range 950 - 1049 db.add_condition(i, data_value_type, (i / 100.0) + 1) # data_value in 1 - 2 db.add_condition(run, tag_type, "tag" + str(i)) # Some text data print("Runs filled with data") return db
from rcdb.provider import RCDBProvider, destroy_all_create_schema from rcdb.model import ConditionType if len(sys.argv) > 1: # Open database using connection string from command line argument db = RCDBProvider(sys.argv[1]) else: # Create in-memory database db = RCDBProvider("sqlite://", check_version=False) destroy_all_create_schema(db) # Create condition type db.create_condition_type("my_val", ConditionType.INT_FIELD, "This is my value") # create run number 1 db.create_run(1) # Add data to database db.add_condition(1, "my_val", 1000) # Replace previous value db.add_condition(1, "my_val", 2000, replace=True) # Get condition from database condition = db.get_condition(1, "my_val") print(condition) print("value =", condition.value) print("name =", condition.name) ct = db.get_condition_type("my_val")