Skip to main content

schema_sql_generator/common/
sql_writer.rs

1use crate::common::print_writer::PrintWriter;
2use std::cell::RefCell;
3use std::rc::Rc;
4
5#[derive(Clone)]
6pub struct SqlWriter {
7    print_writer: Rc<RefCell<PrintWriter>>,
8}
9
10impl SqlWriter {
11    pub fn new(writer: Rc<RefCell<PrintWriter>>) -> Self {
12        Self {
13            print_writer: writer,
14        }
15    }
16
17    pub fn print(&mut self, text: &str) {
18        self.print_writer.borrow_mut().print(text)
19    }
20
21    pub fn println(&mut self, text: &str) {
22        self.print_writer.borrow_mut().println(text)
23    }
24
25    pub fn printf(&mut self, args: std::fmt::Arguments) {
26        self.print_writer.borrow_mut().printf(args)
27    }
28
29    pub fn newline(&mut self) {
30        self.print_writer.borrow_mut().newline()
31    }
32}
33
34#[macro_export]
35macro_rules! sql_print {
36    ($writer:expr, $($arg:tt)*) => {
37        $writer.printf(format_args!($($arg)*));
38    };
39}
40
41#[macro_export]
42macro_rules! sql_println {
43    ($writer:expr, $($arg:tt)*) => {
44        $writer.printf(format_args!($($arg)*));
45        $writer.newline();
46    };
47}
48
49#[macro_export]
50macro_rules! sql_newline {
51    ($writer:expr) => {
52        $writer.newline();
53    };
54}