-
Hello everyone, First of all, I apologize for being so persistent, but I really like SQLPage and I find myself constantly thinking about how to push its limits. This time, I want to ask about how you would use SQLPage to interact with an external REST API, such as https://pokeapi.co/, to create a webpage based on its content. Firstly, what I have thought of is to differentiate between backend and frontend. On the Frontend, we would have SQLPage, which, depending on the Pokémon requested, would perform insertions into a table. On the backend, we would have a backend in any programming language, which would make calls to the API by constantly listening to that table and would delete or update the rows to only make a call once, in addition to inserting what is received from the API into another table, or the same one. This does not worry me (in terms of how to do it) but it seems slow (because it requires 2 differentiated environments linked through database tables), unreliable and I don't like the idea of mixing another programming language (because then, SQLPage miss the point of why it exists). So, I was thinking about how to make the call directly from SQLPage, insert the data that I want or in the order that I want from the JSON returned (with the functions provided by the various DBMSs) and load that information. How would you do it? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
Hi !
|
Beta Was this translation helpful? Give feedback.
-
@Ajotah98 : I posted an example here: https://replit.com/@pimaj62145/SQLPage-external-api-fetch?v=1 insert into friends (user_name, friend_name)
select people.value->>'name', friends.value->>'name'
from json_each(sqlpage.exec('curl', 'https://mocki.io/v1/83a2365c-9392-4a3d-8953-9b3ad4f3acb1')) people
join json_each(people.value, '$.friends') friends; This is the SQLite syntax to iterate over json data. Depending on your database, the syntax may be different:
|
Beta Was this translation helpful? Give feedback.
-
Just for cross-reference in case someone else stumbles on this topic, here are the previous discussions on this topic: |
Beta Was this translation helpful? Give feedback.
-
🎉This is implemented in v0.20.3 : |
Beta Was this translation helpful? Give feedback.
@Ajotah98 : I posted an example here: https://replit.com/@pimaj62145/SQLPage-external-api-fetch?v=1
This is the SQLite syntax to iterate over json data. Depending on your database, the syntax may be different: