I assume you are using taipy version 2.1.3. Which is the latest as of today.
The error you are facing is that db_extra_args
should be provided in the configuration of your data node. An empty dictionary should work. db_extra_args={}
.
I noticed 3 other (potential) issues in your code:
- A missing semicolon ";" at the end of the SQL query.
- A missing path parameter. It should point to the folder containing the SQLite database file. If the path is not provided, Taipy will search for it in the root folder. (In my example I have my database stored in the file "../data/sqlite/taipy.db")
- The db_name should include the file extension. (In my example it is "taipy.db")
Below is the code I used to make your code work in my environment. I previously created a sales table (CREATE TABLE sales (date int, nb_sales int);
) in the database "../data/sqlite/taipy.db".
from taipy import Config
import taipy as tp
import pandas as pd
def double(data):
return "WHATEVER"
def write_query_builder(data: pd.DataFrame):
insert_data = list(
data[["date", "nb_sales"]].itertuples(index=False, name=None))
return [
"DELETE FROM sales;",
("INSERT INTO sales VALUES (?, ?);", insert_data)
]
sales_cfg = Config.configure_sql_data_node(
id="sales_history",
db_username="",
db_password="",
db_extra_args={},
db_name="taipy.db",
db_engine="sqlite",
read_query="SELECT * from sales;",
write_query_builder=write_query_builder,
path="../data/sqlite/"
)
output_data_node_cfg = Config.configure_data_node(id="output")
# Configuration of tasks
task_cfg = Config.configure_task("double", double, sales_cfg, output_cfg)
# Configuration of the pipeline and scenario
pipeline_cfg = Config.configure_pipeline("my_pipeline", [task_cfg])
scenario_cfg = Config.configure_scenario("my_scenario", [pipeline_cfg])
# Run of the Core
tp.Core().run()
Note that when no db_extra_args
is needed, it will not be necessary to provide an empty dictionary anymore in the next version 2.2 (The target date is May 2023 for the release). A documentation enhancement is also planned for 2.2, particularly more examples for all supported db_engines (SQLite, mssql, MySQL, or PostgreSQL).