pub trait IntoParam {
// Required method
fn into_param(self) -> Param;
}Expand description
Types that can be bound as D1 query parameters.
Implemented for text (&str, String, &String), bool (INTEGER 1/0),
f64, integers up to 32 bits, i64 (see MAX_SAFE_INTEGER),
serde_json::Value (stored as compact JSON text), Option<T> (None is
NULL) and Param itself. params! calls it on each
value; implement it for your own types (e.g. an enum stored as text) by
delegating to one of these.
§Examples
use ocre::{IntoParam, Param, params};
enum Status {
Draft,
Published,
}
impl IntoParam for Status {
fn into_param(self) -> Param {
match self {
Status::Draft => "draft",
Status::Published => "published",
}
.into_param()
}
}
assert_eq!(params![Status::Published], params!["published"]);Required Methods§
Sourcefn into_param(self) -> Param
fn into_param(self) -> Param
Converts the value into a bound parameter.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl IntoParam for Value
JSON values are stored as their compact text in a TEXT column (the
generators add CHECK (json_valid(<column>))). Read them back with
#[serde(deserialize_with = "ocre::json_from_sql")].
impl IntoParam for Value
JSON values are stored as their compact text in a TEXT column (the
generators add CHECK (json_valid(<column>))). Read them back with
#[serde(deserialize_with = "ocre::json_from_sql")].
fn into_param(self) -> Param
Source§impl IntoParam for bool
SQLite has no boolean type: true/false are stored as INTEGER 1/0.
Read them back with #[serde(deserialize_with = "ocre::bool_from_sql")].
impl IntoParam for bool
SQLite has no boolean type: true/false are stored as INTEGER 1/0.
Read them back with #[serde(deserialize_with = "ocre::bool_from_sql")].
fn into_param(self) -> Param
Source§impl IntoParam for i64
Integers within ±(2^53 - 1) are bound as numbers. Larger values are bound
as decimal text, exact for comparisons in WHERE clauses.
impl IntoParam for i64
Integers within ±(2^53 - 1) are bound as numbers. Larger values are bound
as decimal text, exact for comparisons in WHERE clauses.
fn into_param(self) -> Param
Implementors§
impl IntoParam for Deterministic
Binds the encrypted text. Without installed keys (no valid
SECRET_KEY_BASE) it binds NULL, which a NOT NULL column
refuses; the error is logged.
impl IntoParam for Encrypted
Binds the encrypted text. Without installed keys (no valid
SECRET_KEY_BASE) it binds NULL, which a NOT NULL column
refuses; the error is logged.