SqliteClient

Struct SqliteClient 

Source
pub struct SqliteClient { /* private fields */ }
Expand description

SQLite 客户端,用于连接SQLite数据库,可以进行crud操作

Implementations§

Source§

impl SqliteClient

Source

pub fn new(db_path: &str) -> Result<Self, Error>

创建一个新的 SQLite 客户端实例

该函数会打开指定路径的 SQLite 数据库文件,如果文件不存在则会自动创建

§参数
  • db_path - 数据库文件的路径字符串引用
§返回值
  • Ok(SqliteClient) - 成功创建的 SQLite 客户端实例
  • Err(sqlite::Error) - 数据库连接过程中发生的错误
§示例
let client = SqliteClient::new("database.db");
Source

pub fn execute(&self, sql: &str) -> Result<(), Error>

执行SQL语句

该函数用于执行不返回结果集的SQL语句(如INSERT、UPDATE、DELETE等)。 如果SQL语句返回了结果集,则会返回错误。

§参数
  • sql - 要执行的SQL语句字符串
§返回值
  • Ok(()) - SQL语句执行成功
  • Err(sqlite::Error) - SQL语句执行失败或返回了结果集
§错误

当SQL语句返回结果集时,会返回ExecuteReturnedResults错误, 此时应该使用query系列函数来处理

Source

pub fn query<T: FromSqliteRow>(&self, sql: &str) -> Vec<T>

执行SQL查询并返回结果集

该函数用于执行给定的SQL查询语句,并将查询结果转换为指定类型的向量。 结果类型T必须实现FromSqliteRow trait,以便能够从数据库行中创建实例。

§参数
  • sql - 要执行的SQL查询语句字符串引用
§返回值

返回包含查询结果的Vec,其中T是实现了FromSqliteRow trait的类型

§泛型约束

T: FromSqliteRow - 结果类型必须实现从SQLite行数据转换的trait

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,