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