GET the join of two tables using a REST api - javascript

I'm fairly new to using REST to retrieve data from a database. I'm hoping to make a website which has an SQLite database on it. It seems Backbone.js will be a good fit for what I'm trying to do, and it says they interact well with a RESTful API to get data from a database. I read Understand Backbone.js REST calls to get a better understanding of how REST works.
I found this simple API https://github.com/alixaxel/ArrestDB to get data from an SQLite database.
What I am still not getting is how (if possible) to JOIN two tables.
For example, I have a Books table with BookID, Title and AuthorID, and an Authors table with AuthorID, First Name, Last Name, Age. AuthorID in the Books table is a foreign key to the Authors table.
If I use ArrestDB and go to http://api.mysite.com/books/ I'll get a JSON response of the books, and http://api.mysite.com/authors/ I'll get a JSON response from the Authors. How do I get all the books with the full information of their respective authors? This would be accomplished in SQL using a JOIN. Do I have to merge them manually in Javascript?

Related

nodejs shopify rest api pagination

I'm trying to get all products from Shopify store via rest API and with
direction=next&last_id=id
it does not return all products.
I see that there is a different way to paginate products endpoint with headers but I'm not pretty good with NodeJS and don't know how to strip strings that I receive to have only needed parameters.
Below is response example and I need only page_info from rel="next" element
<https://xxx.myshopify.com/admin/api/2022-10/products.json?limit=250&page_info=xxx>; rel="previous", <https://xxx.myshopify.com/admin/api/2022-10/products.json?limit=250&page_info=xxx>; rel="next"
any ideas?
splitting to array and search by chars

Is there any way by which we can create relationship in dynmodb

I am new to Amazon Dynamo DB, I have created a user table and address table.and I want to retrieve all users with their particular address as I have assigned user_id in address table to each address. So how can I get user info with address with one query rather than querying both table and merge after. Is their any way like in MySQL we can use JOIN?
Dynamodb is not meant for these types of queries; especially aggregation queries are not ideal. DynamoDB is mainly good for fast lookups for predefined access patterns (e.g. get all items in shopping cart for user ID X).
Since addresses are unique properties of users, you might be able to add an attribute to the user ID table. So basically you have one table with all user data and their properties, including address, that you can query by user ID.
If you need to support different queries I'd suggest you note them all down first before deciding on your data model. (E.g. get all users and sort by last name, get all users living in city X). If the data model in dynamodb is too complex to support all these access patterns you might need to change to a SQL-like db instead.
Edit: note that there are ways to model relationships in dynamodb but they are not trivial. For some examples see the link below. But as suggested above, first define your access patterns before deciding on your data model.
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-modeling-nosql-B.html

Port ~1m partial objects from Firebase to my own database (mongo)

I am looking for a way to transfer about 1 million records from my Firebase's users table to a new MongoDB's users collection I've created on my own server. I want to bring in only some data such as the age, username, and name. I would use Mongo for "fast retrieval" for display in profile pages (because profile pages require me to get the user data before even loading any of the page's data, I am looking to optimize this part as much as possible).
Enough about context. Real question -- how may I get 1m records from Firebase? I tried fetching records by doing limitToFirst(500000) and then limitToLast(500000) (to then loop through the records and store in mongo) but that's still way too big.

Loopback filter using related model field

Imagine we have two tables, session and movie in postgresql. The table session has a foreignkey to movie. How can i define a relation in movie so that i can ask for movies with filters on session. This table, for example, has a column created and i want to ask for results that has sessions after today with a custom method in Movies.js.
The table session has a foreignkey to movie, then you can define relations on both models(use a custom foreign key if necessary). Then, you can simply query data through the relation you have already defined. just use find, include, scope and where to get the data you want. If you can paste your json files for both models, it will be easy to figure it out.

How can i use REST in python django for multiple tasks

This is the first time i am using REST for any web applications.
For normal get an post and i simply call the API done in Django Rest Framework.
But i am not able to think how can i deal with situations where something more needs to be done.
Suppose I have
List of users in database and their product they have bought.
Now i have web form where if someone adds the user and then submit the button , then
I have to get the list of items bought by that user in 5 hour window
Update the row in database which says buy_succeessful to false
Then again get the list of orders from the items he has bought and then update the rows with order_successful to false
Now current in my submit actions i am doing like
call to api to add the user in override manual enrty table. This is simple post to that table
Then after getting the sucessful tehn i again call api to list of items this user has bought using Query parameters . Then i have the list
Then again i loop through the list and post to api for updating that record in datbase
and so on
I am feeling this is not right.
I have found that quite often there are some more things to do tahn just saving individual objects in database.
whats the best way to do that. DO i need to have view api for every function
Try the 3rd step of the DRF Tutorial:
http://www.django-rest-framework.org/tutorial/3-class-based-views
Here, it shows how to do a "PUT" request for updating data. And also some of the other DRF features.
Also, you can reference serializer.object which is the object instance of the django model record that you are saving to the database. This question here talks about adding extra attributes, etc... before saving to the database:
Editing django-rest-framework serializer object before save
You can also access the record post_save and there are other hooks in the framework that you can use.

Categories

Resources