54 lines
2.6 KiB
Markdown
54 lines
2.6 KiB
Markdown
# solutions.bitbadger.documents
|
|
|
|
Treat PostgreSQL and SQLite as document stores from Java, Kotlin, Scala, and Groovy
|
|
|
|
## Examples
|
|
|
|
```java
|
|
// Retrieve (find) all orders (Java)
|
|
public List<Order> findOrders(Connection conn) {
|
|
Find.all(/*table name*/ "order", /*type*/ Order.class, conn);
|
|
}
|
|
```
|
|
|
|
```kotlin
|
|
// Mark an order as fulfilled (Kotlin)
|
|
fun markFulfilled(orderId: Long, conn: Connection) =
|
|
conn.patchById(
|
|
/*table name*/ "order",
|
|
/*document ID*/ orderId,
|
|
/*patch object*/ mapOf("fulfilled" to true)
|
|
)
|
|
```
|
|
|
|
```scala
|
|
// Delete orders marked as obsolete (Scala)
|
|
def deleteObsolete(Connection conn):
|
|
conn.deleteByFields(/*table name*/ "order",
|
|
/*field criteria*/ Field.equal("obsolete", true) :: Nil)
|
|
```
|
|
|
|
```groovy
|
|
// Remove the pending status from multiple orders (Groovy)
|
|
void clearPending(List<Long> orderIds, Connection conn) {
|
|
conn.removeFieldsByFields(/*table name*/ "order",
|
|
/*field criteria*/ List.of(Field.any("id", orderIds)),
|
|
/*fields to remove*/ List.of("pending"))
|
|
}
|
|
```
|
|
|
|
## Packages / Modules
|
|
|
|
* The `core` module provides the base implementation and can be used from any JVM language.
|
|
* The `solutions.bitbadger.documents` package contains support types like `Configuration` and `Field`.
|
|
* The `solutions.bitbadger.documents.java` package contains document access functions and serialization config.
|
|
* The `solutions.bitbadger.documents.java.extensions` package contains extensions on the JDBC `Connection` object, callable as extension methods from Kotlin or as static functions from other languages.
|
|
|
|
* The `groovy` module packages the extension methods so that Groovy can access them. No other packages will need to be imported; they will show up on any `Connection` instance.
|
|
|
|
* The `kotlinx` module utilizes the kotlinx-serialization project for its JSON serialization, which requires a different serializer and different function/method signatures (`inline fun <reified T> ...` vs. `fun <T> ...`).
|
|
* `solutions.bitbadger.documents.kotlinx` and `solutions.bitbadger.documents.kotlinx.extensions` packages expose a similar API to their `java` counterparts, but one designed to be consumed from Kotlin. Generally, document retrieval functions will require a generic parameter instead of a `Class<T>` parameter.
|
|
|
|
* The `scala` module extends `core` by utilizing Scala's implicit `ClassTag`s to remove the `Class[T]` parameter.
|
|
* `solutions.bitbadger.documents.scala` and `solutions.bitbadger.documents.scala.extensions` packages expose the same API as their `java` counterparts, utilizing Scala collections and `Option`s instead of Java collections and `Optional`s.
|