ORM using the API declared in hex/hexql
Use the QueryLanguage
helpers by creating a static import for them.
import static hex.ql.QueryLangauge.*
Instantiate your repo instance
Repository<Person> repo = new PersonRepository();
Start querying!
repo.where(Person::getLastName, is("Newton"))
.forEach(p -> System.out.println(p.getFirstName() + " " + p.getLastName());
Some things to keep in mind:
-
Queries are lazy. That means that just executing:
repo.where(Person::getLastName, is("Newton"))
... will not execute the query on the database. It is only when you call a resolution expression that the database will be queried. For example, it was not until we called
forEach()
in the above sample that the database was queried and we started retrieving results. -
The
java.util.stream.Collectors
work well onQuery
instances too, sinceQuery
implementsjava.util.Stream
. So to get a list ofQuery
results.List<Person> newtons = from(people).where(Person::getLatsName, is("Newton")).collect(Collectors.toList());
The Repo ConnectionManager
looks for the hex_repo.properties
file in the root of your classpath. For now it's got a
pretty basic config for connecting to a database.
driver: org.postgresql.Driver
url: jdbc:postgresql:hex_repo_test
username: pg
password:
I would love some contributers but keep in mind the following:
It's a pretty common practice for a lot of JVM based ORMs out there. I'd like to see something that doesn't do it. At first I tried to do zero byte manipulation, but that seemed excessively idealistic. I'm breaking down and allowing the creating of subclasses off of model objects.
All mapping metadata should be able to be declared outside of the "Model" classes.
NOTE: As of now I still haven't figured out how I'm going to declare custom mapping of fields to columns.
This is pretty much already done now. Checkout hex.repo.streams.RepositoryStream
. As of this writing there ar still a number of methos that need implementing, but the groundwork is all there.
e.g. Calling Stream#filter
on a Repository Query will translate itself to an addition to the where clause.
That being said, here's the normal contributing ramble:
- Fork it (
http://github.com/thejayvm/hex/fork
) - Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
- If fixing reported issues please use
hub pull-request
to make a PR with the same ID as the issue. (https://github.com/github/hub)