MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / parse_create_database

Function parse_create_database

nodedb-sql/src/ddl_ast/parse/database/create.rs:10–41  ·  view source on GitHub ↗
(
    parts: &[&str],
    original: &str,
)

Source from the content-addressed store, hash-verified

8use super::with_options::parse_with_options;
9
10pub(super) fn parse_create_database(
11 parts: &[&str],
12 original: &str,
13) -> Result<NodedbStatement, SqlError> {
14 let mut idx = 2usize; // skip CREATE DATABASE
15 let if_not_exists = if parts.get(idx).map(|w| w.to_uppercase()).as_deref() == Some("IF")
16 && parts.get(idx + 1).map(|w| w.to_uppercase()).as_deref() == Some("NOT")
17 && parts.get(idx + 2).map(|w| w.to_uppercase()).as_deref() == Some("EXISTS")
18 {
19 idx += 3;
20 true
21 } else {
22 false
23 };
24
25 let name = parts
26 .get(idx)
27 .copied()
28 .ok_or_else(|| SqlError::Parse {
29 detail: "CREATE DATABASE requires a name".into(),
30 })?
31 .to_string();
32 let name = name.trim_matches('"').to_string();
33
34 let options = parse_with_options(original);
35
36 Ok(NodedbStatement::Database(DatabaseStmt::CreateDatabase {
37 name,
38 if_not_exists,
39 options,
40 }))
41}
42
43#[cfg(test)]
44mod tests {

Callers 1

try_parseFunction · 0.70

Calls 3

parse_with_optionsFunction · 0.85
to_stringMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected