Skip to content

Commit

Permalink
Make it possible to set the attachment key when creating a basket
Browse files Browse the repository at this point in the history
  • Loading branch information
gacarrillor committed Sep 24, 2024
1 parent 39b6748 commit 6106469
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
4 changes: 3 additions & 1 deletion modelbaker/dbconnector/db_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,9 @@ def get_classes_relevance(self):
"""
return []

def create_basket(self, dataset_tid, topic, tilitid_value=None):
def create_basket(
self, dataset_tid, topic, tilitid_value=None, attachment_key="modelbaker"
):
"""
Returns the state and the errormessage
"""
Expand Down
7 changes: 5 additions & 2 deletions modelbaker/dbconnector/gpkg_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,9 @@ def get_classes_relevance(self):
return contents
return []

def create_basket(self, dataset_tid, topic, tilitid_value=None):
def create_basket(
self, dataset_tid, topic, tilitid_value=None, attachment_key="modelbaker"
):
if self._table_exists(GPKG_BASKET_TABLE):
cursor = self.conn.cursor()
cursor.execute(
Expand Down Expand Up @@ -951,7 +953,7 @@ def create_basket(self, dataset_tid, topic, tilitid_value=None):
cursor.execute(
"""
INSERT INTO "{basket_table}" ("{tid_name}", dataset, topic, "{tilitid_name}", attachmentkey )
VALUES (?, ?, ?, ?, 'modelbaker')
VALUES (?, ?, ?, ?, ?)
""".format(
tid_name=self.tid,
tilitid_name=self.tilitid,
Expand All @@ -962,6 +964,7 @@ def create_basket(self, dataset_tid, topic, tilitid_value=None):
dataset_tid,
topic,
tilitid_value,
attachment_key,
),
)
self.conn.commit()
Expand Down
7 changes: 5 additions & 2 deletions modelbaker/dbconnector/mssql_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,9 @@ def get_classes_relevance(self):
result = self._get_dict_result(cur)
return result

def create_basket(self, dataset_tid, topic, tilitid_value=None):
def create_basket(
self, dataset_tid, topic, tilitid_value=None, attachment_key="modelbaker"
):
if self.schema and self._table_exists(BASKET_TABLE):
cur = self.conn.cursor()
cur.execute(
Expand All @@ -1081,7 +1083,7 @@ def create_basket(self, dataset_tid, topic, tilitid_value=None):
cur.execute(
"""
INSERT INTO {schema}.{basket_table} ({tid_name}, dataset, topic, {tilitid_name}, attachmentkey )
VALUES (NEXT VALUE FOR {schema}.{sequence}, {dataset_tid}, '{topic}', {tilitid}, 'modelbaker')
VALUES (NEXT VALUE FOR {schema}.{sequence}, {dataset_tid}, '{topic}', {tilitid}, {attachment_key})
""".format(
schema=self.schema,
sequence="t_ili2db_seq",
Expand All @@ -1091,6 +1093,7 @@ def create_basket(self, dataset_tid, topic, tilitid_value=None):
dataset_tid=dataset_tid,
topic=topic,
tilitid=tilitid_value,
attachment_key=attachment_key,
)
)
self.conn.commit()
Expand Down
7 changes: 5 additions & 2 deletions modelbaker/dbconnector/pg_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,9 @@ def get_classes_relevance(self):
return cur.fetchall()
return []

def create_basket(self, dataset_tid, topic, tilitid_value=None):
def create_basket(
self, dataset_tid, topic, tilitid_value=None, attachment_key="modelbaker"
):
if self.schema and self._table_exists(PG_BASKET_TABLE):
cur = self.conn.cursor()
cur.execute(
Expand Down Expand Up @@ -1129,7 +1131,7 @@ def create_basket(self, dataset_tid, topic, tilitid_value=None):
sql.SQL(
"""
INSERT INTO {schema}.{basket_table} ({tid_name}, dataset, topic, {tilitid_name}, attachmentkey)
VALUES (nextval(%s), %s, %s, %s, 'modelbaker')
VALUES (nextval(%s), %s, %s, %s, %s)
"""
).format(
schema=sql.Identifier(self.schema),
Expand All @@ -1142,6 +1144,7 @@ def create_basket(self, dataset_tid, topic, tilitid_value=None):
dataset_tid,
topic,
tilitid_value,
attachment_key,
),
)
self.conn.commit()
Expand Down

0 comments on commit 6106469

Please sign in to comment.