i'm making a chat app using firebase. For each document that contains any name, i'm creating it as auth.currentUser.displayName. So for example, each message in the chat is a document created as:
sender: currentUser?.displayName!,
avatar: currentUser?.photoURL!,
content: message,
time,
About changing the username, i know how to do it, but if i change my username, i would have to access all the documents of every user that contains my name and change it too. Is there a better way to do it? Like, instead of auth.currentUser.displayName, i use something like user XYZ.displayName, and if user XYZ changes its name, it will also change in every other document.
Thanks in advance
But if i change my username, i would have to access all the documents
of every user that contains my name and change it too.
This is indeed a consequence of the data modelling in a NoSQL database, where you duplicate data instead of normalizing it as you would do in a SQL database.
Is there a better way to do it?
Apart from mimicking an SQL database (having the user name in a unique user document and fetching this doc each time you want to display this user name - i.e. you mimic an SQL join) there is no other way than updating each doc containing the value of the user name.
Mimicking an SQL database means that each time you want to display a message in the chat you need to fetch the document containing the user name value (not good for cost and performance). Keeping the denormalized approach means that you need to update all the corresponding message documents only when a user name change. So, depending on the frequency of the user names updates, you can decide which one is the best.
Like, instead of auth.currentUser.displayName, i use something like
user XYZ.displayName, and if user XYZ changes its name, it will also
change in every other document.
Basically this will not make any difference since you'll have to update all the docs containing the (previous) user name.
Related
I have an app, in which a user can create a session for themselves. By a session I mean , it has a title and a frequency (For Example - {"title": "homework" , "frequency": "MWF"} where MWF is Monday,Wednesday,Friday). I want to store the session frequency and title in my firestore database in such a way that when the user creates a new session, i fetch from firestore the possible clashes -
For example - if the user is creating a session called "homework" and an "homework" already exists then , I can tell them that a session by that name already exists OR If a user is creating a session with frequency" MTS and already has a session with the frequency MWF, then I have to tell the user that there is a possible clash. Same with creating TTF and MWF already exists, then I have to inform the user of a possible clash.
My question, is that how can i do it, given the fact that I use the firestore database?
The easiest thing to do is simply query for any documents that would conflict before you allow the user to add the conflicting document. So, if you want to find a conflict where title="homework", you would query for conflicts first:
firestore.collection("your-collection").where("title", "==", "homework")
// then check the results to see if there was a match
Firestore doesn't provide a way to stop duplicate field values in a collection, so it's still possible that somehow a user could add a conflicting document. If you need to force uniqueness of a field value within a collection, that requires much more work, which might not be worthwhile for your case.
I'm creating a React application where my data has the following structure:
interface BookCase {
id: number;
bookShelves: BookShelf[];
}
interface BookShelf {
id: number;
}
Every bookcase and every bookshelf has an id property. I use this for the key attribute and for locating a bookshelf inside the bookShelves array. The id is generated in the backend by the database (With a BigSerial in PostgreSQL) on save.
I now want to create a new bookcase inside my frontend without immediately saving it to the backend. First I want to work with it, perform some operations on it (e.g. place a book on the shelf), and afterwards send the whole batch of changes with the new entities to the backend where it will then be persisted in the database.
Of course I do not yet have an id, although I need one to work on the bookcases. Should I rewrite my application to also accept null for id (I would prefer not to)? Should I just randomly create an temporary id, possibly having duplicates with the ids already present in the database (or for example use a negative value like -1)? Then I would need to replace all the ids afterwards after it has been saved to the database.
With UUIDs I could generate it on the frontend, but I guess there also has to be a common pattern to work with just incrementing integers as the id.
I do not think there is a clear answer here.
Essentially you have a object-relational mapping and there are various ways to handle it. Entity Framework for example just uses the default for the data type. So if the entity does not exist yet the ID will be 0 and any persisted entities have values starting at 1 so there are no conflicts.
One way i usually handle saving is by returning the updated record from the request, so you just replace your old one with that and you have the correct ID value applied automatically.
In our web application we want to use DB2 row level access control to control who can view what. Each table would contain a column named userId which contain the user id. We want log-in users be able to see only row's usereId column with theirs id. I have seen db2 permission examples using DB2 session_id or user, for example taking DB2 given Banking example :
CREATE PERMISSION EXAMPLEBANKING.IN_TELLER_ROW_ACCESS
ON EXAMPLEBANKING.CUSTOMER FOR ROWS WHERE BRANCH in (
SELECT HOME_BRANCH FROM EXAMPLEBANKING.INTERNAL_INFO WHERE EMP_ID = SESSION_USER
)
ENFORCED FOR ALL ACCESS
ENABLE;
Our table gets updated dynamically hence we don't know what row get added or deleted hence we don't know what are all the user Id in the table.
At any given time, different user would log-on to the web to view information retrieve from the tables, the permission declaration above only take SESSION_USER as the input, can I change it to something like Java function parameter where one can pass arbitrary id to the permission? If not then how do I handle different log-in users at arbitrary time? Or do I just keep changing SESSION_USER dynamically as new user login (using "db2 set" ??)? If so then is this the best practice for this kind use case?
Thanks in advance.
Since the user ID in question is application-provided, not originating from the database, using SESSION_USER, which equals to the DB2 authorization ID, would not be appropriate. Instead you might use the CLIENT_USERID variable, as described here.
This might become a little tricky if you use connection pooling in your application, as the variable must be set each time after obtaining a connection from the pool and reset before returning it to the pool.
Check out Trusted Contexts, this is exactly why they exist. The linked article is fairly old (you can use trusted contexts with PHP, ruby, etc. now).
I have a dataset where users report health symptoms once per week. Users can also opt to report for other members of their households. The data come in a Users file and a Household file and are linked by user_id. The household members are missing values for state and zip. I am struggling to find a way to populate these missing values from the data of the primary user reporting for them.
Essentially I want to say: if state variable is blank, populate with the data from the reporting user whose user_id variable is the same.
I had found a post that mentioned the xfill command (http://www.sealedenvelope.com/stata/xfill/) which I thought would address my needs, but I continually get an error state is not constant within user_id. I've had no luck researching this error to determine why it is occurring.
Can anyone explain why xfill does not work, or suggest an alternative approach?
Presumably this is happening because you have users who move across states, while xfill only works for static variables. To verify this is the case, tag them like this:
capture ssc install egenmore
bys user_id: egen states = nvals(state)
edit if states>1
This will show you users who report living in more than one state.
If you have a date of report variable, you might be able to use carryforward to deal with this like this:
bys user_id (report_date): carryforward state, gen(state2)
I have been trying to create a select-your-picture-and-upload function of a normal user's profile in Delphi 7, but I am running in some problems.
Basically what I want is the following:
User uploads a picture from a folder (which I have achieved through a normal
OpenPictureDialog component)
Said picture gets stored in a database, which is where I'm stuck.
The database is a normal access database.
The table has a unique ID to identify the members and next to that is the picture of each member on the "Picture field" (which is set as a BLOB object).
So in other words my question is the following:
What components do I need to use in order to save a picture to a specified place in my database?
I have found some random code in the net but I'm running into troubles understanding what it does.
ADOQuery.SQL.Text := 'SELECT PictureField FROM YourTable';
ADOQuery.Open();
ADOQuery.Edit();
TBlobField(ADOQuery.FieldByName('PictureField')).LoadFromFile('PathToPictureFile');
ADOQuery.Post();
You can use imageEn component.
Web Site url to get information and download trial