MCPcopy Create free account
hub / github.com/SeldonIO/seldon-server / addAttrsToDb

Function addAttrsToDb

scripts/add_attr_schema.py:13–40  ·  view source on GitHub ↗
(attrs, item_type)

Source from the content-addressed store, hash-verified

11 text='TEXT', enum='ENUM')
12
13def addAttrsToDb(attrs, item_type):
14 attrs.append({"name":"content_type", "value_type":["article"]})
15 for attr in attrs:
16 attrValType = attr['value_type']
17 if type(attrValType) is list:
18 attrValType = 'enum'
19 cur = db.cursor()
20 cur.execute("INSERT INTO ITEM_ATTR (name, type, item_type) "
21 + " VALUES (%s, %s, %s)", (attr['name'], value_types_to_db_map[attrValType], item_type))
22 if attrValType is 'enum':
23 for index,enum in enumerate(attr['value_type'], start=1):
24 cur = db.cursor()
25 cur.execute("SELECT attr_id FROM ITEM_ATTR WHERE NAME = %s and ITEM_TYPE = %s", (attr['name'],item_type))
26 rows = cur.fetchall()
27 attrId = rows[0][0]
28 cur = db.cursor()
29 cur.execute("INSERT INTO ITEM_ATTR_ENUM (attr_id, value_id, value_name) VALUES (%s, %s, %s)",(attrId, index, enum))
30 cur = db.cursor()
31
32 cur.execute("SELECT attr_id, value_id, value_name FROM ITEM_ATTR_ENUM")
33 rows = cur.fetchall()
34 for row in rows:
35 enum_attr_id = row[0]
36 enum_value_id = row[1]
37 enum_value_name = row[2]
38 cur = db.cursor()
39 cur.execute("INSERT INTO DIMENSION (item_type, attr_id, value_id) VALUES"
40 + " (%s, %s, %s)", (item_type, enum_attr_id, enum_value_id))
41
42def doDbChecks():
43 cur = db.cursor()

Callers 1

addToDbFunction · 0.70

Calls 1

executeMethod · 0.65

Tested by

no test coverage detected