@@ -42,17 +42,17 @@ def is_motherduck(self):
4242 def prepare (self , views ):
4343 schemas = set (view .schema for view in views )
4444 for schema in schemas :
45- self .con .sql (f"CREATE SCHEMA IF NOT EXISTS { schema } " )
45+ self .con .cursor (). sql (f"CREATE SCHEMA IF NOT EXISTS { schema } " )
4646 console .log (f"Created schema { schema } " )
4747
4848 def teardown (self ):
4949 os .remove (self .path )
5050
5151 def materialize_sql_view (self , view ):
52- self .con .sql (f"CREATE OR REPLACE TABLE { view .table_reference } AS ({ view .query } )" )
52+ self .con .cursor (). sql (f"CREATE OR REPLACE TABLE { view .table_reference } AS ({ view .query } )" )
5353
5454 def materialize_sql_view_incremental (self , view , incremental_field_name ):
55- self .con .sql (
55+ self .con .cursor (). sql (
5656 f"""
5757 INSERT INTO { view .table_reference }
5858 SELECT *
@@ -63,14 +63,18 @@ def materialize_sql_view_incremental(self, view, incremental_field_name):
6363
6464 def materialize_python_view (self , view ):
6565 dataframe = self .read_python_view (view ) # noqa: F841
66- self .con .sql (f"CREATE OR REPLACE TABLE { view .table_reference } AS SELECT * FROM dataframe" )
66+ self .con .cursor ().sql (
67+ f"CREATE OR REPLACE TABLE { view .table_reference } AS SELECT * FROM dataframe"
68+ )
6769
6870 def materialize_json_view (self , view ):
6971 dataframe = pd .read_json (view .path ) # noqa: F841
70- self .con .sql (f"CREATE OR REPLACE TABLE { view .table_reference } AS SELECT * FROM dataframe" )
72+ self .con .cursor ().sql (
73+ f"CREATE OR REPLACE TABLE { view .table_reference } AS SELECT * FROM dataframe"
74+ )
7175
7276 def delete_table_reference (self , table_reference ):
73- self .con .sql (f"DROP TABLE IF EXISTS { table_reference } " )
77+ self .con .cursor (). sql (f"DROP TABLE IF EXISTS { table_reference } " )
7478
7579 def read_sql (self , query : str ) -> pd .DataFrame :
7680 return self .con .cursor ().sql (query ).df ()
@@ -154,8 +158,8 @@ def switch_for_wap_mode(self, view_keys: list[tuple[str]]):
154158 try :
155159 # Concatenate all the statements into one string and execute them
156160 sql = "\n " .join (f"{ statement } ;" for statement in statements )
157- self .con .execute (f"BEGIN TRANSACTION; { sql } COMMIT;" )
161+ self .con .cursor (). execute (f"BEGIN TRANSACTION; { sql } COMMIT;" )
158162 except duckdb .ProgrammingError as e :
159163 # Make sure to rollback if there's an error
160- self .con .execute ("ROLLBACK" )
164+ self .con .cursor (). execute ("ROLLBACK" )
161165 raise e
0 commit comments