Quarkus PanacheEntityBase query with IN - quarkus

I have a customer entity of type PanacheEntityBase. I would like get all customers by ids
I can get it with customer.list("customerId", id) in a loop. I dont think its a good solution. I prefer using IN. Please suggest how to use IN with PanacheEntityBase

I solved the problem with customerEntity.list("customerId IN (?1)", customerIds);
Note: customersids must be a java list (Array did not work)

Related

spring reactive: check if user exists or not

I am using spring reactive and need to check weather user with particular
data exists or not and currently I am not able to solve that problem.
Considering the scenerio
In my document I need to check if username or email already exists or not
In RDBS I can do it as
select count(id)>0 where username='abc' or email='abc#idx.com'
while using spring reactive which returns either mono or flux the simple most query becomes
{$or:[{"username":"abc"},{"email":"abc#idx.com"}]} which will return flux but I need boolean to verify from db
On solution is that I can get Flux<User> and the iterate it using form loop but then using ' result.block()' whick will block some other threads and therefore not a clean solution.
Is there any clean solution or any Idea how to solve this.
Thanks
Edit One possible solution can be creating unique indexing in monogdb, that I am using right now. But if there is any other solution please let me know
Using Spring Data MongoDB, you can use something like below:
public interface ReactiveUserRepository extends ReactiveSortingRepository<User, Long> {
Mono<User> findByUsernameAndEmail(String username, String email);
}
Find a single entity for the given criteria. It completes with IncorrectResultSizeDataAccessException on non-unique results.
You can refer to the complete syntax here:
https://docs.spring.io/spring-data/mongodb/docs/current/reference/html/

How to use stub.CreateTable in Hyperledger programming

A chaincode based on Hyperledger uses stub.PutState and stub.GetState to interact with the data base. However, if I have a struct with more than one attibutes, for example :
person {
"ID": "123",
"firstname":"joe",
"lastname":"doe",
"age":"34",
}
Then if I want to update the age, what arguments should I send to the method ?
I noticed that there is stub.CreateTable method which seems to be more convenient for my case, however, I couldn't find any document or explication about how to use this method. Would you please give me a link to the document or some brief explication please ?
Thanks.
You can not change anything on the ledger.The only way you can update the person infomation is insert a new line to cover the old.
Here is a chaincode where a table is used. You can see how to create a table, insert, delete rows :
https://github.com/hyperledger/fabric/blob/master/examples/chaincode/go/asset_management_interactive/asset_management.go#L51-L54
Hope this helps
Please look at the cases in the switch statement in the invoke method of this code. I believe the case "replaceRowTableOne": case has some insight as to what you're trying to do.
https://github.com/christo4ferris/fabric-docs/blob/master/bddtests/chaincode/go/table/table.go

How to massive delete in php-activerecord where id NOT in list?

I'm running a CodeIgniter application with PHP-Activerecord installed and I need to do a massive delete. The PHP-AR library supports massive update and delete, but the function only takes the ids that you want to delete/update. I'm trying to do a massive delete where the ids are NOT in the list.
delete from table where id not in (1,2,3...,500)
Unfortunately, the PHP-Activerecord website is of no help, and their forums are so horribly built (no search... seriously?) that I'm truly stuck.
edit: Please note, CodeIgniter's built-in ORM is not the same as PHP-Activerecord. Just thought I'd clarify that.
A bit late but this may help someone else. In PHPActiveRecord, do it in this way:
$ids_to_delete = array(1,2,3);
YourModel::delete_all(array('conditions' => array('id NOT IN (?)', $ids_to_delete)));
Ref: http://www.phpactiverecord.org/docs/ActiveRecord/Model#methoddelete_all
SInce active record is actually build string query with function, you can use this method:
- make your list as string
- make this query : $this->db->where('id not in',$string)->delete('table')

DBSet and dynamic sql expressions

So I have Products class that represent the products table.
To get all the records I do:
db.Products.ToList()
And I have a string like this:
String queryString = "mp=5 AND optic=TRUE AND price=500";
My question is how can I use this string to filter Products? Where func only accept lambda expressions..
Thanks
I'm not sure if it's still supported or not, but you can use Dynamic LINQ to allow you to add 'text' based expressions as you require. See:
http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx
http://pranayamr.blogspot.com/2011/04/dynamic-query-with-linq.html
You may also want to think about using a Predicate builder to do the same job more declaratively. There are a few out there, but one that I've used with great success is the albahari one:
http://www.albahari.com/nutshell/predicatebuilder.aspx
hope this helps..
You can execute Raw SQL against the DbSet and return a strong typed list. For detail, please refer to this blog post by EF team.

How can I force a complete load along a navigation relationship in Entity Framework?

Okay, so I'm doing my first foray into using the ADO.NET Entity Framework.
My test case right now includes a SQL Server 2008 database with 2 tables, Member and Profile, with a 1:1 relationship.
I then used the Entity Data Model wizard to auto-generate the EDM from the database. It generated a model with the correct association. Now I want to do this:
ObjectQuery<Member> members = entities.Member;
IQueryable<Member> membersQuery = from m in members select m;
foreach (Member m in membersQuery)
{
Profile p = m.Profile;
...
}
Which halfway works. I am able to iterate through all of the Members. But the problem I'm having is that m.Profile is always null. The examples for LINQ to Entities on the MSDN library seem to suggest that I will be able to seamlessly follow the navigation relationships like that, but it doesn't seem to work that way. I found that if I first load the profiles in a separate call somehow, such as using entities.Profile.ToList, then m.Profile will point to a valid Profile.
So my question is, is there an elegant way to force the framework to automatically load the data along the navigation relationships, or do I need to do that explicitly with a join or something else?
Thanks
Okay I managed to find the answer I needed here http://msdn.microsoft.com/en-us/magazine/cc507640.aspx. The following query will make sure that the Profile entity is loaded:
IQueryable<Member> membersQuery = from m in members.Include("Profile") select m;
I used this technique on a 1 to many relationship and works well. I have a Survey class and many questions as part of that from a different db table and using this technique managed to extract the related questions ...
context.Survey.Include("SurveyQuestion").Where(x => x.Id == id).First()
(context being the generated ObjectContext).
context.Survey.Include<T>().Where(x => x.Id == id).First()
I just spend 10mins trying to put together an extention method to do this, the closest I could come up with is ...
public static ObjectQuery<T> Include<T,U>(this ObjectQuery<T> context)
{
string path = typeof(U).ToString();
string[] split = path.Split('.');
return context.Include(split[split.Length - 1]);
}
Any pointers for the improvements would be most welcome :-)
On doing a bit more research found this ... StackOverflow link which has a post to Func link which is a lot better than my extension method attempt :-)

Resources