Skip to content

Commit a8133ff

Browse files
committed
Add serde feature for Ltree value.
1 parent ed717d7 commit a8133ff

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

Cargo.toml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "diesel_ltree"
3-
version = "0.3.1"
3+
version = "0.4.0"
44
# Currently maintained by Conner Bradley, originally written by Ashe Connor
55
authors = ["Conner Bradley <[email protected]>", "Ashe Connor <[email protected]>"]
66
description = "Adds support for the PostgreSQL ltree extension to Diesel"
@@ -12,11 +12,15 @@ repository = "https://github.com/kivikakk/diesel_ltree"
1212

1313
[dependencies]
1414
byteorder = "1.0"
15-
diesel = { version = "2.0", default-features = false, features = [
15+
diesel = { version = "2.2", default-features = false, features = [
1616
"postgres_backend",
1717
] }
18+
serde = { version = "1.0", optional = true }
1819

1920
[dev-dependencies]
2021
dotenv = "0.15"
21-
diesel = { version = "2.0", default-features = false, features = ["postgres"] }
22+
diesel = { version = "2.2", default-features = false, features = ["postgres"] }
2223
diesel_migrations = "2.0"
24+
25+
[features]
26+
serde = ["dep:serde"]

src/lib.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ pub mod values {
3737

3838
/// A ltree [label path](https://www.postgresql.org/docs/current/ltree.html#LTREE-DEFINITIONS).
3939
#[derive(Debug, PartialEq, Eq, Clone, FromSqlRow, AsExpression)]
40+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
41+
#[cfg_attr(feature = "serde", serde(transparent))]
4042
#[diesel(sql_type = crate::sql_types::Ltree)]
4143
pub struct Ltree(pub String);
4244

@@ -96,18 +98,18 @@ pub mod functions {
9698
use crate::sql_types::*;
9799
use diesel::sql_types::*;
98100

99-
sql_function!(fn subltree(ltree: Ltree, start: Int4, end: Int4) -> Ltree);
100-
sql_function!(fn subpath(ltree: Ltree, offset: Int4, len: Int4) -> Ltree);
101-
// sql_function!(fn subpath(ltree: Ltree, offset: Int4) -> Ltree);
102-
sql_function!(fn nlevel(ltree: Ltree) -> Int4);
103-
//sql_function!(fn index(a: Ltree, b: Ltree) -> Int4);
104-
sql_function!(fn index(a: Ltree, b: Ltree, offset: Int4) -> Int4);
105-
sql_function!(fn text2ltree(text: Text) -> Ltree);
106-
sql_function!(fn ltree2text(ltree: Ltree) -> Text);
107-
sql_function!(fn lca(ltrees: Array<Ltree>) -> Ltree);
108-
109-
sql_function!(fn lquery(x: Text) -> Lquery);
110-
sql_function!(fn ltxtquery(x: Text) -> Ltxtquery);
101+
define_sql_function!(fn subltree(ltree: Ltree, start: Int4, end: Int4) -> Ltree);
102+
define_sql_function!(fn subpath(ltree: Ltree, offset: Int4, len: Int4) -> Ltree);
103+
// define_sql_function!(fn subpath(ltree: Ltree, offset: Int4) -> Ltree);
104+
define_sql_function!(fn nlevel(ltree: Ltree) -> Int4);
105+
//define_sql_function!(fn index(a: Ltree, b: Ltree) -> Int4);
106+
define_sql_function!(fn index(a: Ltree, b: Ltree, offset: Int4) -> Int4);
107+
define_sql_function!(fn text2ltree(text: Text) -> Ltree);
108+
define_sql_function!(fn ltree2text(ltree: Ltree) -> Text);
109+
define_sql_function!(fn lca(ltrees: Array<Ltree>) -> Ltree);
110+
111+
define_sql_function!(fn lquery(x: Text) -> Lquery);
112+
define_sql_function!(fn ltxtquery(x: Text) -> Ltxtquery);
111113
}
112114

113115
pub mod dsl {

0 commit comments

Comments
 (0)