Comments (4)
Thanks for letting me know.
In the file https://github.com/rursprung/r2d2-oracle/blob/master/src/lib.rs:
/// let mut connector = oracle::Connector::new("system", "manager", "");
/// let connector = connector.privilege(oracle::Privilege::Sysdba);
Could you remove let connector =
?
/// let manager = OracleConnectionManager::new_with_connector(connector.clone());
Could you remove .clone()
? It is required only when the connector is referred later.
pub fn new_with_connector(connector: oracle::Connector) -> OracleConnectionManager {
IMO, rust doesn't tend to use methods starting with new_xxx
. For example the method name to create a new Vec with capacity is Vec::with_capacity
, not Vec::new_with_capacity
. In addition, the standard library has no methods starting with new_with
except two deprecated methods.
(Open this page and put new_with
in the search box at the top of the page.)
I think from_connector
is preferable though what do you choose is up to you.
fn is_valid(&self, conn: &mut oracle::Connection) -> Result<(), oracle::Error> {
conn.query("SELECT 1 FROM dual", &[]).map(|_| ())
}
Could you use conn.ping()
instead? It checks the network connection between the client and the server without executing a SQL statement.
fn has_broken(&self, conn: &mut oracle::Connection) -> bool {
self.is_valid(conn).is_err()
}
According to this document, has_broken
should not block. However it makes a network round trip so it may block when the network traffic is in trouble. Could you change it simply false
as the document say?
I may add a similar method to return the connection status by using OCI_ATTR_SERVER_STATUS after I check what "doing a light weight connection health check" means.
from rust-oracle.
thanks a lot for your feedback!
this doesn't work:
let manager = OracleConnectionManager::new_with_connector(oracle::Connector::new("system", "manager", "").privilege(oracle::Privilege::Sysdba));
---- src\lib.rs - OracleConnectionManager::new_with_connector (line 56) stdout ----
error[E0308]: mismatched types
--> src\lib.rs:59:59
|
6 | let manager = OracleConnectionManager::new_with_connector(oracle::Connector::new("system", "manager", "").privilege(oracle::Privilege::Sysdba));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `r2d2_oracle::oracle::Connector`, found mutable reference
|
= note: expected type `r2d2_oracle::oracle::Connector`
found type `&mut r2d2_oracle::oracle::Connector`
and this doesn't work either:
let connector = oracle::Connector::new("system", "manager", "")
.privilege(oracle::Privilege::Sysdba);
let manager = OracleConnectionManager::new_with_connector(connector.clone());
---- src\lib.rs - OracleConnectionManager::new_with_connector (line 56) stdout ----
error[E0716]: temporary value dropped while borrowed
--> src\lib.rs:59:17
|
6 | let connector = oracle::Connector::new("system", "manager", "")
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
7 | .privilege(oracle::Privilege::Sysdba);
| - temporary value is freed at the end of this statement
8 | let manager = OracleConnectionManager::new_with_connector(connector.clone());
| --------- borrow later used here
|
= note: consider using a `let` binding to create a longer lived value
i think this might actually be a problem of your API design of Connector
: you return &mut Connector
in e.g. privilege
. what i have seen elsewhere was that it would return Connector
instead (the instance, not a reference to it). so it consumes itself and then forwards it again. i think this would be more idiomatic rust.
thanks for the naming suggestion for from_connector
, i'll take that over.
and thanks for pointing out Connection::ping
, i'll switch to that. wasn't aware of it (guess i should've paid a closer look at the docs...)
same goes for has_broken
: i copied this from r2d2-mysql: https://github.com/outersky/r2d2-mysql/blob/master/src/pool.rs
i'll wait with changing has_broken
until i hear back from you about OCI_ATTR_SERVER_STATUS
from rust-oracle.
i think this might actually be a problem of your API design of
Connector
: you return&mut Connector
in e.g.privilege
. what i have seen elsewhere was that it would returnConnector
instead (the instance, not a reference to it). so it consumes itself and then forwards it again. i think this would be more idiomatic rust.
std::process::Command and std::fs::DirBuilder return &mut Self
. They are non-consuming builders described in the Rust API Guidelines.
I understand the guideline about builders as:
- Use non-consuming builders if the terminal methods take
&self
- Use consuming builders if the terminal methods take
self
I chose non-consuming builders because Connector.connect
takes &self
.
from rust-oracle.
thanks for your review!
rursprung/r2d2-oracle#2 has been merged and will soon be released as v0.2.0
from rust-oracle.
Related Issues (20)
- Any idea why I'm getting `DPI Error: DPI-1080: connection was closed by ORA-3156` HOT 3
- Usage with asynchronous code problem - how to shut down `.connect()` call that hangs indefinitely HOT 6
- Insert null values HOT 3
- How to change the value of "oracleClientLibDir" in dpiContextCreateParams struct HOT 3
- API to upload file as BLOB without preallocation HOT 3
- Question - async/await stream to many users using just 1 thread HOT 2
- the `?` operator can only be used in a function that returns `Result` or `Option` HOT 1
- QUESTION the trait `ToSql` is not implemented for `SqlValue`
- Question - Calling Oracle Stored Procedures Example HOT 3
- Convert recordset to Vec of Columns HOT 1
- Question - Alter Sessions HOT 1
- A way to set path for oracle instant client HOT 2
- How to extract `Geometry` type. HOT 2
- How can I save ResultSet<'_, oracle::Row> for later access? HOT 6
- `*mut oracle::binding::binding::dpiStmt` cannot be sent between threads safely HOT 2
- Question - Trying to use like operator with wildcards within query_as HOT 5
- Ability to auto-gen structs from db HOT 1
- execute create table sql error? HOT 3
- Question about performance HOT 11
- Why the lifetime is 'static
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust-oracle.