edgedb_sdk/lib.rs
1//! EdgeDB WebAssembly SDK
2//!
3//! # Example
4//!
5//! The primary use of this SDK is to create a web handler, and to make some
6//! database queries inside that handler. Somewhat minimal example:
7//!
8//! ```rust,no_run
9//! use edgedb_sdk::web;
10//! use edgedb_sdk::client::{Client, create_client};
11//! use once_cell::sync::Lazy;
12//!
13//! static CLIENT: Lazy<Client> = Lazy::new(|| create_client());
14//!
15//! #[web::handler]
16//! fn handler(_req: web::Request) -> web::Response {
17//! let query_result = CLIENT.query_required_single::<i64, _>(
18//! "SELECT 7*8",
19//! &(),
20//! );
21//! match query_result {
22//! Ok(value) => {
23//! web::response()
24//! .status(web::StatusCode::OK)
25//! .header("Content-Type", "text/html")
26//! .body(format!("7 times 8 is {value}").into())
27//! .expect("response is built")
28//! }
29//! Err(e) => {
30//! log::error!("Error handling request: {:#}", e);
31//! web::response()
32//! .status(web::StatusCode::INTERNAL_SERVER_ERROR)
33//! .header("Content-Type", "text/plain")
34//! .body(format!("Internal Server Error").into())
35//! .expect("response is built")
36//! }
37//! }
38//! }
39//! ```
40#![warn(missing_debug_implementations, missing_docs)]
41
42mod http_server;
43mod bug;
44mod bindgen;
45
46#[cfg(feature="client")]
47pub mod client;
48pub mod web;
49pub mod log;
50
51pub use edgedb_sdk_macros::init_hook;
52
53#[cfg(not(feature="host"))]
54#[export_name = "_edgedb_sdk_pre_init"]
55extern "C" fn init() {
56 log::init();
57}