1#![allow(non_local_definitions)]
35
36mod connection;
37mod conversions;
38mod cursor;
39mod profiling;
40
41pub use connection::Database;
43pub use cursor::Cursor;
44use pyo3::{exceptions::PyException, prelude::*};
45
46pyo3::create_exception!(vibesql, Warning, PyException);
48pyo3::create_exception!(vibesql, Error, PyException);
49pyo3::create_exception!(vibesql, InterfaceError, Error);
50pyo3::create_exception!(vibesql, DatabaseError, Error);
51pyo3::create_exception!(vibesql, DataError, DatabaseError);
52pyo3::create_exception!(vibesql, OperationalError, DatabaseError);
53pyo3::create_exception!(vibesql, IntegrityError, DatabaseError);
54pyo3::create_exception!(vibesql, InternalError, DatabaseError);
55pyo3::create_exception!(vibesql, ProgrammingError, DatabaseError);
56pyo3::create_exception!(vibesql, NotSupportedError, DatabaseError);
57
58#[pyfunction]
73fn connect() -> PyResult<Database> {
74 Ok(Database::new())
75}
76
77#[pyfunction]
83fn enable_profiling() {
84 profiling::enable_profiling();
85}
86
87#[pyfunction]
91fn disable_profiling() {
92 profiling::disable_profiling();
93}
94
95#[pymodule]
99fn vibesql(m: &Bound<'_, PyModule>) -> PyResult<()> {
100 m.add("apilevel", "2.0")?;
102 m.add("threadsafety", 1)?;
103 m.add("paramstyle", "qmark")?;
104
105 m.add_function(wrap_pyfunction!(connect, m)?)?;
106 m.add_function(wrap_pyfunction!(enable_profiling, m)?)?;
107 m.add_function(wrap_pyfunction!(disable_profiling, m)?)?;
108 m.add_class::<Database>()?;
109 m.add_class::<Cursor>()?;
110
111 m.add("Warning", m.py().get_type::<Warning>())?;
113 m.add("Error", m.py().get_type::<Error>())?;
114 m.add("InterfaceError", m.py().get_type::<InterfaceError>())?;
115 m.add("DatabaseError", m.py().get_type::<DatabaseError>())?;
116 m.add("DataError", m.py().get_type::<DataError>())?;
117 m.add("OperationalError", m.py().get_type::<OperationalError>())?;
118 m.add("IntegrityError", m.py().get_type::<IntegrityError>())?;
119 m.add("InternalError", m.py().get_type::<InternalError>())?;
120 m.add("ProgrammingError", m.py().get_type::<ProgrammingError>())?;
121 m.add("NotSupportedError", m.py().get_type::<NotSupportedError>())?;
122
123 Ok(())
124}