mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-24 22:45:44 +00:00
rollback my changes
This commit is contained in:
parent
b1e1928702
commit
605daf324b
@ -99,7 +99,10 @@ def get_transactions(connection, transactions_ids: list):
|
||||
def store_metadatas(connection, metadata: list):
|
||||
space = connection.space("meta_data")
|
||||
for meta in metadata:
|
||||
space.insert((meta["id"], meta["data"] if not "metadata" in meta else meta["metadata"]))
|
||||
|
||||
data = meta["data"] if not "metadata" in meta else meta["metadata"]
|
||||
if data:
|
||||
space.insert((meta["id"], meta["data"] if not "metadata" in meta else meta["metadata"]))
|
||||
|
||||
|
||||
@register_query(TarantoolDB)
|
||||
@ -117,24 +120,25 @@ def get_metadata(connection, transaction_ids: list):
|
||||
# asset: {"id": "asset_id"}
|
||||
# asset: {"data": any} -> insert (tx_id, asset["data"]).
|
||||
# def store_asset(connection, asset: dict, tx_id=None):
|
||||
def store_asset(connection, asset):
|
||||
def store_asset(connection, asset: dict):
|
||||
space = connection.space("assets")
|
||||
# print(f"DATA store asset: {asset}")
|
||||
try:
|
||||
if isinstance(asset, dict):
|
||||
space.insert((asset, asset["id"], asset["id"]))
|
||||
elif isinstance(asset, tuple):
|
||||
space.insert(asset)
|
||||
else:
|
||||
raise Exception(f"Unkown asset format for this query :: {asset} ::")
|
||||
except Exception as err: # TODO Add Raise For Duplicate
|
||||
print(err)
|
||||
space.insert(asset)
|
||||
# if tx_id is not None:
|
||||
# space.insert((asset, tx_id, tx_id))
|
||||
# else:
|
||||
# space.insert((asset, str(asset["id"]), str(asset["id"]))) # TODO Review this function
|
||||
except: # TODO Add Raise For Duplicate
|
||||
print("DUPLICATE ERROR")
|
||||
|
||||
|
||||
@register_query(TarantoolDB)
|
||||
def store_assets(connection, assets: list):
|
||||
space = connection.space("assets")
|
||||
for asset in assets:
|
||||
try:
|
||||
store_asset(asset=asset)
|
||||
space.insert(asset)
|
||||
except Exception as ex: # TODO Raise ERROR for Duplicate
|
||||
print(f"EXCEPTION : {ex} ")
|
||||
|
||||
@ -152,8 +156,8 @@ def get_assets(connection, assets_ids: list) -> list:
|
||||
_returned_data = []
|
||||
for _id in list(set(assets_ids)):
|
||||
asset = get_asset(connection, _id)
|
||||
_returned_data.append(asset)
|
||||
return sorted(_returned_data, key=lambda k: k["id"], reverse=False)
|
||||
_returned_data.append(tuple(asset))
|
||||
return sorted(_returned_data, key=lambda k: k[0]["id"], reverse=False)
|
||||
|
||||
|
||||
@register_query(TarantoolDB)
|
||||
|
||||
@ -51,11 +51,11 @@ def test_write_assets(db_conn):
|
||||
# conn = Connection().get_connection()
|
||||
conn = db_conn.get_connection()
|
||||
assets = [
|
||||
{'id': '1', 'data': '1'},
|
||||
{'id': '2', 'data': '2'},
|
||||
{'id': '3', 'data': '3'},
|
||||
({'id': '1', 'data': '1'}, '1', '1'),
|
||||
({'id': '2', 'data': '2'}, '2', '2'),
|
||||
({'id': '3', 'data': '3'}, '3', '3'),
|
||||
# Duplicated id. Should not be written to the database
|
||||
{'id': '1', 'data': '1'}
|
||||
({'id': '1', 'data': '1'}, '1', '1'),
|
||||
]
|
||||
|
||||
# write the assets
|
||||
@ -63,7 +63,7 @@ def test_write_assets(db_conn):
|
||||
query.store_asset(connection=conn, asset=asset)
|
||||
|
||||
# check that 3 assets were written to the database
|
||||
documents = query.get_assets(assets_ids=[asset["id"] for asset in assets], connection=conn)
|
||||
documents = query.get_assets(assets_ids=[asset[2] for asset in assets], connection=conn)
|
||||
|
||||
assert len(documents) == 3
|
||||
assert list(documents) == assets[:-1]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user