Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting the database via config_builder.db("graph") using the ConfigBuilder seems to be ignored #116

Closed
avrabe opened this issue Oct 1, 2023 · 2 comments · Fixed by #117

Comments

@avrabe
Copy link

avrabe commented Oct 1, 2023

I'm working on some code in https://github.com/avrabe/graph-git-rs
For this I've locally created a project with an additional database graph.

Independent if I mention the database name in the url() or the db() of the ConfigBuilder, at the end always the neo4j database is used. Do I miss something in my code?

    let config = ConfigBuilder::new()
        .uri(opts.uri)
        .user(opts.user)
        .password(opts.password)
        .db(opts.db)
        .build()
        .unwrap();
    info!("{:?}", config);
    let graph = Arc::new(Graph::connect(config).await.unwrap());
    //Transactions
    let txn = graph.start_txn().await.unwrap();
    txn.run_queries(collector).await.unwrap();
    txn.commit().await.unwrap();
2023-10-01T12:33:37.796902Z  INFO graph_git_cli: graph-git-cli/src/main.rs: Config { uri: "bolt://127.0.0.1:7687", user: "neo4j", password: "12345678", max_connections: 16, db: "graph", fetch_size: 200 }
@avrabe avrabe changed the title Setting the db in the ConfigBuilder seems to be ignored Setting the config_builder.db("graph") in the ConfigBuilder seems to be ignored Oct 1, 2023
@avrabe avrabe changed the title Setting the config_builder.db("graph") in the ConfigBuilder seems to be ignored Setting the database via config_builder.db("graph") using the ConfigBuilder seems to be ignored Oct 1, 2023
@permosegaard
Copy link

permosegaard commented Oct 1, 2023

Just hit this as well, you can hotfix this by vendoring in the repo and updating messages.rs from ...

pub fn begin() -> BoltRequest {
	BoltRequest::Begin(Begin::new(BoltMap::default()))
}

... to ...

pub fn begin(db: &str) -> BoltRequest {
	let mut extra = BoltMap::default();
	extra.put("db".into(), db.to_owned().into());

	BoltRequest::Begin(Begin::new(extra))
}

... and txn.rs from ...

pub(crate) async fn new(config: Config, mut connection: ManagedConnection) -> Result<Self> {
	let begin = BoltRequest::begin();
	match connection.send_recv(begin).await? {
		BoltResponse::Success(_) => Ok(Txn {
			config,
			connection: Arc::new(Mutex::new(connection)),
		}),
		msg => Err(unexpected(msg, "BEGIN")),
	}
}

... to ...

pub(crate) async fn new(config: Config, mut connection: ManagedConnection) -> Result<Self> {
	let begin = BoltRequest::begin(&config.db);
	match connection.send_recv(begin).await? {
		BoltResponse::Success(_) => Ok(Txn {
			config,
			connection: Arc::new(Mutex::new(connection)),
		}),
		msg => Err(unexpected(msg, "BEGIN")),
	}
}

@knutwalker
Copy link
Collaborator

Thanks for reporting this. #117 fixes this issue, so that start_txn will use the configured database.
We also add the functions start_tx_on, execute_on, and run_on that accept a db: &str parameter which takes precedence over the configured database, so you can run queries on whatever database you need without having to configure and use separate clients (see https://github.com/neo4j-labs/neo4rs/blob/0784bd863abfc03c83b50094704be04f67959653/lib/tests/txn_change_db.rs for an example usage).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants