Best way to load JSON data into Snowflake Table using Django

Viewed 32

After perusing through a few resources, I can't quite find a solution that addresses my problem.

I'm building a Django API that users will ideally be able to post to save data locally, as well as insert into a Snowflake Table. I'm able to store that data into my local database fine, but not sure how to go about storing that data into a Snowflake Table.

It's stored into my local database as JSON format, like so:

[
   {
       "id":1,
       "player": "Lilly",
       "power": "Punch"
   }
]

Here is my views.py file

class PlayersView(APIView):
    def post(self, request):
        player = PlayerSerializer(data=request.data)
        if player.is_valid():
            player.save()
            snow = Snowflake()
            query = f"""
            create or replace TABLE {table_name} (ID 
            NUMBER(38,0) NOT NULL autoincrement start 0 increment 1, PLAYER 
            VARCHAR(16777216), POWER VARCHAR(16777216)); """
            snow.query(query, return_data=True)
            return Response(player.data, status=status.HTTP_201_CREATED)
        else:
            return Response(player.errors, status=status.HTTP_400_BAD_REQUEST)

    def get(self, request):
        players = Players.objects.all()
        data = PlayerSerializer(players, many=True).data
        print(data)
        return Response(data)

Happy to clarify if anyone has any further questions. Thanks in advance!

0 Answers
Related