I have a spring r2dbc connection for a postgresql database and would like to Create a Table,
effectively the equivalent of SQL
CREATE TABLE IF NOT EXISTS name (id, bigint);
how can I do it as DatabaseClient seems to only support select/insert?
I have a spring r2dbc connection for a postgresql database and would like to Create a Table,
effectively the equivalent of SQL
CREATE TABLE IF NOT EXISTS name (id, bigint);
how can I do it as DatabaseClient seems to only support select/insert?
You don't need to use DatabaseClient to create your tables. So when I faced the same problem as you I did something like the following code :
fun postgresProcess(config: PostgresConfig): PostgresProcess {
val runtime = PostgresStarter.getDefaultInstance()
val exec = runtime.prepare(config)
val postgres = exec.start()
// connecting to a running Postgres and feeding up the database
val conn = DriverManager.getConnection("jdbc:postgresql://$host:$port/$database", username, password)
conn.createStatement().execute("CREATE TABLE customer ( id SERIAL PRIMARY KEY, firstname VARCHAR(100) NOT NULL, lastname VARCHAR(100) NOT NULL);")
return postgres
}
At start, you could do something like this and after you can use database client.
I remember trying flyway without success. I would have liked to use the DatabaseClient. More code on my repo github
as Thomas Andolf said in the comment
.execute().sql()
is indeed the correct approach
in my case i needed to block indefinitely for the result before continuing so i needed to append .fetch().all().collectList().block();