Skip to content

Is read only mode supported? #168

Closed
Closed
@hughpearse

Description

@hughpearse

Hello I am writing code using this library to run arbitrary SQL queries via a service account. I would like to build a connection in read only mode. I have tried the following ways and failed.

First attempt:

@Transactional
public Mono<String> runQueryStrictlyReadOnly() {
    return databaseClient.sql("SET TRANSACTION READ ONLY")
            .then()
            .then(databaseClient.sql("SELECT name FROM my_table WHERE id = 1")
                .map(row -> row.get("name", String.class))
                .one()
            );
}

Second attempt:

   @Transactional(readOnly = true)
   public Mono<String> runQuery() {
       return databaseClient.sql("SELECT name FROM my_table WHERE id = 1")
               .map(row -> row.get("name", String.class))
               .one();
   }
}

Third attempt:

ConnectionFactoryOptions options = ConnectionFactoryOptions.builder()
    .option(ConnectionFactoryOptions.DRIVER, "oracle")
    .option(ConnectionFactoryOptions.HOST, "localhost")
    .option(ConnectionFactoryOptions.PORT, 1521)
    .option(ConnectionFactoryOptions.USER, "read_user")
    .option(ConnectionFactoryOptions.PASSWORD, "password123")
    .option(Option.valueOf("readOnly"), true) 
    .build();

None of these block attempts to run insert statements.
Is it even possible?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions