pub struct DatabaseRef { /* private fields */ }Expand description
A handle to a Database with one level of access, made by
Database::admin, Database::write or Database::read. Copy,
and free to pass to other code.
Its calls are made as the user of its level. Where the runtime has no
user of that level, the next one up’s is used, and a read handle’s calls
are then made with the setting readonly = 2: a read handle’s writes are
refused either way.
Implementations§
Source§impl DatabaseRef
impl DatabaseRef
Sourcepub fn query(&self, sql: impl Into<String>) -> Query<'static>
pub fn query(&self, sql: impl Into<String>) -> Query<'static>
Begins a query: set its parameters, settings and query id on the
returned Query, then run it with a fetch method.
async fn kinds(id: u64) -> Result<Vec<String>, Error> {
EVENTS
.read()
.query("SELECT kind FROM events WHERE id = {id:UInt64}")
.param("id", id)
.fetch_all()
.await
}Sourcepub fn exec(&self, sql: impl Into<String>) -> Exec<'static>
pub fn exec(&self, sql: impl Into<String>) -> Exec<'static>
Begins a statement that returns no rows, such as an ALTER TABLE … UPDATE or an INSERT … SELECT: set its parameters and settings on
the returned Exec, then await it for an ExecResult. Any rows
it returns are discarded.
async fn forget(id: u64) -> Result<(), Error> {
EVENTS
.write()
.exec("DELETE FROM events WHERE id = {id:UInt64}")
.param("id", id)
.await?;
Ok(())
}Sourcepub fn insert<'a, T: Serialize>(
&self,
table: &str,
rows: &'a [T],
) -> Insert<'a, T>
pub fn insert<'a, T: Serialize>( &self, table: &str, rows: &'a [T], ) -> Insert<'a, T>
Begins an insert of rows into table (table or db.table): each
row is a struct or map whose fields are its columns (see the module
docs). Await it for an ExecResult; settings for
the insert, such as async_insert, are set on the returned Insert.
#[derive(serde::Serialize)]
struct Event<'a> {
id: u64,
kind: &'a str,
}
async fn record(id: u64) -> Result<(), Error> {
EVENTS
.write()
.insert("events", &[Event { id, kind: "signup" }])
.await?;
Ok(())
}Sourcepub fn connection_string(&self) -> Result<String, Error>
pub fn connection_string(&self) -> Result<String, Error>
The URL to connect to the database with, for a ClickHouse client
other than this SDK’s: http[s]://user:password@host:port/database,
with the user of the handle’s level, the user and password
URL-encoded. ClickHouse’s clients read the database from the path.
Where the runtime has no user of the handle’s level, the URL has the
next level up’s. The readonly setting that keeps a read handle’s
own calls from writing then isn’t in it: set it on the client.
Trait Implementations§
Source§impl Clone for DatabaseRef
impl Clone for DatabaseRef
impl Copy for DatabaseRef
Auto Trait Implementations§
impl !RefUnwindSafe for DatabaseRef
impl !UnwindSafe for DatabaseRef
impl Forget for DatabaseRef
impl Freeze for DatabaseRef
impl Move for DatabaseRef
impl Send for DatabaseRef
impl Sync for DatabaseRef
impl Unpin for DatabaseRef
impl UnsafeUnpin for DatabaseRef
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
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> ⓘ
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> ⓘ
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request