I'm using the requests module to post in Google Sheets through sheety under three different columns: First Name, Last Name, Email.
I provided the JSON data to upload in this way:
data = {
"user":{
"first name": first_name,
"last name": last_name,
"email": email1,
}
}
The column under the Email label in the sheet is the only one which was uploaded correctly, while the others remain blank.
I understood that I'm not giving the proper key value for a label with a space inside, i.e. First Name, Last Name, but I don't understand how to provide the key correctly.
As per the Sheety documentation, you have to use CamelCase for two words with space:
data = {
"user": {
"firstName": first_name,
"lastName": last_name,
"email": email1
}
}
Related
Referring to the default sample schema mentioned in https://hasura.io/hub/project/hasura/hello-world/data-apis i.e. to the following two tables:
1) author: id,name
2) article: id, title, content, rating, author_id
where article:author_id has an array relationship to author:id.
How do I make a query to select authors who have written at least one article? Basically, something like select author where len(author.articles) > 0
TL;DR:
There's no length function that you can use in the Hasura data API syntax right now. Workaround 1) filter on a property that is guaranteed to be true for every row. Like id > 0. 2) Build a view and expose APIs on your view.
Option 1:
Use an 'always true' attribute as a filter.
{
"type": "select",
"args": {
"table": "author",
"columns": [
"*"
],
"where": {
"articles": {
"id": {
"$gt": "0"
}
}
}
}
}
This reads as: select all authors where ANY article has id > 0
This works because id is an auto-incrementing int.
Option 2:
Create a view and then expose data APIs on them.
Head to the Run SQL window in the API console and run a migration:
CREATE VIEW author_article_count as (
SELECT au.*, ar.no_articles
FROM
author au,
(SELECT author_id, COUNT(*) no_articles FROM article GROUP BY author_id) ar
WHERE
au.id = ar.author_id)
Make sure you mark this as a migration (a checkbox below the RunSQL window) so that this gets added to your migrations folder.
Now add data APIs to the view, by hitting "Track table" on the API console's schema page.
Now you can make select queries using no_articles as the length attribute:
{
"type": "select",
"args": {
"table": "author_article_count",
"columns": [
"*"
],
"where": {
"no_articles": {
"$gt": "0"
}
}
}
}
Let's say that the users can add posts on a public board.
Should the post objects contain not only the uid of the user that created the post and the actual post, but also the additional information that would be displayed in the UI to other users such as the poster's first name, last name etc.?
If this information would not be included, there would be needed one more call to retrieve them.
I think it is problematic when an user decides to change his/her name for example, because that would mean to update all the posts created by the respective user.
What is your opinion? Thanks.
Edit:
To show an example, which would be better between the two versions of post:
"post_id": {
"firstName": "Adam",
"lastName": "Smith",
"byUser": "uid",
"message": "message1"
}
or
"post_id": {
"byUser": "uid",
"message": "message1"
}
where
"user_uid": {
"firstName": "Adam",
"lastName": "Smith"
}
If you want to have the name next to the user's post then use this:
"post_id": {
"name": "Adam Smith",
"byUser": "uid",
"message": "message1"
}
This way when retrieving a list of posts, you do only one call. Also add a users node in the database that will contain the list of users:
"users" :{
"name": "Adam Smith",
"email": "email#gmail.com"
}
This way when a user wants to update his name, it will be updated in the list of users and update it also in the post_id. Thus when retrieving the posts of a user in a Home Activity(that contains all posts) you will also get the updated name.
this might help: https://firebase.googleblog.com/2013/04/denormalizing-your-data-is-normal.html
I want to avoid duplicated keys in different documents.
For example, in the document 1 I have this:
{
"user": "myuser",
"email: "a#a.com"
}
In the document 2 I have:
{
"user": "myuser2",
"email: "b#b.com"
}
And in document 3 I have:
{
"user": "myuser",
"email: "c#c.com"
}
I don't want to be possible to create document 3, as the user key has the same value. Is possible to do this with database rules?
Thanks.
add the document with user as a unique ID like that
db.collection("Your Collection").document(user).set(Your Object)
"user" is the user field of your object
one solution could be using email address as an unique id for your document, because email addresses are always unique:
db.collection("collection/" + userObject.email).set(userObject)
or
db.collection("collection").doc(email).set(user object)
I am very beginner to AWS DynamoDB, I want to scan the DynamoDB with SENDTO.emailAddress = "first#first.com" as FilterExpression.
The DB Structure looks like this
{
ID
NAME
MESSAGE
SENDTO[
{
name
emailAddress
}
]
}
A Sample Data
{
ID: 1,
NAME: "HELLO",
MESSAGE: "HELLO WORLD!",
SENDTO: [
{
name: "First",
emailAddress: "first#first.com"
},
{
name: "Second",
emailAddress: "second#first.com"
}
]
}
I want to retrieve document that match emailAddress. I tried to scan with filter expression and here is my code to retrieve the data. I am using AWS Javascript SDK.
let params = {
TableName : "email",
FilterExpression: "SENDTO.emailAddress = :emailAddress",
ExpressionAttributeValues: {
":emailAddress": "first#first.com",
}
}
let result = await ctx.docClient.scan(params).promise();
In order to find the item by sendto attribute, you need to know both name and emailAddress attribute value. DynamoDB can't find the data by just one of the attributes in an object (i.e. email attribute value alone).
CONTAINS function can be used to find the data in List data type.
CONTAINS is supported for lists: When evaluating "a CONTAINS b", "a"
can be a list; however, "b" cannot be a set, a map, or a list.
Sample code using Contains:-
var params = {
TableName: "email",
FilterExpression: "contains (SENDTO, :sendToVal)",
ExpressionAttributeValues: {
":sendToVal": {
"name" : "First",
"emailAddress" : "first#first.com"
}
}
};
If you don't know the value of name and emailAddress attribute, you may need to remodel the data to fulfill your use case.
I think that you should create two tables for users and for messages.
The user table has partition_key: user_id and sort_key: email and a field with an array of his messages ids.
The message table has partition_key: message_id and a field with an array of users ids.
When you will get the array of users ids you can use BATCH GET query to get all users of one message.
When you will get the array of message ids you can use BATCH GET query to get all messages of one user.
If you want to get one user by email you can use QUERY method.
Docs
I am trying to use the Firebase orderByChild() function per the documentation example but the queries are not coming back filtered or sorted.
Here is the sample data structure:
"notifications": {
"001": {
"member_id": "abc123",
"created_at": 1424357680681,
"new": true,
"first_name": "Jon",
"last_name": "Snow",
"message": "likes your photo"
},
"002": {
"member_id": "abc456",
"created_at": 1424357680681,
"new": true,
"first_name": "Clark",
"last_name": "Kent",
"message": "likes your comment"
}
}
When a user logs in, I want to query the notifications hash for only the notifications with a member_id that matches the current user's id.
I have tried both versions with and without the "child_added".
Option A:
ref.orderByChild("member_id").equalTo(memberId);
Option B:
ref.orderByChild("member_id").equalTo(memberId)
.on("child_added", function(data) {
console.log("new child id = " + data.key());
});
When I query the notifications hash, the query returns an array of all of the notifications. They are neither limited to the member_id of the current user, nor sorted by member_id. (I can delete the member_id key entirely and the notification will still be returned).
I can always filter the returned array by member_id in-app, but I would really like to get the query working per the documentation.
Any help is appreciated!
I found the problem!
I was under the impression that you could add the query modifiers in place.
I was doing:
ref.orderByChild("member_id").equalTo(memberId);
var sync = $firebase(ref);
It should actually be:
var sync = $firebase(ref.orderByChild("member_id").equalTo(memberId));
Most likely your memberId variable is a number, while you're storing the corresponding value as a string.
If you store numbers as a string, this query won't give any results:
ref.orderByChild("member_id").equalTo(456)
But this one will:
ref.orderByChild("member_id").equalTo('456')
The easiest fix in your snippet of code is coercing the memberId to a string like this:
ref.orderByChild("member_id").equalTo(''+memberId)
See this fiddle for a working sample: http://jsfiddle.net/695rf0vy/