-
-
Notifications
You must be signed in to change notification settings - Fork 5
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[db] The 'order_by' clause is not taking effect. #1191
Comments
Hi, this might be a misunderstanding. The There are few ways you can achieve something similar. Some ideas:
Anyway in case you meant actual property QueryBuilder.insert().nodes().aliases("root").query(),
QueryBuilder.insert()
.nodes()
.values([[["id", 5]], [["id", 3]], [["id", 7]]])
.query(),
QueryBuilder.insert().edges().from("root").to(":1").query(),
QueryBuilder.select()
.ids(
QueryBuilder.search()
.from("root")
.order_by(DbKeyOrder.Asc("id"))
.query(),
)
.query(), and the result of the last query was: {"result":7,"elements":[{"id":3,"from":null,"to":null,"values":[{"key":{"String":"id"},"value":{"I64":3}}]},{"id":2,"from":null,"to":null,"values":[{"key":{"String":"id"},"value":{"I64":5}}]},{"id":4,"from":null,"to":null,"values":[{"key":{"String":"id"},"value":{"I64":7}}]},{"id":1,"from":null,"to":null,"values":[]},{"id":-7,"from":1,"to":4,"values":[]},{"id":-6,"from":1,"to":3,"values":[]},{"id":-5,"from":1,"to":2,"values":[]}]} When I flipped the order_by to {"result":7,"elements":[{"id":4,"from":null,"to":null,"values":[{"key":{"String":"id"},"value":{"I64":7}}]},{"id":2,"from":null,"to":null,"values":[{"key":{"String":"id"},"value":{"I64":5}}]},{"id":3,"from":null,"to":null,"values":[{"key":{"String":"id"},"value":{"I64":3}}]},{"id":1,"from":null,"to":null,"values":[]},{"id":-7,"from":1,"to":4,"values":[]},{"id":-6,"from":1,"to":3,"values":[]},{"id":-5,"from":1,"to":2,"values":[]}]} Both are correct. The elements with an |
Understood, I was using the internal database ID for sorting, which seems to be an incorrect approach. Sorting by other fields works normally. Thank you! |
Additionally, I have another question. How can I avoid duplicate insertion of edges in the code |
That would be the use case for the // This will insert new node only if "root" does not exist yet
QueryBuilder.insert().nodes().aliases("root").query()
// This will insert 3 new nodes only when the search query in ids does not yield any ids
QueryBuilder.insert()
.nodes()
.ids(
QueryBuilder.search()
.from("root")
.where()
.node()
.and()
.not()
.ids("root")
.query(),
)
.count(3)
.query()
// This will insert edges only when there are not any yet
QueryBuilder.insert()
.edges()
.ids(QueryBuilder.search().from("root").where().edge().query())
.from("root")
.to(":1")
.query() I have tested these queries and they are re-entrant meaning they won't insert duplicates when run repeatedly. Of course you would likely want to fine tune the conditions etc. I have also found a bug in that server does not replace ":1" with previous query when this alias is found in the insert ids. Eg. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
The text was updated successfully, but these errors were encountered: