Struct mysql::OptsBuilder [−][src]
pub struct OptsBuilder { /* fields omitted */ }
Expand description
Provides a way to build Opts
.
let mut ssl_opts = SslOpts::default();
ssl_opts = ssl_opts.with_pkcs12_path(Some(Path::new("/foo/cert.p12")))
.with_root_ca_path(Some(Path::new("/foo/root_ca.der")));
// You can create new default builder
let mut builder = OptsBuilder::new();
builder = builder.ip_or_hostname(Some("foo"))
.db_name(Some("bar"))
.ssl_opts(Some(ssl_opts));
// Or use existing T: Into<Opts>
let builder = OptsBuilder::from_opts(existing_opts)
.ip_or_hostname(Some("foo"))
.db_name(Some("bar"));
Connection URL
Opts
also could be constructed using connection URL. See docs on OptsBuilder
’s methods for
the list of options available via URL.
Example:
let connection_url = "mysql://root:password@localhost:3307/mysql?prefer_socket=false";
let pool = my::Pool::new(connection_url).unwrap();
Implementations
Use a HashMap for creating an OptsBuilder instance:
OptsBuilder::new().from_hash_map(client);
HashMap
key,value pairs:
- user = Username
- password = Password
- host = Host name or ip address
- port = Port, default is 3306
- socket = Unix socket or pipe name(on windows) defaults to
None
- db_name = Database name (defaults to
None
). - prefer_socket = Prefer socket connection (defaults to
true
) - tcp_keepalive_time_ms = TCP keep alive time for mysql connection (defaults to
None
) - compress = Compression level(defaults to
None
) - tcp_connect_timeout_ms = Tcp connect timeout (defaults to
None
) - stmt_cache_size = Number of prepared statements cached on the client side (per connection)
- secure_auth = Disable
mysql_old_password
auth plugin
Login .cnf file parsing lib https://github.com/rjcortese/myloginrs returns a HashMap for client configs
Note: You do not have to use myloginrs lib.
Address of mysql server (defaults to 127.0.0.1
). Hostnames should also work.
Note: IPv6 addresses must be given in square brackets, e.g. [::1]
.
Socket path on unix or pipe name on windows (defaults to None
).
Can be defined using socket
connection url parameter.
Database name (defaults to None
).
The timeout for each attempt to read from the server (defaults to None
).
Note that named pipe connection will ignore duration’s nanos
, and also note that
it is an error to pass the zero Duration
to this method.
The timeout for each attempt to write to the server (defaults to None
).
Note that named pipe connection will ignore duration’s nanos
, and also note that
it is likely error to pass the zero Duration
to this method.
TCP keep alive time for mysql connection (defaults to None
). Available as
tcp_keepalive_time_ms
url parameter.
Can be defined using tcp_keepalive_time_ms
connection url parameter.
Set the TCP_NODELAY
option for the mysql connection (defaults to true
).
Setting this option to false re-enables Nagle’s algorithm, which can cause unusually high latency (~40ms) but may increase maximum throughput. See #132.
Prefer socket connection (defaults to true
). Available as prefer_socket
url parameter
with value true
or false
.
Will reconnect via socket (on named pipe on windows) after TCP connection
to 127.0.0.1
if true
.
Will fall back to TCP on error. Use socket
option to enforce socket connection.
Can be defined using prefer_socket
connection url parameter.
Commands to execute on each new database connection.
Driver will require SSL connection if this option isn’t None
(default to None
).
Callback to handle requests for local files. These are
caused by using LOAD DATA LOCAL INFILE
queries. The
callback is passed the filename, and a Write
able object
to receive the contents of that file.
If unset, the default callback will read files relative to
the current directory.
Tcp connect timeout (defaults to None
). Available as tcp_connect_timeout_ms
url parameter.
Can be defined using tcp_connect_timeout_ms
connection url parameter.
Bind address for a client (defaults to None
).
Use carefully. Will probably make pool unusable because of address already in use errors.
Number of prepared statements cached on the client side (per connection).
Defaults to DEFAULT_STMT_CACHE_SIZE
.
Can be defined using stmt_cache_size
connection url parameter.
Call with None
to reset to default.
If not None
, then client will ask for compression if server supports it
(defaults to None
).
Can be defined using compress
connection url parameter with values:
true
- library defined default compression level;fast
- library defined fast compression level;best
- library defined best compression level;0
,1
, …,9
- explicitly defined compression level where0
stands for “no compression”;
Note that compression level defined here will affect only outgoing packets.
Additional client capabilities to set (defaults to empty).
This value will be OR’ed with other client capabilities during connection initialisation.
Note
It is a good way to set something like CLIENT_FOUND_ROWS
but you should note that it
won’t let you to interfere with capabilities managed by other options (like
CLIENT_SSL
or CLIENT_COMPRESS
). Also note that some capabilities are reserved,
pointless or may broke the connection, so this option should be used with caution.
Connect attributes
This value is sent to the server as custom name-value attributes.
You can see them from performance_schema tables: session_account_connect_attrs
and session_connect_attrs
when all of the following conditions
are met.
- The server is MySQL 5.6 or later, or MariaDB 10.0 or later.
performance_schema
is on.performance_schema_session_connect_attrs_size
is -1 or big enough to store specified attributes.
Note
Attribute names that begin with an underscore (_
) are not set by
application programs because they are reserved for internal use.
The following attributes are sent in addition to ones set by programs.
name | value |
---|---|
_client_name | The client library name (rust-mysql-simple ) |
_client_version | The client library version |
_os | The operation system (target_os cfg feature) |
_pid | The client proces ID |
_platform | The machine platform (target_arch cfg feature) |
program_name | The first element of std::env::args if program_name isn’t set by programs. |
Disables mysql_old_password
plugin (defaults to true
).
Available via secure_auth
connection url parameter.
Trait Implementations
Returns the “default value” for a type. Read more
Performs the conversion.
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
Auto Trait Implementations
impl RefUnwindSafe for OptsBuilder
impl Send for OptsBuilder
impl Sync for OptsBuilder
impl Unpin for OptsBuilder
impl UnwindSafe for OptsBuilder
Blanket Implementations
Mutably borrows from an owned value. Read more
fn fmt_binary(self) -> FmtBinary<Self> where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self> where
Self: Binary,
Causes self
to use its Binary
implementation when Debug
-formatted.
fn fmt_display(self) -> FmtDisplay<Self> where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self> where
Self: Display,
Causes self
to use its Display
implementation when
Debug
-formatted. Read more
fn fmt_lower_exp(self) -> FmtLowerExp<Self> where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self> where
Self: LowerExp,
Causes self
to use its LowerExp
implementation when
Debug
-formatted. Read more
fn fmt_lower_hex(self) -> FmtLowerHex<Self> where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self> where
Self: LowerHex,
Causes self
to use its LowerHex
implementation when
Debug
-formatted. Read more
Causes self
to use its Octal
implementation when Debug
-formatted.
fn fmt_pointer(self) -> FmtPointer<Self> where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self> where
Self: Pointer,
Causes self
to use its Pointer
implementation when
Debug
-formatted. Read more
fn fmt_upper_exp(self) -> FmtUpperExp<Self> where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self> where
Self: UpperExp,
Causes self
to use its UpperExp
implementation when
Debug
-formatted. Read more
fn fmt_upper_hex(self) -> FmtUpperHex<Self> where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self> where
Self: UpperHex,
Causes self
to use its UpperHex
implementation when
Debug
-formatted. Read more
pub fn lift_into(self) -> U
pub fn lift_into(self) -> U
Performs the indexed conversion.
impl<T> Pipe for T where
T: ?Sized,
impl<T> Pipe for T where
T: ?Sized,
Pipes by value. This is generally the method you want to use. Read more
Borrows self
and passes that borrow into the pipe function. Read more
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R where
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R where
R: 'a,
Mutably borrows self
and passes that borrow into the pipe function. Read more
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R where
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R where
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
Borrows self
, then passes self.borrow()
into the pipe function. Read more
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R where
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R where
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
Mutably borrows self
, then passes self.borrow_mut()
into the pipe
function. Read more
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R where
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R where
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
Borrows self
, then passes self.as_ref()
into the pipe function.
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R where
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R where
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
Mutably borrows self
, then passes self.as_mut()
into the pipe
function. Read more
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Deref<Target = T>,
T: 'a + ?Sized,
R: 'a,
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Deref<Target = T>,
T: 'a + ?Sized,
R: 'a,
Borrows self
, then passes self.deref()
into the pipe function.
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
Immutable access to the Borrow<B>
of a value. Read more
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
Mutable access to the BorrowMut<B>
of a value. Read more
Immutable access to the AsRef<R>
view of a value. Read more
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
Mutable access to the AsMut<R>
view of a value. Read more
Immutable access to the Deref::Target
of a value. Read more
Mutable access to the Deref::Target
of a value. Read more
Calls .tap()
only in debug builds, and is erased in release builds.
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
Calls .tap_mut()
only in debug builds, and is erased in release
builds. Read more
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
Calls .tap_borrow()
only in debug builds, and is erased in release
builds. Read more
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
Calls .tap_borrow_mut()
only in debug builds, and is erased in release
builds. Read more
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
Calls .tap_ref()
only in debug builds, and is erased in release
builds. Read more
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
Calls .tap_ref_mut()
only in debug builds, and is erased in release
builds. Read more