Skip to content

Commit 8632879

Browse files
committed
Made databases disableable
1 parent 301e4b2 commit 8632879

File tree

7 files changed

+287
-100
lines changed

7 files changed

+287
-100
lines changed

src/choice.rs

Lines changed: 47 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,59 @@ pub struct Choice(pub String);
77
const _: () = {
88
use sqlx::database::{Database, HasValueRef};
99
use sqlx::error::BoxDynError;
10-
use sqlx::{Decode, MySql, Postgres, Sqlite, Type};
11-
impl Type<Postgres> for Choice {
12-
fn type_info() -> <Postgres as Database>::TypeInfo {
13-
<str as Type<Postgres>>::type_info()
14-
}
15-
fn compatible(ty: &<Postgres as Database>::TypeInfo) -> bool {
16-
<str as Type<Postgres>>::compatible(ty)
10+
use sqlx::{Decode, Type};
11+
12+
#[cfg(feature = "postgres")]
13+
const _: () = {
14+
use sqlx::Postgres;
15+
impl Type<Postgres> for Choice {
16+
fn type_info() -> <Postgres as Database>::TypeInfo {
17+
<str as Type<Postgres>>::type_info()
18+
}
19+
fn compatible(ty: &<Postgres as Database>::TypeInfo) -> bool {
20+
<str as Type<Postgres>>::compatible(ty)
21+
}
1722
}
18-
}
19-
impl<'r> Decode<'r, Postgres> for Choice {
20-
fn decode(value: <Postgres as HasValueRef<'r>>::ValueRef) -> Result<Self, BoxDynError> {
21-
<String as Decode<'r, Postgres>>::decode(value).map(Self)
23+
impl<'r> Decode<'r, Postgres> for Choice {
24+
fn decode(value: <Postgres as HasValueRef<'r>>::ValueRef) -> Result<Self, BoxDynError> {
25+
<String as Decode<'r, Postgres>>::decode(value).map(Self)
26+
}
2227
}
23-
}
28+
};
2429

25-
impl Type<MySql> for Choice {
26-
fn type_info() -> <MySql as Database>::TypeInfo {
27-
<str as Type<MySql>>::type_info()
30+
#[cfg(feature = "mysql")]
31+
const _: () = {
32+
use sqlx::MySql;
33+
impl Type<MySql> for Choice {
34+
fn type_info() -> <MySql as Database>::TypeInfo {
35+
<str as Type<MySql>>::type_info()
36+
}
37+
fn compatible(ty: &<MySql as Database>::TypeInfo) -> bool {
38+
<str as Type<MySql>>::compatible(ty)
39+
}
2840
}
29-
fn compatible(ty: &<MySql as Database>::TypeInfo) -> bool {
30-
<str as Type<MySql>>::compatible(ty)
41+
impl<'r> Decode<'r, MySql> for Choice {
42+
fn decode(value: <MySql as HasValueRef<'r>>::ValueRef) -> Result<Self, BoxDynError> {
43+
<String as Decode<'r, MySql>>::decode(value).map(Self)
44+
}
3145
}
32-
}
33-
impl<'r> Decode<'r, MySql> for Choice {
34-
fn decode(value: <MySql as HasValueRef<'r>>::ValueRef) -> Result<Self, BoxDynError> {
35-
<String as Decode<'r, MySql>>::decode(value).map(Self)
36-
}
37-
}
46+
};
3847

39-
impl Type<Sqlite> for Choice {
40-
fn type_info() -> <Sqlite as Database>::TypeInfo {
41-
<str as Type<Sqlite>>::type_info()
42-
}
43-
fn compatible(ty: &<Sqlite as Database>::TypeInfo) -> bool {
44-
<str as Type<Sqlite>>::compatible(ty)
48+
#[cfg(feature = "sqlite")]
49+
const _: () = {
50+
use sqlx::Sqlite;
51+
impl Type<Sqlite> for Choice {
52+
fn type_info() -> <Sqlite as Database>::TypeInfo {
53+
<str as Type<Sqlite>>::type_info()
54+
}
55+
fn compatible(ty: &<Sqlite as Database>::TypeInfo) -> bool {
56+
<str as Type<Sqlite>>::compatible(ty)
57+
}
4558
}
46-
}
47-
impl<'r> Decode<'r, Sqlite> for Choice {
48-
fn decode(value: <Sqlite as HasValueRef<'r>>::ValueRef) -> Result<Self, BoxDynError> {
49-
<String as Decode<'r, Sqlite>>::decode(value).map(Self)
59+
impl<'r> Decode<'r, Sqlite> for Choice {
60+
fn decode(value: <Sqlite as HasValueRef<'r>>::ValueRef) -> Result<Self, BoxDynError> {
61+
<String as Decode<'r, Sqlite>>::decode(value).map(Self)
62+
}
5063
}
51-
}
64+
};
5265
};

0 commit comments

Comments
 (0)