diff --git a/src/backend/mysql/table.rs b/src/backend/mysql/table.rs index 7c5b42a91..881922f4c 100644 --- a/src/backend/mysql/table.rs +++ b/src/backend/mysql/table.rs @@ -105,6 +105,7 @@ impl TableBuilder for MysqlQueryBuilder { ColumnType::Cidr => unimplemented!("Cidr is not available in MySQL."), ColumnType::Inet => unimplemented!("Inet is not available in MySQL."), ColumnType::MacAddr => unimplemented!("MacAddr is not available in MySQL."), + ColumnType::LTree => unimplemented!("LTree is not available in MySQL."), } ) .unwrap(); diff --git a/src/backend/postgres/table.rs b/src/backend/postgres/table.rs index e0a8ed854..f9dd1b1de 100644 --- a/src/backend/postgres/table.rs +++ b/src/backend/postgres/table.rs @@ -77,6 +77,7 @@ impl TableBuilder for PostgresQueryBuilder { ColumnType::Inet => "inet".into(), ColumnType::MacAddr => "macaddr".into(), ColumnType::Year(_) => unimplemented!("Year is not available in Postgres."), + ColumnType::LTree => "ltree".into(), } ) .unwrap() diff --git a/src/backend/sqlite/table.rs b/src/backend/sqlite/table.rs index 94491861a..996630045 100644 --- a/src/backend/sqlite/table.rs +++ b/src/backend/sqlite/table.rs @@ -90,6 +90,7 @@ impl TableBuilder for SqliteQueryBuilder { ColumnType::Year(_) => unimplemented!("Year is not available in Sqlite."), ColumnType::Bit(_) => unimplemented!("Bit is not available in Sqlite."), ColumnType::VarBit(_) => unimplemented!("VarBit is not available in Sqlite."), + ColumnType::LTree => unimplemented!("LTree is not available in Sqlite."), } ) .unwrap() diff --git a/src/extension/postgres/ltree.rs b/src/extension/postgres/ltree.rs new file mode 100644 index 000000000..232976e5e --- /dev/null +++ b/src/extension/postgres/ltree.rs @@ -0,0 +1,18 @@ +use std::fmt; + +use crate::PgLTree; + +impl fmt::Display for PgLTree { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self.0) + } +} + +impl From for PgLTree +where + T: Into, +{ + fn from(field: T) -> Self { + PgLTree(field.into()) + } +} diff --git a/src/extension/postgres/mod.rs b/src/extension/postgres/mod.rs index abe5424a8..acd0c7daa 100644 --- a/src/extension/postgres/mod.rs +++ b/src/extension/postgres/mod.rs @@ -2,6 +2,7 @@ pub use expr::*; pub use extension::*; pub use func::*; pub use interval::*; +pub use ltree::*; pub use types::*; use crate::types::BinOper; @@ -10,6 +11,7 @@ pub(crate) mod expr; pub(crate) mod extension; pub(crate) mod func; pub(crate) mod interval; +pub(crate) mod ltree; pub(crate) mod types; /// Binary operator diff --git a/src/table/column.rs b/src/table/column.rs index 4e56121b9..baecd6559 100644 --- a/src/table/column.rs +++ b/src/table/column.rs @@ -52,6 +52,7 @@ pub enum ColumnType { Cidr, Inet, MacAddr, + LTree, } impl PartialEq for ColumnType { @@ -580,6 +581,13 @@ impl ColumnDef { self } + /// Set column type as `ltree` + /// This is only supported on Postgres. + pub fn ltree(&mut self) -> &mut Self { + self.types = Some(ColumnType::LTree); + self + } + /// Set constraints as SimpleExpr pub fn check(&mut self, value: T) -> &mut Self where diff --git a/tests/postgres/table.rs b/tests/postgres/table.rs index 6292000bc..cf7294e4f 100644 --- a/tests/postgres/table.rs +++ b/tests/postgres/table.rs @@ -597,3 +597,27 @@ fn alter_with_check_constraint() { r#"ALTER TABLE "glyph" ADD COLUMN "aspect" integer NOT NULL DEFAULT 101 CHECK ("aspect" > 100)"#, ); } + +#[test] +fn create_16() { + assert_eq!( + Table::create() + .table(Glyph::Table) + .col( + ColumnDef::new(Glyph::Id) + .integer() + .not_null() + .auto_increment() + .primary_key() + ) + .col(ColumnDef::new(Glyph::Tokens).ltree()) + .to_string(PostgresQueryBuilder), + [ + r#"CREATE TABLE "glyph" ("#, + r#""id" serial NOT NULL PRIMARY KEY,"#, + r#""tokens" ltree"#, + r#")"#, + ] + .join(" ") + ); +}