Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/requery/requery
requery - modern SQL based query & persistence for Java / Kotlin / Android
https://github.com/requery/requery
android java jdbc kotlin mysql oracle persistence postgres rxjava sql sqlite
Last synced: 24 days ago
JSON representation
requery - modern SQL based query & persistence for Java / Kotlin / Android
- Host: GitHub
- URL: https://github.com/requery/requery
- Owner: requery
- License: apache-2.0
- Created: 2015-11-14T00:45:31.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2022-03-08T12:08:29.000Z (over 2 years ago)
- Last Synced: 2024-09-28T18:02:22.318Z (about 1 month ago)
- Topics: android, java, jdbc, kotlin, mysql, oracle, persistence, postgres, rxjava, sql, sqlite
- Language: Java
- Homepage:
- Size: 2.79 MB
- Stars: 3,137
- Watchers: 81
- Forks: 247
- Open Issues: 175
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- awesome-android - requery - Compile time ORM and SQL query library for Java & Android. (Libraries / Database)
- awesome-java - requery - Modern, lightweight but powerful object mapping and SQL generator. Easily map to or create databases, or perform queries and updates from any Java-using platform. (Projects / Database)
- awesome-kotlin - Requery - A modern SQL based query & persistence. (Libraries / Database)
- awesome-android-libraries - requery
- awesome-android - requery - Compile time ORM and SQL query library for Java & Android. (Libraries / Database)
- awesome-java - requery - Modern, lightweight but powerful object mapping and SQL generator. Easily map to or create databases, or perform queries and updates from any Java-using platform. (Projects / Database)
- awesome-kotlin-android - requery - 轻量强大的ORM数据库 🔥🔥🔥🔥🔥 (开源库 / 数据库)
- awesome-java-zh - requery - 现代,轻量级但功能强大的对象映射和SQL生成器。轻松映射或创建数据库,或从任何使用Java的平台执行查询和更新。 (项目 / 数据库)
README
![requery](http://requery.github.io/logo.png)
A light but powerful object mapping and SQL generator for Java/Kotlin/Android with RxJava and Java 8 support.
Easily map to or create databases, perform queries and updates from any platform that uses Java.[![Build Status](https://travis-ci.org/requery/requery.svg?branch=master)](https://travis-ci.org/requery/requery)
[![Download](https://api.bintray.com/packages/requery/requery/requery/images/download.svg)](https://bintray.com/requery/requery/requery/_latestVersion)Examples
--------Define entities from an abstract class:
```java
@Entity
abstract class AbstractPerson {@Key @Generated
int id;@Index("name_index") // table specification
String name;@OneToMany // relationships 1:1, 1:many, many to many
Set phoneNumbers;@Converter(EmailToStringConverter.class) // custom type conversion
Email email;@PostLoad // lifecycle callbacks
void afterLoad() {
updatePeopleList();
}
// getter, setters, equals & hashCode automatically generated into Person.java
}```
or from an interface:```java
@Entity
public interface Person {@Key @Generated
int getId();String getName();
@OneToMany
Set getPhoneNumbers();String getEmail();
}
```
or use immutable types such as those generated by [@AutoValue](https://github.com/google/auto/tree/master/value):```java
@AutoValue
@Entity
abstract class Person {@AutoValue.Builder
static abstract class Builder {
abstract Builder setId(int id);
abstract Builder setName(String name);
abstract Builder setEmail(String email);
abstract Person build();
}static Builder builder() {
return new AutoValue_Person.Builder();
}@Key
abstract int getId();abstract String getName();
abstract String getEmail();
}
```
(Note some features will not be available when using immutable types, see [here](https://github.com/requery/requery/wiki/Immutable-types))**Queries:** dsl based query that maps to SQL
```java
Result query = data
.select(Person.class)
.where(Person.NAME.lower().like("b%")).and(Person.AGE.gt(20))
.orderBy(Person.AGE.desc())
.limit(5)
.get();
```**Relationships:** represent relations more efficiently with Java 8 Streams, RxJava Observables or
plain iterables. (sets and lists are supported to)```java
@Entity
abstract class AbstractPerson {@Key @Generated
int id;@ManyToMany
Result groups;
// equivalent to:
// data.select(Group.class)
// .join(Group_Person.class).on(Group_ID.equal(Group_Person.GROUP_ID))
// .join(Person.class).on(Group_Person.PERSON_ID.equal(Person.ID))
// .where(Person.ID.equal(id))
}
```**[Kotlin](https://github.com/requery/requery/wiki/Kotlin) specific support using property references and infix functions:**
```kotlin
data {
val result = select(Person::class) where (Person::age gt 21) and (Person::name eq "Bob") limit 10
}
```**Java 8 [streams](https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html):**
```java
data.select(Person.class)
.orderBy(Person.AGE.desc())
.get()
.stream().forEach(System.out::println);
```**Java 8 optional and time support:**
```java
public interface Person {@Key @Generated
int getId();String getName();
Optional getEmail();
ZonedDateTime getBirthday();
}
```**[RxJava](https://github.com/ReactiveX/RxJava) [Observables](http://reactivex.io/documentation/observable.html):**
```java
Observable observable = data
.select(Person.class)
.orderBy(Person.AGE.desc())
.get()
.observable();
```**[RxJava](https://github.com/ReactiveX/RxJava) observe query on table changes:**
```java
Observable observable = data
.select(Person.class)
.orderBy(Person.AGE.desc())
.get()
.observableResult().subscribe(::updateFromResult);
```**Read/write separation** Along with immutable types optionally separate queries (reading)
and updates (writing):```java
int rows = data.update(Person.class)
.set(Person.ABOUT, "student")
.where(Person.AGE.lt(21)).get().value();
```Features
--------- No Reflection
- Fast startup & performance
- No dependencies (RxJava is optional)
- Typed query language
- Table generation
- Supports JDBC and most popular databases (MySQL, Oracle, SQL Server, Postgres and more)
- Supports Android (SQLite, RecyclerView, Databinding, SQLCipher)
- Blocking and non-blocking API
- Partial objects/refresh
- Upsert support
- Caching
- Lifecycle callbacks
- Custom type converters
- Compile time entity validation
- JPA annotations (however requery is not a JPA provider)Reflection free
---------------requery uses compile time annotation processing to generate entity model classes and mapping
attributes. On Android this means you get about the same performance reading objects from a query
as if it was populated using the standard Cursor and ContentValues API.Query with Java
---------------The compiled classes work with the query API to take advantage of compile time generated attributes.
Create type safe queries and avoid hard to maintain, error prone string concatenated queries.Relationships
-------------You can define One-to-One, One-to-Many, Many-to-One, and Many-to-Many relations in your models using
annotations. Relationships can be navigated in both directions. Of many type relations can be loaded
into standard java collection objects or into a more efficient
[Result](http://requery.github.io/javadoc/io/requery/query/Result.html) type.
From a [Result](http://requery.github.io/javadoc/io/requery/query/Result.html)
easily create a Stream, RxJava Observable, Iterator, List or Map.Many-to-Many junction tables can be generated automatically. Additionally the relation model is
validated at compile time eliminating runtime errors.vs JPA
------requery provides a modern set of interfaces for persisting and performing queries. Some key
differences between requery and JPA providers like Hibernate or EclipseLink:- Queries maps directly to SQL as opposed to JPQL.
- Dynamic Queries easily done through a DSL as opposed to the verbose `CriteriaQuery` API.
- Uses easily understandable extended/generated code instead of reflection/bytecode weaving for
state tracking and member accessAndroid
-------Designed specifically with Android support in mind. See [requery-android/example](https://github.com/requery/requery/tree/master/requery-android/example)
for an example Android project using databinding and interface based entities. For more information
see the [Android](https://github.com/requery/requery/wiki/Android) page.Supported Databases
-------------------
Tested on some of the most popular databases:- PostgresSQL (9.1+)
- MySQL 5.x
- Oracle 12c+
- Microsoft SQL Server 2012 or later
- SQLite (Android or with the [xerial](https://github.com/xerial/sqlite-jdbc) JDBC driver)
- Apache Derby 10.11+
- H2 1.4+
- HSQLDB 2.3+JPA Annotations
---------------A subset of the JPA annotations that map onto the requery annotations are supported.
See [here](https://github.com/requery/requery/wiki/JPA-Annotations) for more information.Upserts
-------Upserts are generated with the appropriate database specific query statements:
- Oracle/SQL Server/HSQL: `merge into when matched/not matched`
- PostgresSQL: `on conflict do update` (requires 9.5 or later)
- MySQL: `on duplicate key update`Using it
--------Versions are available on bintray jcenter / maven central.
```gradle
repositories {
jcenter()
}dependencies {
compile 'io.requery:requery:1.6.1'
compile 'io.requery:requery-android:1.6.1' // for android
annotationProcessor 'io.requery:requery-processor:1.6.1'
}
```For information on gradle and annotation processing & gradle see the [wiki](https://github.com/requery/requery/wiki/Gradle-&-Annotation-processing#annotation-processing).
License
-------Copyright (C) 2019 requery.io
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.