Struct pgx_utils::sql_entity_graph::ToSqlConfigEntity
source · pub struct ToSqlConfigEntity {
pub enabled: bool,
pub callback: Option<fn(_: &SqlGraphEntity, _: &PgxSql) -> Result<String, Box<dyn Error + Send + Sync + 'static>>>,
pub content: Option<&'static str>,
}Expand description
Represents configuration options for tuning the SQL generator.
When an item that can be rendered to SQL has these options at hand, they should be respected. If an item does not have them, then it is not expected that the SQL generation for those items can be modified.
The default configuration has enabled set to true, and callback to None, which indicates
that the default SQL generation behavior will be used. These are intended to be mutually exclusive
options, so callback should only be set if generation is enabled.
When enabled is false, no SQL is generated for the item being configured.
When callback has a value, the corresponding ToSql implementation should invoke the
callback instead of performing their default behavior.
Fields
enabled: boolcallback: Option<fn(_: &SqlGraphEntity, _: &PgxSql) -> Result<String, Box<dyn Error + Send + Sync + 'static>>>content: Option<&'static str>Implementations
sourceimpl ToSqlConfigEntity
impl ToSqlConfigEntity
sourcepub fn to_sql(
&self,
entity: &SqlGraphEntity,
context: &PgxSql
) -> Option<Result<String>>
pub fn to_sql(
&self,
entity: &SqlGraphEntity,
context: &PgxSql
) -> Option<Result<String>>
Given a SqlGraphEntity, this function converts it to SQL based on the current configuration.
If the config overrides the default behavior (i.e. using the ToSql trait), then Some(eyre::Result)
is returned. If the config does not override the default behavior, then None is returned. This can
be used to dispatch SQL generation in a single line, e.g.:
config.to_sql(entity, context).unwrap_or_else(|| entity.to_sql(context))?Trait Implementations
sourceimpl Clone for ToSqlConfigEntity
impl Clone for ToSqlConfigEntity
sourcefn clone(&self) -> ToSqlConfigEntity
fn clone(&self) -> ToSqlConfigEntity
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresourceimpl Debug for ToSqlConfigEntity
impl Debug for ToSqlConfigEntity
sourceimpl Default for ToSqlConfigEntity
impl Default for ToSqlConfigEntity
sourcefn default() -> ToSqlConfigEntity
fn default() -> ToSqlConfigEntity
sourceimpl Hash for ToSqlConfigEntity
impl Hash for ToSqlConfigEntity
sourceimpl PartialEq<ToSqlConfigEntity> for ToSqlConfigEntity
impl PartialEq<ToSqlConfigEntity> for ToSqlConfigEntity
impl Eq for ToSqlConfigEntity
Auto Trait Implementations
impl RefUnwindSafe for ToSqlConfigEntity
impl Send for ToSqlConfigEntity
impl Sync for ToSqlConfigEntity
impl Unpin for ToSqlConfigEntity
impl UnwindSafe for ToSqlConfigEntity
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.