我有一个用于postgresql数据库的spring r2dbc连接,并想创建一个表,
实际上相当于SQL
CREATE TABLE IF NOT EXISTS name (id, bigint);
当DatabaseClient似乎只支持select/insert时,我该怎么做呢?
发布于 2019-06-26 02:22:50
正如Thomas Andolf在评论中所说的那样
.execute().sql()
确实是正确的方法
在我的例子中,我需要无限期地阻止结果,然后才能继续,所以我需要附加.fetch().all().collectList().block();
发布于 2019-06-25 04:54:44
您不需要使用DatabaseClient来创建表。所以,当我遇到和你一样的问题时,我做了类似以下代码的事情:
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
}
开始的时候,你可以这样做,然后你就可以使用数据库客户端了。
我记得我尝试过flyway,但没有成功。我本来想用DatabaseClient的。我的repo github上有更多代码
https://stackoverflow.com/questions/56743704
复制相似问题