pub struct JsonUpdate { /* private fields */ }Expand description
JSON 字段更新构造器
提供 think-orm 风格的 JSON 字段 SET 子句构造。
- MySQL:
JSON_SET(col, '$.key', 'value') - PG:
jsonb_set(col, '{key}', '"value"') - SQLite:
json_set(col, '$.key', 'value')
Implementations§
Source§impl JsonUpdate
impl JsonUpdate
Sourcepub fn set_str(self, key: impl Into<String>, value: &str) -> JsonUpdate
pub fn set_str(self, key: impl Into<String>, value: &str) -> JsonUpdate
添加一个 SET 项(key → value,value 为字符串)
Sourcepub fn set_i64(self, key: impl Into<String>, value: i64) -> JsonUpdate
pub fn set_i64(self, key: impl Into<String>, value: i64) -> JsonUpdate
添加一个 SET 项(key → value,value 为 i64)
Sourcepub fn set_bool(self, key: impl Into<String>, value: bool) -> JsonUpdate
pub fn set_bool(self, key: impl Into<String>, value: bool) -> JsonUpdate
添加一个 SET 项(key → value,value 为 bool)
Sourcepub fn array_append_str(self, key: impl Into<String>, value: &str) -> JsonUpdate
pub fn array_append_str(self, key: impl Into<String>, value: &str) -> JsonUpdate
数组追加元素(字符串):将 value 追加到 col.path 指向的数组末尾
- MySQL:
col = JSON_ARRAY_APPEND(col, '$.path', 'v') - PG:
col = jsonb_set(col, '{path}', (col#>'{path}') || to_jsonb('v'::text)) - SQLite:
col = json_set(col, '$.path', json_insert(col->'$.path', '$[#]', 'v'))
注:追加多个元素请多次调用。
Sourcepub fn array_append_i64(self, key: impl Into<String>, value: i64) -> JsonUpdate
pub fn array_append_i64(self, key: impl Into<String>, value: i64) -> JsonUpdate
数组追加元素(整数)
Sourcepub fn remove_key(self, key: impl Into<String>) -> JsonUpdate
pub fn remove_key(self, key: impl Into<String>) -> JsonUpdate
删除指定 JSON 路径的字段
- MySQL:
col = JSON_REMOVE(col, '$.key') - PG:
col = col - 'key' - SQLite:
col = json_remove(col, '$.key')
Auto Trait Implementations§
impl Freeze for JsonUpdate
impl RefUnwindSafe for JsonUpdate
impl Send for JsonUpdate
impl Sync for JsonUpdate
impl Unpin for JsonUpdate
impl UnsafeUnpin for JsonUpdate
impl UnwindSafe for JsonUpdate
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> 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