Partition Key in Azure - javascript

Is there any way to set the partition key of an item before inserting it using Javascript?
I've got a Win8 JS app and I want to set the PK so I can have several Cars (for example) linked to an User to be able to given an username, I can query every car that belongs to it. Also, for performance stuff, these Cars should be in the same partition, so, any way?
For example, let's say I've got an User. An User can have several properties, among them, a list of Cars. I've got two tables in Azure Table Storage, one for users and another one for cars and I want to link cars to users through User property "username" (a string) in such a way that I can create a query to select cars whose id is "username". I also want to have performance issues into account so I find desirable to have each set of cars in its own partition asigning them as PK user's username. The question is how can I do this in W8JS app.

Related

How to write data into a specific location Firebase Web

I want to write data into a specific location in the database. Let's say, I have a couple of users in the database. Each of them has their own personal information, including their e-mails. I want to find the user based on the e-mail, that's to say by using his e-mail (but I don't know exactly whose e-mail it is, but whoever it is do something with that user's information). To be more visible, here is my database sample.
Now, while working on one of my javascript files, when the user let's say name1 changes his name, I update my object in javascript and want to replace the whole object under ID "-LEp2F2fSDUt94SRU0cx". To cut short, I want to write this updated object in the path ("Users/-LEp2F2fSDUt94SRU0cx") without doing it by hand and just "knowing" the e-mail. So the logic is "Go find the user with the e-mail "name1#yahoo.com" and replace the whole object with his new updated object". I tried to use orderByChild("Email").equalTo("name1#yahoo.com").set(updated_object), but this syntax does not work I guess. Hopefully I could explain myself.
The first part is the query, that is separate from the post to update. This part is the query to get the value:
ref.child('users').orderByChild("Email").equalTo("name1#yahoo.com")
To update, you need to do something like this once you have the user id from the query result:
ref.child('users').child(userId).child("Email").update(newValue);
firebase.database.Query
A Query sorts and filters the data at a Database location so only a
subset of the child data is included. This can be used to order a
collection of data by some attribute (for example, height of
dinosaurs) as well as to restrict a large list of items (for example,
chat messages) down to a number suitable for synchronizing to the
client. Queries are created by chaining together one or more of the
filter methods defined here.
// Find all dinosaurs whose height is exactly 25 meters.
var ref = firebase.database().ref("dinosaurs");
ref.orderByChild("height").equalTo(25).on("child_added", function(snapshot) {
console.log(snapshot.key);
});

Inappropriate Redis Database Design

I have a node.js API that is responsible for 3 things:
Registering a buyer
Getting a buyer with ID
Finding the matching buyer's offer based on some criteria
Details here
Since I'm new to Redis, I started the implementation like this:
JSON.stringify the buyer and store it with SET
Store all buyer's offers as ordered set (this is for the third endpoint, which requires the offer with the highest value) - this set contains string that represents the name of a hash
Then, that hash stores strings that represent the names of sets that have certain values and a location which the user will be redirected to after these conditions have been fulfilled (buyer1_devices, buyer1_hours, etc.)
Now, here is the problem:
I need to get GET /route working. As described on GitHub page that I have provided, I have 3 parameters: a timestamp, devices, and states. I have to browse through all the sets and get the appropriate location to redirect a user to. The location is stored in a hash, but I have to browse through all the sets. Since this is probably a bad implementation, where did it all go wrong and to go about implementing this?
Note that this is a redis problem, not a node one. I need instructions on how to go about implementing this in Redis, and then I will be ready to code it in Node.
Thank you in advance
The first rule of Redis: store the data just like you want to read it.
To answer the /route query you need "filteration" on two attributes of from the buyers' offers - state and device. There is more than one way to skin that cat, so here's one: use many Sorted Sets for the offers.
Each such offers Sorted Set key name could look like this: <device>:<state> (so the example offered in the git will be added to the key desktop:CA).
To query, use the route's arguments to compose your key's name, then proceed regularly to find the highest-scored offer and resolve the buyer's details in the Hash.
Now go get that job!

JavaScript - save, store and update an array

So I am working on an application and once a user connects (via soundcloud), the following object:
{userid: userid, username: username, genre: genre, followings: followings}
is pushed into an array:
var users = [];
What I want to be able to do is for when a new user connects, to store this new user's profile object in the users array, however I want this new connector's profile to append previously logged in users in the array. So that basically the more users that log in, the bigger the array gets, creating a database of users if that makes sense?
Is there a way of doing this in JavaScript?
Thanks!
The best way to accomplish this is what you somewhat hinted at - a database. There are several databases that you could essentially store locally or in the browser cache, jStorage is one I've heard good things about. A simple search for javascript database will probably give you many other good answers.
You could also create a remote db using sqlite or any other database engine to create your container. Note that would would have to either work with an API or define some sort of content management system so you could perform the CRUD operations on the database.
The layout you provided ( {userid: userid, username: username, genre: genre, followings: followings} ) would work fairly well in a database table. You will have to define what your data types are for each of these fields, probably text or number for the user id, text for username, etc, so you can create the tables with the correct data type.
The followings field seems like it will have more than one entry, i.e. it will be a list or array, so you would probably want to create another table to house those entries and then use a primary key or some other identifier to link to it in your first table.
This question may be of some use to you: How to store a list in a column of a database table
You should create a database and store this information in it. I dont think there is a way to save users info only with JS.

How do I create a one to many relationship in Parse?

I'm trying to set up relationships in parse, but I don't know how. For instance, could I get explicit instructions on how I would link the two tables below?
Branch table consist of objectId, branchName, company, address.
Company table consist of objectId, companyName.
I would like to make a relation between Branch's company field and Company's objectId field in the manner that If I were to pull a record for a specific Branch, the string in the company field would relate to the objectId in the Company table. In real terms 1 company can have multiple branch's, but a branch can only relate to one company.
I have primarily used Access and understand how to make relationships and calls there, but cant figure out how to do it in parse. Do I need to wrote code in my main.js file? Can I do this from the data tab in my dashboard on parse.com?
Relationships in Parse are handled through the Relation data type. To make a class that uses a relation, do the following:
Go into your Parse account, open the app you want to add this class to.
Click on 'Core'.
Click on "data".
Click "Add Class:
For Class #1, call it Company.
Make sure that class is highlighted on the left side, and click "Add Col": Add the companyName as a column, and choose string as the data type.
Do these same instructions again, this time for the Branch class.
Add more columns for the branch class for branchName and address. For the company name relation, do the following:
Add a new column. For the "Select a Type" dropdown, choose "Relation";
On the middle dropdown, it will ask you what you want to relate it to, tell it which Parse class (Company), and on the right, name the column (in your case, it would be "CompanyId").

In Flux architecture how does one manage stores that store the same type of data?

I've a got a lot of user lists in my app, e.g. a list of your followers and followings, lists of followers and followings of other users, lists of users who liked a post, lists of users in search results, lists of users invited through referral program, and so on...
If I create a separate store for every list and keep whole user records there, it's possible that the same user record will be in more than one store. Keeping these records in sync between stores doesn't seem like a good idea. I could have a single store with all user records and then the other stores would only need to store IDs of users they need. Is it a good idea to do it like this or are there other better approaches?
That is exactly the way to go. If you use database storage and you make the id fields indexes you can use a JOIN to combine those fields really fast.

Categories