-
Notifications
You must be signed in to change notification settings - Fork 7
/
lib.rs
66 lines (58 loc) · 1.26 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
///
use chrono::{DateTime, Utc};
pub mod serialization;
pub use datamodel::{self, common::preview_features::PreviewFeature};
pub use graphql_parser;
pub use inflector;
pub use juniper;
pub use prisma_derive::{self, Query};
pub use prisma_models;
pub use request_handlers;
pub use serde;
pub use log;
pub use futures;
pub use query_connector;
pub use query_core;
/// This allows objects(structs) describe what data they want want from the db.
///
/// ideally you aren't deriving this directly, you're using the derive proc macro `Query`.
///
/// ```rust
/// #[derive(Query)]
/// struct User {
/// id: String,
/// name: String
/// }
///
/// User::query(); // Produces `{ id name }`, which is then interpolated into a graphql query.
/// ```
pub trait Queryable {
fn query() -> String;
}
macro_rules! generate_queryable_impl {
(
$($y:ty),+
) => {
$(impl Queryable for $y {
fn query() -> String {
String::new()
}
})+
}
}
generate_queryable_impl!(i64, i32, i16, i8, f64, f32, &str, bool, String, DateTime<Utc>);
impl<T: Queryable> Queryable for Vec<T> {
fn query() -> String {
T::query()
}
}
impl<T: Queryable> Queryable for Option<T> {
fn query() -> String {
T::query()
}
}
impl<T: Queryable> Queryable for Box<T> {
fn query() -> String {
T::query()
}
}