surrealdb_core/sql/statements/
use.rs1use revision::revisioned;
2use serde::{Deserialize, Serialize};
3use std::fmt;
4
5use crate::sql::escape::escape_ident;
6
7#[revisioned(revision = 1)]
8#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
9#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
10#[non_exhaustive]
11pub struct UseStatement {
12 pub ns: Option<String>,
13 pub db: Option<String>,
14}
15
16impl fmt::Display for UseStatement {
17 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
18 f.write_str("USE")?;
19 if let Some(ref ns) = self.ns {
20 let ns = escape_ident(ns);
21 write!(f, " NS {ns}")?;
22 }
23 if let Some(ref db) = self.db {
24 let db = escape_ident(db);
25 write!(f, " DB {db}")?;
26 }
27 Ok(())
28 }
29}