All Projects → t9t → jooq-postgresql-json

t9t / jooq-postgresql-json

Licence: Apache-2.0 License
jOOQ support for PostgreSQL json & jsonb

Programming Languages

java
68154 projects - #9 most used programming language
kotlin
9241 projects
shell
77523 projects

Projects that are alternatives of or similar to jooq-postgresql-json

jooq-plugin
Plugin for generating jOOQ classes using dockerized databases
Stars: ✭ 55 (+37.5%)
Mutual labels:  jooq, jooq-generator
eventide-postgres
Event Sourcing and Microservices Stack for Ruby
Stars: ✭ 92 (+130%)
Mutual labels:  postgres
upper
Upper is a open source back-end framework based on the Dart language.
Stars: ✭ 39 (-2.5%)
Mutual labels:  postgres
besu-exflo
A plugin for the Besu enterprise-grade Ethereum client with the aim of making it easier to extract chain data into a variety of different data stores and processing pipelines.
Stars: ✭ 16 (-60%)
Mutual labels:  postgres
nodejs-with-postgres-api-example
k8s course example - node.js app with Postgres, Hapi.js and Swagger
Stars: ✭ 59 (+47.5%)
Mutual labels:  postgres
PostgreSQLClient
PostgreSQL connector for Godot Engine in GDScript.
Stars: ✭ 28 (-30%)
Mutual labels:  postgres
node-backend-template
A template for NodeJS backend projects
Stars: ✭ 19 (-52.5%)
Mutual labels:  postgres
feathers-objection
Feathers database adapter for Objection.js, an ORM based on KnexJS SQL query builder for Postgres, Redshift, MSSQL, MySQL, MariaDB, SQLite3, and Oracle. Forked from feathers-knex.
Stars: ✭ 89 (+122.5%)
Mutual labels:  postgres
pg credereum
Prototype of PostgreSQL extension bringing some properties of blockchain to the relational DBMS
Stars: ✭ 52 (+30%)
Mutual labels:  postgres
boilerplate
Fullstack boilerplate using Typescript, React, Node & GraphQL
Stars: ✭ 738 (+1745%)
Mutual labels:  postgres
walrus
Applying RLS to PostgreSQL WAL
Stars: ✭ 59 (+47.5%)
Mutual labels:  postgres
nest-blog-api
Blog Web API with NestJs, Postgres, and Sequelize ORM
Stars: ✭ 69 (+72.5%)
Mutual labels:  postgres
node-starter-kit
Node.js / GraphQL project template pre-configured with TypeScript, PostgreSQL, login flow, transactional emails, unit tests, CI/CD workflow.
Stars: ✭ 76 (+90%)
Mutual labels:  postgres
eslint-plugin-sql
SQL linting rules for ESLint.
Stars: ✭ 56 (+40%)
Mutual labels:  postgres
pgdoctor
Simple, lightweight web service to perform health checks on PostgreSQL instances
Stars: ✭ 64 (+60%)
Mutual labels:  postgres
ptrack
Block-level incremental backup engine for PostgreSQL
Stars: ✭ 21 (-47.5%)
Mutual labels:  postgres
docker-laravel-appengine
Laravel dockerized with official Google App Engine flexible php environment + swoole.
Stars: ✭ 66 (+65%)
Mutual labels:  postgres
nestjs-starter-kit
Nest.js+Postgres+Nginx+Docker starter kit
Stars: ✭ 41 (+2.5%)
Mutual labels:  postgres
space-cloud
Open source Firebase + Heroku to develop, scale and secure serverless apps on Kubernetes
Stars: ✭ 3,405 (+8412.5%)
Mutual labels:  postgres
oksql
An easy clojure postgres library
Stars: ✭ 69 (+72.5%)
Mutual labels:  postgres

jOOQ PostgreSQL JSON support

Provides jOOQ support for PostgreSQL JSON functions and operators for json and jsonb fields.

Requires at least Java 11.


Include as a Maven dependency

First, add the following Maven dependency:

<dependency>
  <groupId>com.github.t9t.jooq</groupId>
  <artifactId>jooq-postgresql-json</artifactId>
  <version>3.2.0</version>
</dependency>

Version matrix

