This repository has been archived by the owner on Oct 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 67
enhancement: implement find on entity #1446
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lostman
force-pushed
the
maciej/1437-entity-find
branch
6 times, most recently
from
November 8, 2023 12:03
20b071a
to
7f65ed1
Compare
lostman
force-pushed
the
maciej/1437-entity-find
branch
from
November 9, 2023 21:06
0ae23a6
to
a0f158d
Compare
ra0x3
suggested changes
Nov 10, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Wow @lostman very well done 👏🏼
- Very clean and sets us up in a good spot to extend and continue the ORM work
- ⭐ ⭐⭐⭐⭐
- I left a comment about the syntax of your order clause. That's my only real feedback
- The rustdoc comments make this pretty easy to follow thankfully 🙏🏼
Co-authored-by: rashad <spam.rashad@protonmail.com>
lostman
force-pushed
the
maciej/1437-entity-find
branch
from
November 13, 2023 09:50
c26e05e
to
f1bab60
Compare
ra0x3
approved these changes
Nov 16, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🥇
deekerno
approved these changes
Nov 17, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, just left one comment about the usage of .unwrap()
.
Comment on lines
+131
to
+149
fn find(query: impl Into<QueryFragment<Self>>) -> Option<Self> { | ||
let query: QueryFragment<Self> = query.into(); | ||
unsafe { | ||
let buff = bincode::serialize(&query.to_string()).unwrap(); | ||
let mut bufflen = (buff.len() as u32).to_le_bytes(); | ||
|
||
let ptr = | ||
ff_single_select(Self::TYPE_ID, buff.as_ptr(), bufflen.as_mut_ptr()); | ||
|
||
if !ptr.is_null() { | ||
let len = u32::from_le_bytes(bufflen) as usize; | ||
let bytes = Vec::from_raw_parts(ptr, len, len); | ||
let data = deserialize(&bytes).unwrap(); | ||
Some(Self::from_row(data)) | ||
} else { | ||
None | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get rid of the .unwrap()
s here? From what I can tell, the other functions in this module don't use them.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Closes #1437.
Example usage:
This PR extends the codegen to generate field selectors for an
@entity
, e.g.:Field<T>
structs implement methods such aseq
,gt
,lt
, etc., which return aFilter<T>
, which, in turn, can be combined usingand
andor
to produce a mode complexFilter<T>
. Finally, aFilter<T>
can be ordered ascending or descending, turning it into aQueryFragment<T>
.The
find
function onEntity
takes aFilter
orQueryFragment
and fetches the corresponding object from the database, if any exists.Testing steps
CI testing. This PR includes an integration test for added functionality.
Changelog
find(query: impl Into<QueryFragment<Self>>) -> Option<Self>
toEntity
.ff_single_select
to FFI, andsingle_select
to the indexer.fuel_indexer_plugin::find
module, which contains the code for generating SQL query fragments.field_selectors
, e.g.,pub fn base_chain_height() -> Field<ChainInfo, U32>
which are used to construct queries