Skip to main content

reifydb_sql/
lib.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2// Copyright (c) 2026 ReifyDB
3
4//! SQL-to-RQL transpiler. Tokenises, parses, and emits a SQL statement into the equivalent RQL surface so callers
5//! who arrive with a SQL query can submit it to an engine that natively speaks RQL. Coverage is intentionally narrow:
6//! the goal is to support the SQL dialects existing tooling produces (SELECT, INSERT, UPDATE, DELETE, basic DDL),
7//! not to be a full ANSI implementation.
8//!
9//! The crate produces RQL text rather than a planner-internal tree on purpose - the boundary stays at the source
10//! level, so SQL behaviour can be verified by reading the emitted RQL and the resulting RQL diagnostics carry the
11//! source span the user submitted.
12
13#![cfg_attr(not(debug_assertions), deny(clippy::disallowed_methods))]
14#![cfg_attr(debug_assertions, warn(clippy::disallowed_methods))]
15
16use std::{error, fmt};
17
18#[cfg_attr(not(debug_assertions), deny(warnings))]
19pub mod ast;
20pub mod emit;
21pub mod parser;
22pub mod token;
23
24#[derive(Debug, Clone)]
25pub struct Error(pub String);
26
27impl fmt::Display for Error {
28	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29		write!(f, "{}", self.0)
30	}
31}
32
33impl error::Error for Error {}
34
35pub fn transpile(sql: &str) -> Result<String, Error> {
36	let tokens = token::tokenize(sql)?;
37	let ast = parser::Parser::new(tokens).parse()?;
38	let rql = emit::emit(&ast)?;
39	Ok(rql)
40}