This shows only which jOOQ version is used in this library. Minor version differences should still be compatible and newer major versions of jOOQ might still work with older versions of this library if nothing changed much in the jOOQ JSON APIs.

See the changelog for more information about what is included in the various releases and the reason for the breaking changes.

Library version jOOQ version Note
3.2.0 3.16.3
3.1.2 3.15.5
3.1.1 3.15.4
3.1.0 3.15.1
3.0.0 3.14.12 Breaking change, upgraded from Java 8 to Java 11. Java 8 no longer supported.
2.0.3 3.14.12
2.0.2 3.14.9
2.0.1 3.14.6
2.0.0 3.14.4 Breaking change because of Kotlin extension function receiver type change.
1.3.0 3.14.4
1.2.2 3.14.4
1.2.1 3.14.3
1.2.0 3.14.0
1.1.2 3.13.4
1.1.1 3.13.2
1.1.0 3.13.1
1.0.0 3.12.3 Breaking change becauuse of jOOQ upgrade from 3.11 to 3.12.
0.4.0 3.11.11

Usage

Use the JsonDSL and JsonbDSL classes to access the JSON functions and operators.

For example, to extract a JSON nested property value as text from a json field:

/* Sample JSON:
{
  "data": {
    "productCode": "Z-5521"
  }
}
*/
String productCode = dsl.select(JsonDSL.extractPathText(MY_TABLE.DATA_FIELD, "data", "productCode"))
    .from(MY_TABLE).fetchOneInto(String.class);

Or for example using the @> operator to update a row of which a jsonb field contains a certain id:

/* Sample JSON:
{
  "id": "1337",
  "name": "The Hitchhiker's Guide to the Galaxy"
}
*/
dsl.update(MY_TABLE)
    .set(MY_TABLE.RATING, 100)
    .where(JsonbDSL.contains(MY_TABLE.DATA_FIELD, JsonbDSL.field("{\"id\": \"1337\"}")))
    .execute()

Kotlin

Kotlin extension functions are available for Field<JSON?> and Field<JSONB?>. That means that instead of something like JsonDSL.extractPathText(MY_TABLE.DATA_FIELD, "data", "productCode") you can instead write: MY_TABLE.DATA_FIELD.extractPathText("data", "productCode").

The extension functions are available in the following packages:

The names of extension functions match the names of the methods on JsonDSL and JsonbDSL, except for concat and contains, which are called concatJson and containsJson respectively to prevent clashes with existing methods of Field.

PostgreSQL json operator support

Reference: https://www.postgresql.org/docs/11/functions-json.html

Operators available for both json (through JsonDSL) and jsonb (through JsonbDSL):

Op Operand Description Method
-> int Get array element arrayElement()
-> text Get object field fieldByKey()
->> int Get array element as text arrayElementText()
->> text Get object field as text fieldByKeyText()
#> text[] Get object at path objectAtPath()
#>> text[] Get object at path as text objectAtPathText()

Operators available only for jsonb (through JsonbDSL):

Op Operand Description Method
@> jsonb Does contain value? contains()
<@ jsonb Are entries contained? containedIn()
? text Does the key exist? hasKey()
?| text[] Does any key exist? hasAnyKey()
?& text[] Do all keys exist? hasAllKeys()
|| jsonb Concatenate values concat()
- text Delete key or element delete()
- text[] Delete multiple keys or elements delete()
- int Delete array element deleteElement()
#- text[] Delete field for path deletePath()

Available PostgreSQL json processing functions

Reference: https://www.postgresql.org/docs/11/functions-json.html#FUNCTIONS-JSON-PROCESSING-TABLE

Processing functions available for both json (through JsonDSL) and jsonb (through JsonbDSL):

Function Return type Description Method
json(b)_array_length int Get length of JSON array arrayLength()
json(b)_extract_path json/jsonb Extract object at path (same as #>) extractPath()
json(b)_extract_path_text text Extract object at path as text (same as #>>) extractPathText()
json(b)_typeof text Get the type of a JSON field typeOf()
json(b)_strip_nulls json/jsonb Remove object fields with null values stripNulls()

Functions only available for json (through JsonbDSL):

Function Return type Description Method
jsonb_pretty text Pretty format JSON field pretty()

References

Contributors

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].