How to get client fields data with your login key in faunadb? - faunadb

After login in faunadb, I need to make a query to get your own data in faunadb. I tried this:
const data = await faunaClient(faunaSecret).query(
q.Get(q.Ref(q.Collection('sellers'), q.Identify()))
)
In this function I have only client secret key, but not your ref. Maybe I need to make a query to get your id and join with the query to get your data...

OMG, i'm very noob in Fauna Query Languague, it's just add q.Identity inside q.Get!
const data = await faunaClient(faunaSecret).query(q.Get(q.Identity()))

Related

How can I access the AspNetUsers table's columns?

So, I have this custom user that has properties FullName and ProfileImage.
I have made everything properly and in the dbo.AspNetUsers table in the database I see that the two columns are there and are populated.
However, when I try to access those columns in the database there is nothing suggested via IntelliSense and I can't access them for the life of me.
Been reading around about it, however I could not figure out why I can't access it.
Pseudocode example
private readonly OnlineCardShopDbContext data;
...
public SomeConstructor(OnlineCardShopDbContext data){
this.data = data;
}
...
var dbUsers = this.data.Users.{none of the two columns' names here}
You can't access the columns with this query.
You should use LINQ methods like Where or Select ie with this query you can select only FullName:
var dbUsers = this.data.Users.Select(user=>new { user.FullName }).ToList();
Read more in link

How to attach multiple parameters to an API request?

I built my own simple REST API with Express and now I'm consuming it from my client (Vue.js)
So in my page I access all the data from this endpoint: GET /api/books, and it works fine
Now I also have a "sort by" button where I want to get the data by the latest entries. I don't know if that's a good way or if I have to handle this in the backend but what I do is calling the same endpoint which is GET /api/books and sorting the data to get them the right way
For ex:
sortByLatest() {
axios
.get("/api/books")
.then(res => {
const books = res.data;
const sortedBooks = books.sort((a, b) => b.createdAt > a.createdAt ? 1 : -1
);
this.books = sortedBooks;
})
// catch block
}
I do that for everything. If I need a limited number of results or a specific property from the data I have to write some logic in the axios .then block to sort or filter what I want. Is this bad practice?
But that's not my actual problem
My problem is, in addition of sorting by the latest entries, I also want to filter the results by a specific property. The problem is when I click the A button it's gonna filter the books by a specific property, and when I click the B button it's gonna sort them buy the latest entries, but not both at the same time!
And what if I want additionnal things like limit the number of results to 10, filter by other properties etc... I want to be able to create requests that ask all those things at once. How can I do that? Do I have to build that in the backend?
I saw some websites using url parameters to filter stuff, like /genre=horror&sort=latest, is that the key of doing it?
Thank you for your time

In Parse Need to fetch nested relation data in one call

I am currently working with parse in react native.
I have a query that fetches data from a collection which has a property with relation to other collection.
Now i want to fetch all these relational data in a single call rather then calling each relation separately.
Currently i get one collection then get its relational data separately in a new call.
const data1 = await result
.get("data1")
.query()
.descending("createdAt")
.find();
const data2 = data1.relation("test");
const data3 = await data2.query().find();
Now i want to fetch the relational data along with the data1 in the very first call.
I would like to know is it even possible in parse.
If yes how?
I have been trying to fetch relational data all day but no success.
Any help would really be appreciated.
I hope you're fine :)
Using relations, you will need to fetch the data with more than a single call.
Why is it necessary?
It is required because the relation type creates a new collection on the database to store the relational data.
Please, take a look at the code below:
query.find().then(results => {
for (var i = results.length - 1; i >= 0; i--) {
let object = results[i];
object.relation("data1").query().each(function(relatedObject) {
console.log(relatedObject);
/* .... */
});
}
}).catch(console.error());
Is there another option to receive the data in a single call?
Yes, there is! To configure this option, you will need to use the pointer or array type, then you will be able to use include() method and get the column value, please read more about it below:
https://docs.parseplatform.org/js/guide/#one-to-many

Find namespace records in Redis

How do I find all the records in Redis?
USER_EXCHANGE = table
USER_ID = User ID (primary key)
UID = relationship
The key is stored with the following structure
USER_EXCHANGE:USER_ID:4030:UID:63867a4c6948e9405f4dd73bd9eaf8782b7a6667063dbd85014bd02046f6cc2e
I am trying to find all the records of the user 4030...
using (var redisClient = new RedisClient ())
{
List<object> ALL_UID = redisClient.Get<List<object>>("USER_EXCHANGE:USER_ID:4030:UID:*");
}
What am I doing wrong? Thank you all for your help.
Hi as you're trying to fetch all keys matching a pattern you should use KEYS.
GET won't match patterns. by will retrieve complete full names.
Caution this is a debug function and not a production function.
doc: https://redis.io/commands/keys
Production simple solution, recommanded for you is :
store a list of your key in a LIST
USER_EXCHANGE:USER_ID:4030 => [ uid1, uid2, uid3 ....]
get list of uids for a specific user ID by getting the list.
This is a good practice in REDIS.

How to retrieve stored image in sql database in asp.net mvc3?

I have a table in my database and one of its columns is in Image data type. I can store Image in database but I can't retrieve it. I want to retrive Image for each logged in user. I used this code:
public ActionResult ShowImage()
{
var userID = GetUserID();
var advert = from ad in StoreDb.Ads where ad.UserId == userID select ad.AdImage;
return File(advert, "Image");
}
But got this error:
Error 2 Argument 1: cannot convert from 'System.Linq.IQueryable' to 'string' C:\Users\Tena\Documents\Visual Studio 2010\Projects\MvcApplication6\MvcApplication6\Controllers\Default3Controller.cs 92 25 MvcApplication6
The problem is that advert is in
System.Linq.IQueryable<>byte[]
format but File needs byte[] format. What should I do now? Any answer is helpful.
Thanks
The problem is that the LINQ query isn't being evaluated and the query as it stands could theoretically return more than one result (hence it's an IQueryable).
In fact the query doesn't look right as presumably there will be more than one advert for a particular user and I wouldn't expect the adverts to be stored according to user in any case, but I don't know anything about your data structure, so I'll just try to help you make the query work and you can refine it later.
Try changing this line:
var advert = from ad in StoreDb.Ads where ad.UserId == userID select ad.AdImage;
to this:
var advert = (from ad in StoreDb.Ads where ad.UserId == userID select ad.AdImage).FirstOrDefault();
I could give you other tips around how to do this, but try that first and see what happens.
I'not sure, this is the way to go for this problem. I usually implement a custom http handler, which expects some id (e.g. userid), connects to the database, fetches the picture and returns a stream of bytes with the correct mime type of the picture.
In the "view" i just create an image tag with the url of the http handler as image source.