### Install Drivers for AnyConnection Source: https://docs.rs/sqlx/latest/sqlx/any/fn.install_drivers.html?search= Installs drivers for `AnyConnection` to use. Must be called before connecting. Errors if called more than once. ```rust pub fn install_drivers( drivers: &'static [AnyDriver], ) -> Result<(), Box> ``` -------------------------------- ### Get Sunday-Based Week Number from OffsetDateTime Source: https://docs.rs/sqlx/latest/sqlx/types/time/struct.OffsetDateTime.html?search= Retrieve the week number where week 1 starts on Sunday (0-53) from an OffsetDateTime. Shows examples across year boundaries. ```rust assert_eq!(datetime!(2019-01-01 0:00 UTC).sunday_based_week(), 0); assert_eq!(datetime!(2020-01-01 0:00 UTC).sunday_based_week(), 0); assert_eq!(datetime!(2020-12-31 0:00 UTC).sunday_based_week(), 52); assert_eq!(datetime!(2021-01-01 0:00 UTC).sunday_based_week(), 0); ``` -------------------------------- ### begin_with Source: https://docs.rs/sqlx/latest/sqlx/struct.Pool.html Retrieves a connection and immediately begins a new transaction using the provided SQL statement. Available on `crate feature 'any'` only. ```APIDOC ## begin_with ### Description Retrieves a connection and immediately begins a new transaction using `statement`. ### Method `async fn begin_with(&self, statement: impl SqlSafeStr) -> Result, Error>` ### Parameters #### Path Parameters - **statement** (impl SqlSafeStr) - Required - The SQL statement to use for beginning the transaction. ### Response #### Success Response (Result, Error>) - **Transaction<'static, DB>** - A new transaction. - **Error** - An error if a connection cannot be acquired or the transaction cannot be started. ``` -------------------------------- ### Get Monday-Based Week Number from OffsetDateTime Source: https://docs.rs/sqlx/latest/sqlx/types/time/struct.OffsetDateTime.html?search= Extract the week number where week 1 starts on Monday (0-53) from an OffsetDateTime. Includes examples for different dates and year ends. ```rust assert_eq!(datetime!(2019-01-01 0:00 UTC).monday_based_week(), 0); assert_eq!(datetime!(2020-01-01 0:00 UTC).monday_based_week(), 0); assert_eq!(datetime!(2020-12-31 0:00 UTC).monday_based_week(), 52); assert_eq!(datetime!(2021-01-01 0:00 UTC).monday_based_week(), 0); ``` -------------------------------- ### begin Source: https://docs.rs/sqlx/latest/sqlx/struct.Pool.html Retrieves a connection and immediately begins a new transaction. Available on `crate feature 'any'` only. ```APIDOC ## begin ### Description Retrieves a connection and immediately begins a new transaction. ### Method `async fn begin(&self) -> Result, Error>` ### Response #### Success Response (Result, Error>) - **Transaction<'static, DB>** - A new transaction. - **Error** - An error if a connection cannot be acquired or the transaction cannot be started. ``` -------------------------------- ### Get Prefix of IpNetwork Source: https://docs.rs/sqlx/latest/sqlx/types/ipnetwork/enum.IpNetwork.html Retrieves the prefix length of an IpNetwork. This example shows how to get the prefix for both IPv4 and IPv6 networks. ```rust use ipnetwork::IpNetwork; assert_eq!(IpNetwork::V4("10.9.0.1".parse().unwrap()).prefix(), 32u8); assert_eq!(IpNetwork::V4("10.9.0.32/16".parse().unwrap()).prefix(), 16u8); assert_eq!(IpNetwork::V6("ff01::0".parse().unwrap()).prefix(), 128u8); assert_eq!(IpNetwork::V6("ff01::0/32".parse().unwrap()).prefix(), 32u8); ``` -------------------------------- ### begin Source: https://docs.rs/sqlx/latest/sqlx/pool/struct.Pool.html?search= Retrieves a connection and immediately begins a new transaction. Requires the `any` feature. ```APIDOC ## begin ### Description Retrieves a connection and immediately begins a new transaction. ### Signature `pub async fn begin(&self) -> Result, Error>` ### Returns A `Result` containing a `Transaction<'static, DB>` on success, or an `Error` on failure. ``` -------------------------------- ### Get UtcOffset from OffsetDateTime Source: https://docs.rs/sqlx/latest/sqlx/types/time/struct.OffsetDateTime.html?search= Retrieve the UTC offset associated with an OffsetDateTime. Examples show how to get the offset for UTC and a custom offset. ```rust assert_eq!(datetime!(2019-01-01 0:00 UTC).offset(), offset!(UTC)); assert_eq!(datetime!(2019-01-01 0:00 +1).offset(), offset!(+1)); ``` -------------------------------- ### options Source: https://docs.rs/sqlx/latest/sqlx/postgres/struct.PgConnectOptions.html?search= Sets additional startup options for the connection as a list of key-value pairs, escaping special characters as needed. ```APIDOC ## options ### Description Set additional startup options for the connection as a list of key-value pairs. Escapes the options’ backslash and space characters as per https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-OPTIONS ### Method `options(self, options: I) -> PgConnectOptions where K: Display, V: Display, I: IntoIterator` ### Parameters - **options** (I) - An iterator of key-value pairs representing the connection options. ### Example ```rust let options = PgConnectOptions::new() .options([("geqo", "off"), ("statement_timeout", "5min")]); ``` ``` -------------------------------- ### Get Monday-Based Week Number Source: https://docs.rs/sqlx/latest/sqlx/types/time/struct.PrimitiveDateTime.html Shows how to get the week number where week 1 starts on Monday. The value ranges from 0 to 53. ```rust assert_eq!(datetime!(2019-01-01 0:00).monday_based_week(), 0); assert_eq!(datetime!(2020-01-01 0:00).monday_based_week(), 0); assert_eq!(datetime!(2020-12-31 0:00).monday_based_week(), 52); assert_eq!(datetime!(2021-01-01 0:00).monday_based_week(), 0); ``` -------------------------------- ### begin_with Source: https://docs.rs/sqlx/latest/sqlx/mysql/type.MySqlPool.html Retrieves a connection and immediately begins a new transaction using the provided SQL statement. ```APIDOC ## begin_with ### Description Retrieves a connection and immediately begins a new transaction using the provided SQL statement. ### Method `pub async fn begin_with(&self, statement: impl SqlSafeStr) -> Result, Error>` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response A `Result` containing a `Transaction` object on success, or an `Error` on failure. #### Response Example None ``` -------------------------------- ### begin Source: https://docs.rs/sqlx/latest/sqlx/sqlite/type.SqlitePool.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Retrieves a connection and immediately begins a new transaction. ```APIDOC ## begin ### Description Retrieves a connection and immediately begins a new transaction. ### Method `async fn begin(&self) -> Result, Error>` ``` -------------------------------- ### PrimitiveDateTime Week Numbering Source: https://docs.rs/sqlx/latest/sqlx/types/time/struct.PrimitiveDateTime.html?search= Methods to get week numbers based on Sunday or Monday as the start of the week. ```APIDOC ## PrimitiveDateTime::sunday_based_week(self) -> u8 ### Description Get the week number where week 1 begins on the first Sunday. The returned value will always be in the range `0..=53`. ### Example ```rust assert_eq!(datetime!(2019-01-01 0:00).sunday_based_week(), 0); assert_eq!(datetime!(2020-01-01 0:00).sunday_based_week(), 0); assert_eq!(datetime!(2020-12-31 0:00).sunday_based_week(), 52); assert_eq!(datetime!(2021-01-01 0:00).sunday_based_week(), 0); ``` ## PrimitiveDateTime::monday_based_week(self) -> u8 ### Description Get the week number where week 1 begins on the first Monday. The returned value will always be in the range `0..=53`. ### Example ```rust assert_eq!(datetime!(2019-01-01 0:00).monday_based_week(), 0); assert_eq!(datetime!(2020-01-01 0:00).monday_based_week(), 0); assert_eq!(datetime!(2020-12-31 0:00).monday_based_week(), 52); assert_eq!(datetime!(2021-01-01 0:00).monday_based_week(), 0); ``` ``` -------------------------------- ### pub async fn connect_with( self, options: <::Connection as Connection>::Options, ) -> Result, Error> Source: https://docs.rs/sqlx/latest/sqlx/any/type.AnyPoolOptions.html?search=std%3A%3Avec Creates a new connection pool using the provided connection options and immediately establishes at least one connection. This function verifies the configuration by attempting to connect. The initial number of connections will be `max(1, min_connections)`. ```APIDOC ## pub async fn connect_with( self, options: <::Connection as Connection>::Options, ) -> Result, Error> ### Description Create a new pool from this `PoolOptions` and immediately open at least one connection. This ensures the configuration is correct. The total number of connections opened is `max(1, min_connections)`. ``` -------------------------------- ### Create empty PgLQueryVariantFlag Source: https://docs.rs/sqlx/latest/sqlx/postgres/types/struct.PgLQueryVariantFlag.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Get a flags value with all bits unset. Useful for starting with a clean state. ```rust pub const fn empty() -> PgLQueryVariantFlag ``` -------------------------------- ### Iterating over a slice Source: https://docs.rs/sqlx/latest/sqlx/postgres/struct.PgArgumentBuffer.html?search=std%3A%3Avec Use `iter()` to get an iterator that yields immutable references to slice elements from start to end. ```rust let x = &[1, 2, 4]; let mut iterator = x.iter(); assert_eq!(iterator.next(), Some(&1)); assert_eq!(iterator.next(), Some(&2)); assert_eq!(iterator.next(), Some(&4)); assert_eq!(iterator.next(), None); ``` -------------------------------- ### sqlx::any::install_drivers Source: https://docs.rs/sqlx/latest/sqlx/any/fn.install_drivers.html?search=u32+-%3E+bool Installs a list of drivers for `AnyConnection` and `AnyPool` to use. This function must be called before an `AnyConnection` or `AnyPool` can be connected. It returns an error if called more than once. ```APIDOC ## Function install_drivers ### Description Installs the list of drivers for `AnyConnection` to use. Must be called before an `AnyConnection` or `AnyPool` can be connected. ### Signature `pub fn install_drivers(drivers: &'static [AnyDriver]) -> Result<(), Box>` ### Parameters * `drivers` (*`&'static [AnyDriver]`*) - A static slice of `AnyDriver` to install. ### Errors * If called more than once. ``` -------------------------------- ### String Length Example Source: https://docs.rs/sqlx/latest/sqlx/postgres/types/struct.PgCiText.html?search=u32+-%3E+bool Demonstrates how to get the length of a string in bytes. Note that this may not correspond to the number of characters or graphemes. ```rust let len = "foo".len(); assert_eq!(3, len); assert_eq!("ƒoo".len(), 4); // fancy f! assert_eq!("ƒoo".chars().count(), 3); ``` -------------------------------- ### Get Day of Year (0-365) Source: https://docs.rs/sqlx/latest/sqlx/types/chrono/struct.NaiveDate.html?search= Returns the day of the year, starting from 0. The range is 0 to 365, varying by year. ```rust use chrono::{Datelike, NaiveDate}; assert_eq!(NaiveDate::from_ymd_opt(2015, 9, 8).unwrap().ordinal0(), 250); assert_eq!(NaiveDate::from_ymd_opt(-308, 3, 14).unwrap().ordinal0(), 73); ``` -------------------------------- ### connect_with Source: https://docs.rs/sqlx/latest/sqlx/prelude/trait.Connection.html?search= Establishes a new database connection using pre-configured options. ```APIDOC ## connect_with ### Description Establishes a new database connection with the provided options. ### Method `connect_with(options: &Self::Options) -> impl Future> + Send` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response - `Self`: A new database connection instance. #### Response Example None ``` -------------------------------- ### options Source: https://docs.rs/sqlx/latest/sqlx/postgres/struct.PgConnectOptions.html?search=std%3A%3Avec Set additional startup options for the connection as a list of key-value pairs. Escapes the options’ backslash and space characters. ```APIDOC ## pub fn options(self, options: I) -> PgConnectOptions where K: Display, V: Display, I: IntoIterator, ### Description Set additional startup options for the connection as a list of key-value pairs. Escapes the options’ backslash and space characters as per https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-OPTIONS ### Method `options` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust let options = PgConnectOptions::new() .options([("geqo", "off"), ("statement_timeout", "5min")]); ``` ### Response #### Success Response Returns `PgConnectOptions` with the additional options set. #### Response Example None provided. ``` -------------------------------- ### Get Day of Year (1-366) Source: https://docs.rs/sqlx/latest/sqlx/types/chrono/struct.NaiveDate.html?search= Returns the day of the year, starting from 1. The range is 1 to 366, varying by year. ```rust use chrono::{Datelike, NaiveDate}; assert_eq!(NaiveDate::from_ymd_opt(2015, 9, 8).unwrap().ordinal(), 251); assert_eq!(NaiveDate::from_ymd_opt(-308, 3, 14).unwrap().ordinal(), 74); ``` -------------------------------- ### install_drivers Source: https://docs.rs/sqlx/latest/sqlx/any/fn.install_drivers.html Installs the list of drivers for `AnyConnection` to use. Must be called before an `AnyConnection` or `AnyPool` can be connected. Errors if called more than once. ```APIDOC ## Function install_drivers ### Description Installs the list of drivers for `AnyConnection` to use. Must be called before an `AnyConnection` or `AnyPool` can be connected. ### Signature ```rust pub fn install_drivers( drivers: &'static [AnyDriver], ) -> Result<(), Box> ``` ### Parameters * `drivers` (`&'static [AnyDriver]`): A static slice of `AnyDriver` to install. ### Errors * If called more than once. ``` -------------------------------- ### Get Day of Month (0-30) Source: https://docs.rs/sqlx/latest/sqlx/types/chrono/struct.NaiveDate.html?search= Returns the day of the month, starting from 0. The range is 0 to 30, varying by month. ```rust use chrono::{Datelike, NaiveDate}; assert_eq!(NaiveDate::from_ymd_opt(2015, 9, 8).unwrap().day0(), 7); assert_eq!(NaiveDate::from_ymd_opt(-308, 3, 14).unwrap().day0(), 13); ``` -------------------------------- ### Connect to Database with Options Source: https://docs.rs/sqlx/latest/sqlx/any/type.AnyPoolOptions.html?search=std%3A%3Avec Establishes a new database connection pool immediately using explicit connection options. This verifies the configuration and opens `max(1, min_connections)` connections. ```rust let pool = PoolOptions::new() .connect_with(PgConnectOptions::new().database("my_db")) .await?; ``` -------------------------------- ### Get Day of Month (1-31) Source: https://docs.rs/sqlx/latest/sqlx/types/chrono/struct.NaiveDate.html?search= Returns the day of the month, starting from 1. The range is 1 to 31, varying by month. ```rust use chrono::{Datelike, NaiveDate}; assert_eq!(NaiveDate::from_ymd_opt(2015, 9, 8).unwrap().day(), 8); assert_eq!(NaiveDate::from_ymd_opt(-308, 3, 14).unwrap().day(), 14); ``` -------------------------------- ### Connect with Specific Options Source: https://docs.rs/sqlx/latest/sqlx/any/type.AnyPoolOptions.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new pool and immediately opens at least one connection using provided `ConnectOptions`. Verifies configuration and ensures `min_connections` are established. ```rust let options = PgConnectOptions::new() .host("localhost") .username("user") .password("password") .database("database"); let pool = PoolOptions::::new() .connect_with(options) .await?; ``` -------------------------------- ### Get Nanosecond from OffsetDateTime Source: https://docs.rs/sqlx/latest/sqlx/types/time/struct.OffsetDateTime.html?search= Retrieves the nanosecond component (0-999,999,999) within the second from an OffsetDateTime. Examples show zero and maximum nanoseconds. ```rust assert_eq!(datetime!(2019-01-01 0:00 UTC).nanosecond(), 0); assert_eq!( datetime!(2019-01-01 23:59:59.999_999_999 UTC).nanosecond(), 999_999_999, ); ``` -------------------------------- ### Get Microsecond from OffsetDateTime Source: https://docs.rs/sqlx/latest/sqlx/types/time/struct.OffsetDateTime.html?search= Extracts the microsecond component (0-999,999) within the second from an OffsetDateTime. Examples cover zero and maximum microseconds. ```rust assert_eq!(datetime!(2019-01-01 0:00 UTC).microsecond(), 0); assert_eq!( datetime!(2019-01-01 23:59:59.999_999 UTC).microsecond(), 999_999, ); ``` -------------------------------- ### Establishing a New Database Connection with Options Source: https://docs.rs/sqlx/latest/sqlx/struct.AnyConnection.html?search=u32+-%3E+bool Establishes a new database connection using provided connection options. This method allows for more granular control over the connection setup. ```rust fn connect_with( options: &Self::Options, ) -> impl Future> + Send where Self: Sized, ``` -------------------------------- ### install_default_drivers Source: https://docs.rs/sqlx/latest/sqlx/any/index.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Installs all currently compiled-in drivers for `AnyConnection` to use. This is a convenience function for setting up all available drivers. ```APIDOC ## Function: install_default_drivers ### Description Install all currently compiled-in drivers for `AnyConnection` to use. ### Signature ```rust fn install_default_drivers() ``` ``` -------------------------------- ### Get Millisecond from OffsetDateTime Source: https://docs.rs/sqlx/latest/sqlx/types/time/struct.OffsetDateTime.html?search= Retrieves the millisecond component (0-999) within the second from an OffsetDateTime. Examples show zero and maximum milliseconds. ```rust assert_eq!(datetime!(2019-01-01 0:00 UTC).millisecond(), 0); assert_eq!(datetime!(2019-01-01 23:59:59.999 UTC).millisecond(), 999); ``` -------------------------------- ### Connect to MySQL with ConnectOptions Source: https://docs.rs/sqlx/latest/sqlx/mysql/type.MySqlPool.html?search=u32+-%3E+bool Creates a new MySQL connection pool with default configuration and provided `ConnectOptions`. Establishes one connection immediately. For production, consider `PoolOptions::new()` for custom configurations. ```rust pub async fn connect_with( options: <::Connection as Connection>::Options, ) -> Result, Error> ``` -------------------------------- ### Get Time from OffsetDateTime Source: https://docs.rs/sqlx/latest/sqlx/types/time/struct.OffsetDateTime.html?search= Retrieve the Time component from an OffsetDateTime, respecting its stored offset. Examples include UTC and a converted offset. ```rust assert_eq!(datetime!(2019-01-01 0:00 UTC).time(), time!(0:00)); assert_eq!( datetime!(2019-01-01 0:00 UTC) .to_offset(offset!(-1)) .time(), time!(23:00) ); ``` -------------------------------- ### Get Size of IpNetwork Source: https://docs.rs/sqlx/latest/sqlx/types/ipnetwork/enum.IpNetwork.html Calculates the total number of host addresses within an IpNetwork. This example shows the size for an IPv4 network. ```rust use ipnetwork::{IpNetwork, NetworkSize}; let net: IpNetwork = "127.0.0.0/24".parse().unwrap(); assert_eq!(net.size(), NetworkSize::V4(256)) ``` -------------------------------- ### Connect with Options Source: https://docs.rs/sqlx/latest/sqlx/struct.AnyConnection.html Establishes a new database connection using provided options. This is an alternative to connecting via a URL. ```rust pub async fn connect_with(options: &Self::Options) -> Result ``` -------------------------------- ### Iterate over a mutable range of elements Source: https://docs.rs/sqlx/latest/sqlx/postgres/types/struct.PgHstore.html Use `range_mut` to get a mutable iterator over a sub-range of elements. Allows in-place modification of values within the specified range. Panics if range start exceeds end, or if start equals end with both bounds excluded. ```rust use std::collections::BTreeMap; let mut map: BTreeMap<&str, i32> = [("Alice", 0), ("Bob", 0), ("Carol", 0), ("Cheryl", 0)].into(); for (_, balance) in map.range_mut("B".."Cheryl") { *balance += 100; } for (name, balance) in &map { println!("{name} => {balance}"); } ``` -------------------------------- ### connect_with Source: https://docs.rs/sqlx/latest/sqlx/struct.Pool.html?search= Creates a new connection pool with a default configuration and the given `ConnectOptions`, establishing one connection immediately. ```APIDOC ## connect_with ### Description Create a new connection pool with a default pool configuration and the given `ConnectOptions`, and immediately establish one connection. ### Method `pub async fn connect_with(options: <::Connection as Connection>::Options) -> Result, Error>` ### Parameters #### Path Parameters - **options** (ConnectOptions) - Required - The connection options for the pool. ### Response #### Success Response (Result, Error>) - **Pool** - A new connection pool. - **Error** - An error if the connection fails. ``` -------------------------------- ### connect_with Source: https://docs.rs/sqlx/latest/sqlx/any/type.AnyPoolOptions.html Create a new pool from this `PoolOptions` and immediately open at least one connection, ensuring configuration correctness. The number of connections opened is `max(1, min_connections)`. ```APIDOC ## pub async fn connect_with( self, options: <::Connection as Connection>::Options, ) -> Result, Error> ### Description Create a new pool from this `PoolOptions` and immediately open at least one connection. This ensures the configuration is correct. The total number of connections opened is `max(1, min_connections)`. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ``` -------------------------------- ### Extract Hour, Minute, Second, and Nanosecond Source: https://docs.rs/sqlx/latest/sqlx/types/time/struct.OffsetDateTime.html?search= Gets the hour, minute, second, and nanosecond from an OffsetDateTime. Shows examples for zero and maximum nanoseconds. ```rust assert_eq!( datetime!(2020-01-01 0:00:00 UTC).to_hms_nano(), (0, 0, 0, 0) ); assert_eq!( datetime!(2020-01-01 23:59:59.999_999_999 UTC).to_hms_nano(), (23, 59, 59, 999_999_999) ); ``` -------------------------------- ### Get Ordinal Day from OffsetDateTime Source: https://docs.rs/sqlx/latest/sqlx/types/time/struct.OffsetDateTime.html?search= Retrieve the day of the year (ordinal) from an OffsetDateTime, in the range of 1 to 366. Includes examples with offset adjustments. ```rust assert_eq!(datetime!(2019-01-01 0:00 UTC).ordinal(), 1); assert_eq!( datetime!(2019-12-31 23:00 UTC) .to_offset(offset!(+1)) .ordinal(), 1, ); ``` -------------------------------- ### install_drivers Source: https://docs.rs/sqlx/latest/sqlx/any/fn.install_drivers.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Installs the list of drivers for `AnyConnection` to use. This must be called before an `AnyConnection` or `AnyPool` can be connected. It returns an error if called more than once. ```APIDOC ## Function install_drivers Available on **crate feature `any`** only. ### Description Install the list of drivers for `AnyConnection` to use. Must be called before an `AnyConnection` or `AnyPool` can be connected. ### Errors If called more than once. ### Signature ```rust pub fn install_drivers( drivers: &'static [AnyDriver] ) -> Result<(), Box> ``` ``` -------------------------------- ### connect_with Source: https://docs.rs/sqlx/latest/sqlx/any/type.AnyPoolOptions.html?search= Create a new pool from this `PoolOptions` and immediately open at least one connection using provided connection options. ```APIDOC ## pub async fn connect_with( self, options: <::Connection as Connection>::Options, ) -> Result, Error> ### Description Create a new pool from this `PoolOptions` and immediately open at least one connection. This ensures the configuration is correct. The total number of connections opened is `max(1, min_connections)`. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **Pool** - A new database connection pool. #### Response Example None ``` -------------------------------- ### Get Day from OffsetDateTime Source: https://docs.rs/sqlx/latest/sqlx/types/time/struct.OffsetDateTime.html?search= Extract the day of the month from an OffsetDateTime, within the range of 1 to 31. Examples show behavior with offset changes. ```rust assert_eq!(datetime!(2019-01-01 0:00 UTC).day(), 1); assert_eq!( datetime!(2019-12-31 23:00 UTC) .to_offset(offset!(+1)) .day(), 1, ); ``` -------------------------------- ### Get Unix Timestamp in Nanoseconds from OffsetDateTime Source: https://docs.rs/sqlx/latest/sqlx/types/time/struct.OffsetDateTime.html?search= Obtain the Unix timestamp with nanosecond precision from an OffsetDateTime. Includes examples for UTC and a negative offset. ```rust use time_macros::datetime; assert_eq!(datetime!(1970-01-01 0:00 UTC).unix_timestamp_nanos(), 0); assert_eq!( datetime!(1970-01-01 0:00 -1).unix_timestamp_nanos(), 3_600_000_000_000, ); ``` -------------------------------- ### install_drivers Source: https://docs.rs/sqlx/latest/sqlx/any/fn.install_drivers.html?search= Installs the list of drivers for `AnyConnection` or `AnyPool` to use. This function must be called before an `AnyConnection` or `AnyPool` can be connected. It returns an error if called more than once. ```APIDOC ## install_drivers ### Description Installs the list of drivers for `AnyConnection` or `AnyPool` to use. Must be called before an `AnyConnection` or `AnyPool` can be connected. ### Errors If called more than once. ### Signature ```rust pub fn install_drivers( drivers: &'static [AnyDriver], ) -> Result<(), Box> ``` ### Available On * crate feature `any` only. ``` -------------------------------- ### begin_with Source: https://docs.rs/sqlx/latest/sqlx/prelude/trait.Connection.html?search= Begins a new transaction with a custom SQL statement. It returns a `Transaction` object for managing the transaction and returns an error if the connection is already in a transaction or if the provided statement does not initiate a transaction. ```APIDOC ## begin_with ### Description Begins a new transaction with a custom SQL statement. Returns a `Transaction` for controlling and tracking the new transaction. Returns an error if the connection is already in a transaction or if `statement` does not put the connection into a transaction. ### Method `begin_with(&mut self, statement: impl SqlSafeStr)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response - `Transaction<'_, Self::Database>`: A transaction object for managing the transaction. #### Response Example None ``` -------------------------------- ### Get Broadcast Address of Ipv4Network Source: https://docs.rs/sqlx/latest/sqlx/types/ipnetwork/enum.IpNetwork.html Calculates the broadcast address (highest IP) for an IPv4 network. Note: This example uses Ipv4Network specifically. ```rust use std::net::Ipv4Addr; use ipnetwork::{IpNetwork, Ipv4Network}; let net: Ipv4Network = "10.9.0.32/16".parse().unwrap(); assert_eq!(net.broadcast(), Ipv4Addr::new(10, 9, 255, 255)); ``` -------------------------------- ### Get Sunday-Based Week Number Source: https://docs.rs/sqlx/latest/sqlx/types/time/struct.PrimitiveDateTime.html Demonstrates retrieving the week number where week 1 starts on Sunday. The value ranges from 0 to 53. ```rust assert_eq!(datetime!(2019-01-01 0:00).sunday_based_week(), 0); assert_eq!(datetime!(2020-01-01 0:00).sunday_based_week(), 0); assert_eq!(datetime!(2020-12-31 0:00).sunday_based_week(), 52); assert_eq!(datetime!(2021-01-01 0:00).sunday_based_week(), 0); ``` -------------------------------- ### MySqlConnection::connect_with Source: https://docs.rs/sqlx/latest/sqlx/struct.MySqlConnection.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Establishes a new database connection with provided options. ```APIDOC ## fn connect_with( options: &Self::Options, ) -> impl Future> + Send ### Description Establish a new database connection with the provided options. ### Method fn ### Parameters - `options`: A reference to the `MySqlConnectOptions` for the connection. ### Response - `impl Future> + Send`: A future that resolves to a new `MySqlConnection` instance or an `Error`. ``` -------------------------------- ### Get Day of Month (0-30) - NaiveDateTime Source: https://docs.rs/sqlx/latest/sqlx/types/chrono/struct.NaiveDateTime.html Retrieves the day of the month, starting from 0, from a NaiveDateTime object. The value ranges from 0 to 30. ```rust use chrono::{Datelike, NaiveDate, NaiveDateTime}; let dt: NaiveDateTime = NaiveDate::from_ymd_opt(2015, 9, 25).unwrap().and_hms_opt(12, 34, 56).unwrap(); assert_eq!(dt.day0(), 24); ``` -------------------------------- ### Connect to Database with PoolOptions Source: https://docs.rs/sqlx/latest/sqlx/mysql/type.MySqlPoolOptions.html?search=std%3A%3Avec Create a new database pool and immediately establish at least one connection using the provided URL. This method ensures the configuration is valid and opens `max(1, min_connections)` connections. ```rust let pool = MySqlPoolOptions::new() .connect("mysql://user:password@host/database") .await?; ``` -------------------------------- ### install_default_drivers Source: https://docs.rs/sqlx/latest/sqlx/any/fn.install_default_drivers.html Installs all currently compiled-in drivers for `AnyConnection` to use. This function is idempotent; subsequent calls have no effect after the first successful call. It is available only when the `any` crate feature is enabled. ```APIDOC ## Function install_default_drivers ### Signature ```rust pub fn install_default_drivers() ``` ### Description Installs all currently compiled-in drivers for `AnyConnection` to use. May be called multiple times; only the first call will install drivers, subsequent calls will have no effect. ### Availability Available on **crate feature `any`** only. ### Panics If `install_drivers` has already been called _not_ through this function. ``` -------------------------------- ### Get Second from OffsetDateTime Source: https://docs.rs/sqlx/latest/sqlx/types/time/struct.OffsetDateTime.html?search= Extracts the second component (0-59) within the minute from an OffsetDateTime, considering the stored offset. Includes examples with offset adjustments. ```rust assert_eq!(datetime!(2019-01-01 0:00 UTC).second(), 0); assert_eq!( datetime!(2019-01-01 23:59:59 UTC) .to_offset(offset!(+0:00:30)) .second(), 29, ); ``` -------------------------------- ### begin_with Source: https://docs.rs/sqlx/latest/sqlx/prelude/trait.Connection.html Begins a new transaction with a custom SQL statement. Returns a `Transaction` object for managing the transaction lifecycle. ```APIDOC ## begin_with ### Description Begins a new transaction with a custom SQL statement. Returns a `Transaction` object for managing the transaction lifecycle. ### Method BeginWith ### Endpoint N/A (SDK Method) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response - **Transaction** (Transaction) - An object for controlling and tracking the new transaction. #### Response Example N/A ``` -------------------------------- ### Get Minute from OffsetDateTime Source: https://docs.rs/sqlx/latest/sqlx/types/time/struct.OffsetDateTime.html?search= Retrieves the minute component (0-59) within the hour from an OffsetDateTime, adjusted for its offset. Shows examples with and without offset adjustments. ```rust assert_eq!(datetime!(2019-01-01 0:00 UTC).minute(), 0); assert_eq!( datetime!(2019-01-01 23:59:59 UTC) .to_offset(offset!(+0:30)) .minute(), 29, ); ``` -------------------------------- ### Initialize QueryBuilder with new Source: https://docs.rs/sqlx/latest/sqlx/query_builder/struct.QueryBuilder.html?search=u32+-%3E+bool Starts building a query with an initial SQL fragment. The initial fragment can be an empty string. ```rust pub fn new(init: impl Into) -> QueryBuilder where ::Arguments: Default, ``` -------------------------------- ### Get Ordinal Day of Year (0-365) - NaiveDateTime Source: https://docs.rs/sqlx/latest/sqlx/types/chrono/struct.NaiveDateTime.html Retrieves the day of the year, starting from 0, from a NaiveDateTime object. The value ranges from 0 to 365. ```rust use chrono::{Datelike, NaiveDate, NaiveDateTime}; let dt: NaiveDateTime = NaiveDate::from_ymd_opt(2015, 9, 25).unwrap().and_hms_opt(12, 34, 56).unwrap(); assert_eq!(dt.ordinal0(), 267); ``` -------------------------------- ### connect_with Source: https://docs.rs/sqlx/latest/sqlx/pool/struct.Pool.html?search=std%3A%3Avec Creates a new connection pool with default configuration and establishes one connection immediately using the provided `ConnectOptions`. Supports feature `any`. ```APIDOC ## connect_with ### Description Create a new connection pool with a default pool configuration and the given `ConnectOptions`, and immediately establish one connection. ### Signature `pub async fn connect_with(options: <::Connection as Connection>::Options) -> Result, Error>` ### Parameters * `options` - The `ConnectOptions` for the database connection. ### Returns A `Result` containing a `Pool` on success or an `Error` on failure. ### Feature Available on **crate feature`any`** only. ``` -------------------------------- ### Get Ordinal Day of Year (1-366) - NaiveDateTime Source: https://docs.rs/sqlx/latest/sqlx/types/chrono/struct.NaiveDateTime.html Retrieves the day of the year, starting from 1, from a NaiveDateTime object. The value ranges from 1 to 366. ```rust use chrono::{Datelike, NaiveDate, NaiveDateTime}; let dt: NaiveDateTime = NaiveDate::from_ymd_opt(2015, 9, 25).unwrap().and_hms_opt(12, 34, 56).unwrap(); assert_eq!(dt.ordinal(), 268); ``` -------------------------------- ### Get the current stream position Source: https://docs.rs/sqlx/latest/sqlx/_config/macros/type.ColumnName.html?search=u32+-%3E+bool The `stream_position` method returns the current byte offset from the start of the stream. This is useful for tracking progress or resuming operations. ```rust fn stream_position(&mut self) -> Result ``` -------------------------------- ### install_default_drivers Source: https://docs.rs/sqlx/latest/sqlx/any/fn.install_default_drivers.html?search=std%3A%3Avec Installs all currently compiled-in drivers for `AnyConnection` to use. Subsequent calls have no effect. Panics if `install_drivers` has already been called. ```APIDOC ## Function install_default_drivers ### Description Install all currently compiled-in drivers for `AnyConnection` to use. May be called multiple times; only the first call will install drivers, subsequent calls will have no effect. ### Panics If `install_drivers` has already been called _not_ through this function. ``` -------------------------------- ### Get ISO Week Number from OffsetDateTime Source: https://docs.rs/sqlx/latest/sqlx/types/time/struct.OffsetDateTime.html?search= Extract the ISO 8601 week number (1-53) from an OffsetDateTime. Examples cover different dates and year transitions. ```rust assert_eq!(datetime!(2019-01-01 0:00 UTC).iso_week(), 1); assert_eq!(datetime!(2020-01-01 0:00 UTC).iso_week(), 1); assert_eq!(datetime!(2020-12-31 0:00 UTC).iso_week(), 53); assert_eq!(datetime!(2021-01-01 0:00 UTC).iso_week(), 53); ``` -------------------------------- ### Establish a New Database Connection with Options Source: https://docs.rs/sqlx/latest/sqlx/prelude/trait.Connection.html?search= Connect to a database using pre-defined options. This provides more control over connection parameters than using a URL string. ```rust sqlx::connect_with(options).await? ``` -------------------------------- ### install_default_drivers Source: https://docs.rs/sqlx/latest/sqlx/any/fn.install_default_drivers.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Installs all currently compiled-in drivers for `AnyConnection` to use. This function can be called multiple times, but only the first call will install drivers; subsequent calls will have no effect. It may panic if `install_drivers` has already been called not through this function. ```APIDOC ## Function install_default_drivers Available on **crate feature`any`** only. ### Description Install all currently compiled-in drivers for `AnyConnection` to use. May be called multiple times; only the first call will install drivers, subsequent calls will have no effect. #### Panics If `install_drivers` has already been called _not_ through this function. ### Signature ```rust pub fn install_default_drivers() ``` ``` -------------------------------- ### Get Millisecond Timestamp from DateTime Source: https://docs.rs/sqlx/latest/sqlx/types/chrono/struct.DateTime.html Returns the number of non-leap milliseconds since January 1, 1970 UTC. Examples show conversion from NaiveDateTime with offset. ```rust use chrono::{NaiveDate, Utc}; let dt = NaiveDate::from_ymd_opt(1970, 1, 1) .unwrap() .and_hms_milli_opt(0, 0, 1, 444) .unwrap() .and_local_timezone(Utc) .unwrap(); assert_eq!(dt.timestamp_millis(), 1_444); let dt = NaiveDate::from_ymd_opt(2001, 9, 9) .unwrap() .and_hms_milli_opt(1, 46, 40, 555) .unwrap() .and_local_timezone(Utc) .unwrap(); assert_eq!(dt.timestamp_millis(), 1_000_000_000_555); ``` -------------------------------- ### Get element offset for unaligned reference Source: https://docs.rs/sqlx/latest/sqlx/postgres/struct.PgArgumentBuffer.html?search=std%3A%3Avec Demonstrates `element_offset` returning `None` when the provided reference does not point to the start of an element within the slice, such as when it points between elements. ```rust let arr: &[[u32; 2]] = &[[0, 1], [2, 3]]; let flat_arr: &[u32] = arr.as_flattened(); let ok_elm: &[u32; 2] = flat_arr[0..2].try_into().unwrap(); let weird_elm: &[u32; 2] = flat_arr[1..3].try_into().unwrap(); assert_eq!(ok_elm, &[0, 1]); assert_eq!(weird_elm, &[1, 2]); assert_eq!(arr.element_offset(ok_elm), Some(0)); // Points to element 0 assert_eq!(arr.element_offset(weird_elm), None); // Points between element 0 and 1 ``` -------------------------------- ### Connect to Database with Options Source: https://docs.rs/sqlx/latest/sqlx/pool/struct.PoolOptions.html?search= Create a new connection pool and establish at least one connection using specific connection options. This method ensures the provided options are valid and at least `min_connections` are available. ```rust let pool = PgPoolOptions::new() .connect_with(options) .await?; ``` -------------------------------- ### BigDecimal Fractional Digit Count Examples Source: https://docs.rs/sqlx/latest/sqlx/types/struct.BigDecimal.html Demonstrates how to get the number of digits to the right of the decimal point for a BigDecimal. Handles positive, negative, and zero fractional parts. ```rust use bigdecimal::BigDecimal; use std::str::FromStr; let a = BigDecimal::from(12345); // No fractional part let b = BigDecimal::from_str("123.45").unwrap(); // Fractional part let c = BigDecimal::from_str("0.0000012345").unwrap(); // Completely fractional part let d = BigDecimal::from_str("5e9").unwrap(); // Negative-fractional part assert_eq!(a.fractional_digit_count(), 0); assert_eq!(b.fractional_digit_count(), 2); assert_eq!(c.fractional_digit_count(), 10); assert_eq!(d.fractional_digit_count(), -9); ``` -------------------------------- ### AnyConnectOptions Implementation Source: https://docs.rs/sqlx/latest/sqlx/prelude/trait.ConnectOptions.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Example implementation of `ConnectOptions` for `AnyConnection`, allowing connections to various database types through a unified interface. ```rust type Connection = AnyConnection ```