davidmoten / rxjava2-jdbc

RxJava2 integration with JDBC including Non-blocking Connection Pools
Apache License 2.0
391 stars 41 forks source link

Is automapping to a concrete class gone? #15

Open kdurnoga opened 6 years ago

kdurnoga commented 6 years ago

I've just migrated from rxjava-jdbc to rxjava2-jdbc and noticed that automapping to a concrete class feature is missing. That was a really useful tiny little thing. Can we hope it returns at some point?

davidmoten commented 6 years ago

Yeah I did leave it out intentionally mainly because of type safety. If your constructor changes then you get no compile time indication and the complication of multiple constructors made the approach a bit unattractive to me. Probably your easiest workaround is to use an intermediate Tuple:

db.select("select name, score from person")
  .getAs(String.class, Integer.class)
  .map(x -> new Person(x._1, x._2));
kdurnoga commented 6 years ago

I see, a pity. Working with tuples becomes cumbersome when the number of columns grows and you have to explicitly specify the type of each of them. Is it possible to reintroduce this functionality, possibly in some utility class?

davidmoten commented 6 years ago

So I'll mark it as an enhancement and pop it on my backlog. The code can be copied from rxjava-jdbc but I'd like to revisit some of the validation stuff (like the existence of multiple constructors with the same number of parameters for instance).

kdurnoga commented 6 years ago

Much appreciated!

cosmin-ionita commented 4 years ago

@davidmoten I tried to fix this issue here: https://github.com/davidmoten/rxjava2-jdbc/pull/53. Please let me know your thoughts!