forked from hantsy/spring-r2dbc-sample
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
84 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
DELETE FROM posts; | ||
INSERT INTO posts (title, content) VALUES ('R2dbc is refined', 'R2dbc is now part of Spring framework core'); | ||
INSERT INTO posts (title, content) VALUES ('Spring Data Relational is refined', 'Spring Data R2dbc is now a subproject of Spring Data Relational'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; | ||
|
||
-- There is no 'if not exists' for type | ||
-- But use a 'Drop' will cause exception if the type is applied in table schema. | ||
-- DROP TYPE post_status; | ||
|
||
-- The value only accept single quotes. | ||
-- CREATE TYPE post_status AS ENUM( 'DRAFT', 'PENDING_MODERATION', 'PUBLISHED'); | ||
|
||
-- A simple way to skip exception when creating type if it is existed. | ||
DO $$ BEGIN | ||
CREATE TYPE post_status AS ENUM( 'DRAFT', 'PENDING_MODERATION', 'PUBLISHED'); | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
|
||
-- Use EnumCodec to handle enum between Java and pg. | ||
-- see: https://github.com/pgjdbc/r2dbc-postgresql#postgres-enum-types | ||
-- CREATE CAST (varchar AS post_status) WITH INOUT AS IMPLICIT; |
9 changes: 1 addition & 8 deletions
9
data-r2dbc-repositories/src/main/java/com/example/demo/PostRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,14 @@ | ||
package com.example.demo; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate; | ||
import org.springframework.data.r2dbc.repository.R2dbcRepository; | ||
import org.springframework.data.relational.core.query.Query; | ||
import org.springframework.data.relational.core.query.Update; | ||
import org.springframework.stereotype.Component; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
import java.util.UUID; | ||
|
||
import static org.springframework.data.relational.core.query.Criteria.where; | ||
|
||
public interface PostRepository extends R2dbcRepository<Post, UUID> { | ||
public Flux<Post> findByTitleContains(String name); | ||
|
||
public Mono<Long> countByTitleContains(String name); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters