Trait ockam::ToSqlxType

source ·
pub trait ToSqlxType {
    // Required method
    fn to_sql(&self) -> SqlxType;
}
Expand description

This trait can be implemented by any type that can be converted to a database type Typically an Identifier (to a Text), a TimestampInSeconds (to an Integer) etc…

This allows a value to be used as a bind parameters in a sqlx query for example:

use std::str::FromStr; use sqlx::query_as; use ockam_node::database::{SqlxType, ToSqlxType};

// newtype for a UNIX-like timestamp struct TimestampInSeconds(u64);

// this implementation maps the TimestampInSecond type to one of the types that Sqlx // can serialize for sqlite impl ToSqlxType for TimestampInSeconds { fn to_sql(&self) -> SqlxType { self.0.to_sql() } }

let timestamp = TimestampInSeconds(10000000); let query = query_as(“SELECT identifier, change_history FROM identity WHERE created_at >= $1”).bind(timestamp.as_sql());

Required Methods§

source

fn to_sql(&self) -> SqlxType

Return the appropriate sql type

Implementations on Foreign Types§

source§

impl ToSqlxType for &str

source§

impl ToSqlxType for &[u8; 32]

source§

impl ToSqlxType for Purpose

source§

impl ToSqlxType for bool

source§

impl ToSqlxType for i8

source§

impl ToSqlxType for i16

source§

impl ToSqlxType for i32

source§

impl ToSqlxType for u8

source§

impl ToSqlxType for u16

source§

impl ToSqlxType for u32

source§

impl ToSqlxType for u64

source§

impl ToSqlxType for PathBuf

source§

impl ToSqlxType for Action

source§

impl ToSqlxType for Resource

source§

impl ToSqlxType for ChangeHistory

source§

impl ToSqlxType for Identifier

source§

impl ToSqlxType for TimestampInSeconds

source§

impl ToSqlxType for OffsetDateTime

Implementors§