I am working on sequelize to find all data with changes in attribute
const chats = Chat.findAll({attributes: [message: decrypt(message)]);
simply I wanted to return chats with the decrypted message, I didn't want to decrypt the message after finding the chat and looping through it
Related
I have been experimenting with Supabase recently and trying to make a twitter like 'replying to #user' comment feature.
So I have a database ERD attached below for reference, As you can see each comment has a userid and also a 'replyingTo' which also stores the userid of the comment which is being replied to.
Now I'm able to query individually between these two tables, So I can get the user of comment along with the comment very easily but however, When I'm trying to fetch the user profile of the comment creator and the profile of replyingTo, I get the following error -
Could not embed because more than one relationship was found for 'Comments' and 'profiles'
I'm not too experienced at PostgreSQL so I'm not sure how to do something of this scope, This is the following code I'm using currently which is giving me the error I have described above.
const { data, error } = await supabase
.from('Comments')
.select('ReplyingTo, profiles:profiles(id), profiles:profiles(id)')
.eq('commentid', cmtid)
My expected outcome is to get the comment, the user profile who created the comment and also the profile of the user who is receiving a reply.
Thank you for your time and patience.
As the error says, the problem is that you have two relationships between profiles and Comments. For this case, you'd need to disambiguate(which foreign key column you want to use for the join) as specified in the PostgREST docs. For the supabase js client, it should be like:
const { data, error } = await supabase
.from('Comments')
.select('ReplyingTo, profiles1:profiles!userid(*), profiles2:profiles!ReplyingTo(*)')
.eq('commentid', cmtid)
I am trying to make a firebase database call to retrieve all row of one particular column in the firebase database of my app and display it in a textbox in my flutter app.
That is, to retrieve all phone numbers in the Users table.
For instance, in SQL we can do like this:
SELECT (PhoneNumers) FROM Users
I am new in flutter/dart, I need some help.
Its really easy.
First of all, setup and initialize firebase in you project. Then make a function and create an instance of firestore like this
FirebaseFirestore firestore = FirebaseFirestore.instance;
Then make something called Collection reference:
CollectionReference users = await firestore.collection("users").get().then((querySnapshot) {
querySnapshot.docs.forEach((doc) {
print(doc["PhoneNumber"].toString())
});
This will grab every collection from Users, loop over them and then print out the document PhoneNumber to console. There is no way to just get a single document field from firestore. It might seem weird, but its quite useful at times. Right now, you have access to every document field of every user of your app.
I've been trying to implement live messaging in my application and I cannot seem to think of a convenient data structure inside Firestore. My current structure looks like this:
collection("conversations").document(id).collection("messages")
Each document holds two attributes user1 and user2 with nicknames of contributors to the conversation. Each document also owns a collection called messages which holds documents where each represents a single message sent with some info.
What I'm trying to do next is to check if the conversation already exists, if not then create it. The problem for me is write a correct query to find out if it exists.
My first idea was: create users array instead which holds nicknames of users and then simply query:
db.collection("conversations").whereField("users", in: ["username1", "username2"])
Problem with this is that it means "where users contains username1 OR username2", but I need it to contain "username1 AND username2".
I tried to be smart and chain the whereField function as following:
db.collection("conversations").whereField("users", arrayContains: "username1").whereField("users", arrayContains: "username2")
Turns out that you cannot use arrayContains more than once in a single query.
After that I came back to the structure as displayed on the screenshot with user1 and user2 and ran a new query:
db.collection("conversations").whereField("user1", isEqualTo: user).whereField("user2", isEqualTo: friend)
This query is ran in a function where user and friend are string parameters holding nicknames of both sender and receiver of the message we're currently sending. Imagine you are sending a message, user is always going to be your nickname and friend the receiver's one. The problem with the query is that you're nickname might be saved under user1 or user2 and receiver's nickname aswell. In either of those situations the conversation exists. How would I have to change the query since I don't know in an advance who will have which position in the query aswell as in Firestore. Running the last query that I included twice while switching user and friend parameter seems very unconvenient.
Any tips or solutions to progress in this problem will be much appreciated!
I am new to mongo. While making a application i came across a weird requirement.
I have collection Document and UserData. The schema for both is given below.
Document {
data : String ,
id : number,
lockedBy : Users
}
Users{
name : String,
email : String,
id : String
}
So here basically a user can lock a document for himself and no one can access it.
The problem here is i dont want to save entire user data in the Document as it will create a lot of redundant data. I want to save the id of the user.
But on the ui side the requirement is to give entire user object(containing id , name , email) as the value of lockedBy.
What I do is i save lockedBy as string with the id of user. Then while fetching i replace the lockedBy with user data by making another call to database and getting the user data based on id.
With increasing number of fetching and saving api i have to make transformation in lot of places. Is there any way to this in a different way. Where i dont have to write the transformation code for lockedBy to change is string to UserData and vice versa.
keep user_id in the Schema,
while sending the response object add users in it, by retrieving it from the the db.
I'm trying to set up a webpage that communicates with a Moodle page. I need different data from a database activity and want to create new entries. Note that I am not talking about the SQL database in BG, it is the activity database in courses.
The information should be retrieved/transferred via the REST API, an HTML POST Request. My problem is that I don't know how to add a new record to the database activity because I cannot transfer the data array. Only the first parameter given appears in my database.
E.g. i tried ...&wsfunction=mod_data_add_entry&databaseid=10&data[0][fieldid]=66&data[0][value]=12&data[1][fieldid]=67&data[1][value]=test
And many other combinations. Always only the first parameter is shown in the database.
The docs tell me this (Pseudocode):
//The fields data to be created
list of (
object {
fieldid int //The field id.
subfield string Default to "" //The subfield name (if required).
value string //The contents for the field always JSON encoded.
}
)
Alternatively:
REST (POST parameters)
data[0][fieldid]= int
data[0][subfield]= string
data[0][value]= string
I cannot find anywhere else something called a "subfield".
Any ideas?
Okay, found it. You have to put your values in "", unless they are not a number. Seems like there is a connection with this special activity because you don't have to do it elsewhere.