Skip to content

Commit

Permalink
fix: update sqldatanode example to run successfully
Browse files Browse the repository at this point in the history
  • Loading branch information
trgiangdo committed Nov 1, 2023
1 parent 3548732 commit 454370c
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 17 deletions.
5 changes: 2 additions & 3 deletions docs/manuals/core/config/advanced-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,10 @@ the default configuration applies if some values are not provided.
import pandas as pd

def write_orders_plan(data: pd.DataFrame):
insert_data = list(
data[["date", "product_id", "number_of_products"]].itertuples(index=False, name=None))
insert_data = data[["date", "product_id", "number_of_products"]].to_dict("records")
return [
"DELETE FROM orders",
("INSERT INTO orders VALUES (?, ?, ?)", insert_data)
("INSERT INTO orders VALUES (:date, :product_id, :number_of_products)", insert_data)
]

def train(sales_history: pd.DataFrame):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
import pandas as pd

def write_query_builder(data: pd.DataFrame):
insert_data = list(
data[["date", "nb_sales"]].itertuples(index=False, name=None))
insert_data = data[["date", "nb_sales"]].to_dict("records")
return [
"DELETE FROM sales",
("INSERT INTO sales VALUES (?, ?)", insert_data)
("INSERT INTO sales VALUES (:date, :nb_sales)", insert_data)
]

sales_history_cfg = Config.configure_sql_data_node(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
import pandas as pd

def write_query_builder(data: pd.DataFrame):
insert_data = list(
data[["date", "nb_sales"]].itertuples(index=False, name=None))
insert_data = data[["date", "nb_sales"]].to_dict("records")
return [
"DELETE FROM sales",
("INSERT INTO sales VALUES (?, ?)", insert_data)
("INSERT INTO sales VALUES (:date, :nb_sales)", insert_data)
]

sales_history_cfg = Config.configure_sql_table_data_node(
sales_history_cfg = Config.configure_sql_data_node(
id="sales_history",
db_name="taipy",
db_engine="sqlite",
Expand Down
4 changes: 2 additions & 2 deletions docs/manuals/core/entities/code_example/my_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@


def write_orders_plan(data: pd.DataFrame):
insert_data = list(data[["date", "product_id", "number_of_products"]].itertuples(index=False, name=None))
return ["DELETE FROM orders", ("INSERT INTO orders VALUES (?, ?, ?)", insert_data)]
insert_data = data[["date", "product_id", "number_of_products"]].to_dict("records")
return ["DELETE FROM orders", ("INSERT INTO orders VALUES (:date, :product_id, :number_of_products)", insert_data)]


def train(sales_history: pd.DataFrame):
Expand Down
6 changes: 3 additions & 3 deletions docs/manuals/core/entities/data-node-mgt.md
Original file line number Diff line number Diff line change
Expand Up @@ -763,9 +763,9 @@ execute a list of queries returned by the query builder:
```python
data = pandas.DataFrame(
[
{"date": "01/08/2019", "product_id": 1 "number_of_products": 450},
{"date": "01/08/2019", "product_id": 3 "number_of_products": 320},
{"date": "01/08/2019", "product_id": 4 "number_of_products": 350},
{"date": "01/08/2019", "product_id": 1, "number_of_products": 450},
{"date": "01/08/2019", "product_id": 3, "number_of_products": 320},
{"date": "01/08/2019", "product_id": 4, "number_of_products": 350},
]
)
Expand Down
4 changes: 2 additions & 2 deletions docs/manuals/core/scheduling/code_example/my_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@


def write_orders_plan(data: pd.DataFrame):
insert_data = list(data[["date", "product_id", "number_of_products"]].itertuples(index=False, name=None))
return ["DELETE FROM orders", ("INSERT INTO orders VALUES (?, ?, ?)", insert_data)]
insert_data = data[["date", "product_id", "number_of_products"]].to_dict("records")
return ["DELETE FROM orders", ("INSERT INTO orders VALUES (:date, :product_id, :number_of_products)", insert_data)]


def train(sales_history: pd.DataFrame):
Expand Down

0 comments on commit 454370c

Please sign in to comment.