async def setUp(self): self.sdb = SqliteDatabase( SqliteDatabaseConfig(filename=self.database_name)) await self.sdb.__aenter__() self.table_name = "myTable" self.cols = { "key": "INTEGER NOT NULL PRIMARY KEY", "firstName": "text", "lastName": "text", "age": "real", } self.data_dicts = [ { "key": 10, "firstName": "John", "lastName": "Doe", "age": 16 }, { "key": 11, "firstName": "John", "lastName": "Miles", "age": 37 }, { "key": 12, "firstName": "Bill", "lastName": "Miles", "age": 40 }, ]
def setUpClass(cls): # SQL table info cls.table_name = "TestTable" cls.cols = { "key": "varchar(100) NOT NULL PRIMARY KEY", "feature_PetalLength": "float DEFAULT NULL", "feature_PetalWidth": "float DEFAULT NULL", "feature_SepalLength": "float DEFAULT NULL", "feature_SepalWidth": "float DEFAULT NULL", "target_name_confidence": "float DEFAULT NULL", "target_name_value": "varchar(100) DEFAULT NULL", } # Sqlite db file file, cls.database_name = tempfile.mkstemp(suffix=".db") os.close(file) # Sqlite config cls.db_config = SqliteDatabaseConfig(cls.database_name) # DbSource config cls.source_config = DbSourceConfig( db=SqliteDatabase(cls.db_config), table_name=cls.table_name, model_columns="key feature_PetalLength feature_PetalWidth feature_SepalLength feature_SepalWidth target_name_confidence target_name_value".split(), ) # Setup connection to reset state (different from the connection used in the tests) conn = sqlite3.connect(cls.database_name) db_cursor = conn.cursor() db_cursor.execute(cls.SQL_TEARDOWN) db_cursor.execute(cls.SQL_SETUP) conn.commit() db_cursor.close() conn.close()
async def operation_db(): """ Create the database and table (myTable) for the db operations """ sdb = SqliteDatabase(SqliteDatabaseConfig(filename="examples.db")) dataflow = DataFlow( operations={"db_query_create": db_query_create_table.op}, configs={"db_query_create": DatabaseQueryConfig(database=sdb)}, seed=[], ) inputs = [ Input( value="myTable", definition=db_query_create_table.op.inputs["table_name"], ), Input( value={ "key": "INTEGER NOT NULL PRIMARY KEY", "firstName": "text", "lastName": "text", "age": "int", }, definition=db_query_create_table.op.inputs["cols"], ), ] async for ctx, result in MemoryOrchestrator.run(dataflow, inputs): pass
def setUpClass(cls): super().setUpClass() fileno, cls.database_name = tempfile.mkstemp(suffix=".db") os.close(fileno) cls.sdb = SqliteDatabase( SqliteDatabaseConfig(filename=cls.database_name) )