项目作者: bkancharla

项目描述 :
JSONB postgres sql integration in spring boot
高级语言: Java
项目地址: git://github.com/bkancharla/jsonb-spring-boot.git
创建时间: 2021-02-11T22:44:21Z
项目社区:https://github.com/bkancharla/jsonb-spring-boot

开源协议:

下载


jsonb-spring-boot

Jsonb data type integration with spring boot

Usage of postgres sql with spring-boot to create, replace and update(specific fields in jsonb data)

Technologies used

  1. JDK1.8
  2. Spring-boot
  3. hibernate-types-52
  4. Lombok
  5. Postgres Sql

Functionalities Exist:

  1. Create new jsonb field
  2. update specific part jsonb ( values)
  3. add and remove new json key values
  4. append to arrays in jsonb data
  5. Searching the data by specific jsonb filed

Service Endpoints.

  1. /**
  2. * This will Create new jsonb field
  3. */
  4. @GetMapping("/create/{firstName}")
  5. public void createNewUser(@PathVariable String firstName) {
  6. userService.createNewUserWithJsonb(firstName);
  7. }
  8. /**
  9. *User provides all the data
  10. * curl -X PUT -H "Content-Type: application/json" -d '{"salary": 100000.0, "address": {"city": "columbus", "state": "ohio", "country": "usa"},
  11. * "children": ["lory", "jack"], "phoneNumber": "333-333-0000"}' http://localhost:8080/createwithalldetails
  12. * @return
  13. */
  14. @PutMapping("/createwithalldetails")
  15. public Users createUser(@RequestBody PersonalDetails personalDetails) {
  16. return userService.createNewUserWithAllDetails(personalDetails);
  17. }
  18. /**
  19. * This will update specific part of jsonb
  20. this will clear out the second level cache if any being used
  21. */
  22. @GetMapping("/updateaddress/{id}")
  23. public void updateSpecificUserSalary(@PathVariable int id) {
  24. userService.updateUserSalary(id);
  25. }
  26. /**
  27. * This will update specific part of jsonb if second level caching being used so update on persistent entity
  28. * Invloves select query before update
  29. */
  30. @GetMapping("/updateaddressforsecondlevelcache/{id}")
  31. public void updateAddressForSecondLevelCache(@PathVariable int id) {
  32. userService.updateAddressForSecondLevelCache(id);
  33. }
  34. /**
  35. * This will add to existing array (prepend the data)
  36. */
  37. @GetMapping("/updatechilds/{id}")
  38. public void addToArray(@PathVariable int id) {
  39. userService.addToArray(id);
  40. }
  41. /**
  42. * This will Remove specific element from existing array
  43. */
  44. @GetMapping("/removearray/{id}")
  45. public void removeFromArray(@PathVariable int id) {
  46. userService.removeFromChildArray(id);
  47. }
  48. /**
  49. * This will read the data which has given Salary
  50. * http://localhost:8080/read/200000.0
  51. *
  52. * @return
  53. */
  54. @GetMapping("/read/{salary}")
  55. public List<Users> readySalaryContains(@PathVariable double salary) {
  56. return userService.readSalaryContains(salary);
  57. }

Notes: please update your db details in application.yaml file