Skip to content
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

Convenient way to create custom query #43

Open
lavrukov opened this issue Mar 6, 2024 · 1 comment
Open

Convenient way to create custom query #43

lavrukov opened this issue Mar 6, 2024 · 1 comment
Assignees
Labels

Comments

@lavrukov
Copy link
Contributor

lavrukov commented Mar 6, 2024

Nowadays, creating custom queries in YOJ is very difficult, which restrict users and forces them to dodge. We need to provide a convenient way.

What's difficult now:

  • Need to inherit from YdbRepositoryTransaction to gain access to execute
  • Need to inherit from InMemoryRepositoryTransaction to implement logic over inMemory
  • You cannot conveniently write the code in one place and then simply call it.

What we want:

  • Have a main YOJ-way to implement custom query in one file for YDB and InMemory (can split if desired)
  • Don't need to register query or touch any code around

Proposal:

  • public interface CustomQuery<PARAMS, RESULT> {}
  • Extend the Tx interface by adding the method <PARAMS, RESULT> RESULT customQuery(CustomQuery<PARAMS, RESULT> query, PARAMS params)
  • YDB interface
public interface YdbCustomQuery<PARAMS, RESULT> extends CustomQuery<PARAMS, RESULT> {
     Statement<PARAMS, RESULT> executeOnYdb(PARAMS params);
}
  • InMemory interface
public interface InMemoryCustomQuery<PARAMS, RESULT> extends CustomQuery<PARAMS, RESULT> {
      RESULT executeOnInMemory(PARAMS params, {public interfaces to InMemoryStorage});
}
  • In this case, the implementation of the custom request will be in one file
public class MySelect implements YdbCustomQuery<List<MyEntity.Id>, List<MyEntity>>, InMemoryCustomQuery<List<MyEntity.Id>, List<MyEntity>> {
     // ...
}
  • Usage:
List<MyEntity> entities = tx.customQuery(MySelect.INSTANCE, List.of(e1.id(), e2.id(), e3.id()))
  • If you don't use InMemory you can implement only YdbCustomQuery
@lavrukov lavrukov added feature New feature or request refactoring Internal improvement that does not change the API or library behavior labels Mar 6, 2024
@lavrukov lavrukov self-assigned this Mar 6, 2024
@lavrukov lavrukov added proposal and removed feature New feature or request refactoring Internal improvement that does not change the API or library behavior labels Mar 6, 2024
@lavrukov
Copy link
Contributor Author

lavrukov commented Mar 13, 2024

With this we should think about how to pass parametrs to query without batabind-magic. For example, we can do something like this QueryParametr.builder(MyEntity.class).field("myFieldTimestamp").value(Instant.now()) and use it to convert value to ydb view with all databind rules

Updated: looks like we need think about using classes from #52 for this case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant