Reputation: 23
I'm trying to get Taipy core working with Sqlite but don't succeed. Taipy doesn't seem to be able to connect.
Does anyone have a small working example?
Regards, Markus
I've tried to connect with e.g. the following settings:
sales_history_cfg = Config.configure_sql_data_node(
id="sales_history",
db_username="",
db_password="",
db_name="taipy",
db_engine="sqlite",
read_query="SELECT * from sales",
write_query_builder=write_query_builder
)
# Configuration of tasks
task_cfg = Config.configure_task("double",
double,
sales_history_cfg,
output_data_node_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()
Upvotes: 2
Views: 330
Reputation: 81
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:
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).
Upvotes: 2
Reputation: 1521
Have you previously created a SQL database with this username, password, and name? Taipy facilitates the connection to an already-existent SQL database but will not create one for you. You will then be able to use it like any other Data Nodes with all the features of Taipy Core.
There are many different ways to create a Database using a Cloud provider or other tools. You can find some information here.
Upvotes: 2