pub struct Record { /* private fields */ }Expand description
Implementations§
Source§impl Record
impl Record
Sourcepub fn is_sql_null(&self, key: &str) -> bool
pub fn is_sql_null(&self, key: &str) -> bool
该列是否为 SQL NULL(区别于 JSON 字面量 null)。
列不存在时返回 false。
Sourcepub fn is_json_null(&self, key: &str) -> bool
pub fn is_json_null(&self, key: &str) -> bool
该列是否为 PostgreSQL json/jsonb 的 JSON 字面量 null。
Sourcepub fn insert(
&mut self,
key: impl Into<String>,
value: impl Into<Value>,
) -> Option<Value>
pub fn insert( &mut self, key: impl Into<String>, value: impl Into<Value>, ) -> Option<Value>
写入字段值并返回被替换的旧值。
Sourcepub fn remove_column(&mut self, key: &str) -> Option<Value>
pub fn remove_column(&mut self, key: &str) -> Option<Value>
移除指定列并返回其原值。
同时从 JSON null sidecar 中移除该列,避免列已不存在却仍被
Record::is_json_null 判定为 JSON null。
§返回
Some(Value):列存在时返回被移除的值None:列不存在
Sourcepub fn retain_columns(&mut self, keys: &[&str])
pub fn retain_columns(&mut self, keys: &[&str])
只保留指定列,其余列及其 JSON null 登记一并移除。
用于多列投影:投影结果必须保留 Record::is_json_null 的区分能力,
不能经 into_map() + Record::from 重建(那会丢失 sidecar)。
Sourcepub fn require<T>(&self, key: &str) -> Result<T, BaseError>where
T: DeserializeOwned,
pub fn require<T>(&self, key: &str) -> Result<T, BaseError>where
T: DeserializeOwned,
读取必需字段并转换为目标类型。
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Record
impl<'de> Deserialize<'de> for Record
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<'r> FromRow<'r, MySqlRow> for Record
Available on crate feature mysql only.实现 sqlx::FromRow,支持从 MySQL 查询结果动态解码
impl<'r> FromRow<'r, MySqlRow> for Record
Available on crate feature
mysql only.实现 sqlx::FromRow,支持从 MySQL 查询结果动态解码
按 MySQL 列类型将值映射到对应的 JSON 类型:
- INT/BIGINT/MEDIUMINT/SMALLINT → i64
- TINYINT → i8
- TINYINT UNSIGNED → u8
- FLOAT/DOUBLE → f64
- DECIMAL/NUMERIC → String(保留精度)
- VARCHAR/TEXT/CHAR → String
- BOOLEAN(即 TINYINT(1))→ Bool
- DATE/DATETIME/TIMESTAMP → ISO 8601 字符串
- NULL → Null
- BLOB/BINARY → Base64 字符串
- JSON → Object/Array
Source§impl<'r> FromRow<'r, PgRow> for Record
Available on crate feature postgres only.实现 sqlx::FromRow,支持从 PostgreSQL 查询结果动态解码。
impl<'r> FromRow<'r, PgRow> for Record
Available on crate feature
postgres only.实现 sqlx::FromRow,支持从 PostgreSQL 查询结果动态解码。
与 MySQL 实现并存,按 feature 分别编译。类型分派基于 OID / PgTypeKind,
不依赖可能被用户自定义类型复用的类型名。
Source§impl JsonSchema for Record
impl JsonSchema for Record
Source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
Whether JSON Schemas generated for this type should be re-used where possible using the
$ref keyword. Read moreSource§fn schema_name() -> String
fn schema_name() -> String
The name of the generated JSON Schema. Read more
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Returns a string that uniquely identifies the schema produced by this type. Read more
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
impl StructuralPartialEq for Record
Auto Trait Implementations§
impl Forget for Record
impl Freeze for Record
impl Move for Record
impl RefUnwindSafe for Record
impl Send for Record
impl Sync for Record
impl Unpin for Record
impl UnsafeUnpin for Record
impl UnwindSafe for Record
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more