-
-
Save kui/81ec2e4502debbda76711152a3cec4c9 to your computer and use it in GitHub Desktop.
Treat timestamp with spring-data-r2dbc in non-UTC timezone
This file contains hidden or 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
val connectionFactory = ConnectionFactories.get("r2dbc:mysql://[email protected]:3306/test") | |
// Wrapper to initialize each connections | |
val connectionFactory2 = object : ConnectionFactory { | |
override fun getMetadata(): ConnectionFactoryMetadata = connectionFactory.metadata | |
override fun create(): Publisher<out Connection> = | |
connectionFactory | |
.create() | |
.toMono() | |
.flatMap { connection -> | |
connection | |
.createStatement("SET time_zone = 'Asia/Tokyo'") | |
.execute() | |
.toMono() | |
.map { connection } | |
} | |
} | |
val client = DatabaseClient.create(connectionFactory2) | |
client.insert() | |
.into("person") | |
.value("name", "John Doe") | |
.value("birthday", LocalDateTime.of(2019, 10, 20, 10, 22)) | |
.await() | |
val person = client.select() | |
.from("person") | |
.`as`(Person::class.java) | |
.fetch() | |
.awaitFirst() | |
println(person) | |
// => Person(id=1, name=John Doe, birthday=2019-10-20T10:22) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment