spaceandtimelabs / SxT-Python-SDK

Python based SDK for interacting with the Space and Time API.
https://spaceandtime.io
MIT License
1.67k stars 57 forks source link

TypeError on INSERT DML #4

Closed nopslip closed 5 months ago

nopslip commented 1 year ago

using the following example from the docs:

    # DML
    # Use DML() to insert, update, delete and merge queries
    dml_data = SpaceAndTimeInit.DML("INSERT INTO ETH.TESTTABLE VALUES(5,'x5')", biscuit)

    dml_data_response = dml_data["response"]
    dml_data_error = dml_data["error"]

    print("Response: ", dml_data_response)
    print("Error: ", dml_data_error)

as a script like this:

from spaceandtimesdk import SpaceAndTimeSDK
from dotenv import load_dotenv
import json
import pprint
import os

load_dotenv()

# Initializing the Space and Time SDK for use.
SpaceAndTimeInit = SpaceAndTimeSDK()

biscuit = os.getenv("Z_BISCUIT")

query = f"INSERT INTO SE_PLAYGROUND.NFT_METADATA VALUES (9998, 9998, \"https://ipfs.moralis.io:2053/ipfs/QmNdgeo398VHvPgpLw6PddrhHfEQ7fkKj7KGbMt6wmWNNv/1998\", \"Alek_Common_1998\", \"Alek\", \"Common\")" 
print(query)

dml_data = SpaceAndTimeInit.DML(query, biscuit)

dml_data_response = dml_data["response"]
dml_data_error = dml_data["error"]

print("Response: ", dml_data_response)
print("Error: ", dml_data_error)

I get the following error:

INSERT INTO SE_PLAYGROUND.NFT_METADATA VALUES (9998, 9998, "https://ipfs.moralis.io:2053/ipfs/QmNdgeo398VHvPgpLw6PddrhHfEQ7fkKj7KGbMt6wmWNNv/1998", "Alek_Common_1998", "Alek", "Common")
Traceback (most recent call last):
  File "/Users/zakwolff/tools/SxT-Python-SDK/big-insert.py", line 18, in <module>
    dml_data = SpaceAndTimeInit.DML(query, biscuit)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: SpaceAndTimeSDK.DML() missing 1 required positional argument: 'biscuit'
nopslip commented 1 year ago

looking spaceandtimesdk.py it looks like maybe the docs are missing resourceId, so I tried this:

from spaceandtimesdk import SpaceAndTimeSDK
from dotenv import load_dotenv
import os

load_dotenv()

# Initializing the Space and Time SDK for use.
SpaceAndTimeInit = SpaceAndTimeSDK()

biscuit = os.getenv("Z_BISCUIT")

query = f"INSERT INTO SE_PLAYGROUND.NFT_METADATA VALUES (9998, 9998, \"https://ipfs.moralis.io:2053/ipfs/QmNdgeo398VHvPgpLw6PddrhHfEQ7fkKj7KGbMt6wmWNNv/1998\", \"Alek_Common_1998\", \"Alek\", \"Common\")" 
print(biscuit)
print(query)

dml_data = SpaceAndTimeInit.DML("SE_PLAYGROUND.NFT_METADATA", query, biscuit)

dml_data_response = dml_data["response"]
dml_data_error = dml_data["error"]

print("Response: ", dml_data_response)
print("Error: ", dml_data_error)

Which gives this:

Response:  None
Error:  400 Client Error: Bad Request for url: https://api.spaceandtime.app/v1/sql/dml

I will DM you the biscuit so you can see that is has the correct permissions.

gssakash-SxT commented 1 year ago

Adding single quotes instead of the "/" or double quotes seemed to have worked. I tried it out by creating a separate table and inserting data into it. Here's a Sample Insert statement

INSERT INTO NAMESPACE.TABLENAME VALUES (9996, 9996, 'https://ipfs.moralis.io:2053/ipfs/QmNdgeo398VHvPgpLw6PddrhHfEQ7fkKj7KGbMa6wmWNNv/1998', 'Jez_Common_1992', 'Jez', 'Rare')

nopslip commented 1 year ago

Thank you, @gssakash-SxT. I think now we just need to get the docs updated include the resourceId in the function call and we can close this.