Module serde_db::ser

source ·
Expand description

Support for serializing rust types into parameters for database commands.

Implementing DB drivers can make use of this functionality when they need to translate rust values into their DB types.

Prepared statements for example might have a function

fn add_batch<T>(&mut self, input: &T) -> HdbResult<()>
where T: serde::ser::Serialize

The consumers of the add_batch() function can hand over a tuple of rust values that correspond to the parameters the prepared statement needs. Or they can hand over an appropriate struct that implements serde::ser::Serialize.

In both cases they do not need to differentiate between nullable and non-nullable database values (except that they cannot convert an Option::None into a non-nullable database value).

In its implementation of DbvFactory, the DB driver can decide to make their life even easier by converting flexibly between different number types (an example can be found in the tests of this crate)

The implementation of add_batch() converts input into a Vec of the driver’s database values that can subsequently be sent to the DB server:

    let db_values: Vec<DBValue> = serde_db::ser::to_params(&input, input_metadata)?;

It is assumed that the prepared statement has metadata about the required input parameters, which implement DbvFactory.

Enums

Error that can occur while serializing a standard rust type or struct into a SQL parameter.

Traits

A factory for database objects.

Functions

Factory for Parse Error.
Provided method that translates the input into a Vec of database values.
Factory for Parse Error.