sea_query/extension/postgres/ltree.rs
1use crate::Iden;
2
3/// PostgreSQL `ltree` extension type.
4///
5/// `ltree` stores a raber path which in this struct is represented as the
6/// tuple's first value.
7///
8/// # PostcreSQL Reference
9///
10/// The following set of SQL statements can be used to create a table with
11/// a `ltree` column. Here the `ltree` column is called `path`.
12///
13/// The `path` column is then populated to generate the tree.
14///
15/// ```ignore
16/// CREATE TABLE test (path ltree);
17/// INSERT INTO test VALUES ('Top');
18/// INSERT INTO test VALUES ('Top.Science');
19/// INSERT INTO test VALUES ('Top.Science.Astronomy');
20/// INSERT INTO test VALUES ('Top.Science.Astronomy.Astrophysics');
21/// INSERT INTO test VALUES ('Top.Science.Astronomy.Cosmology');
22/// INSERT INTO test VALUES ('Top.Hobbies');
23/// INSERT INTO test VALUES ('Top.Hobbies.Amateurs_Astronomy');
24/// INSERT INTO test VALUES ('Top.Collections');
25/// INSERT INTO test VALUES ('Top.Collections.Pictures');
26/// INSERT INTO test VALUES ('Top.Collections.Pictures.Astronomy');
27/// INSERT INTO test VALUES ('Top.Collections.Pictures.Astronomy.Stars');
28/// INSERT INTO test VALUES ('Top.Collections.Pictures.Astronomy.Galaxies');
29/// INSERT INTO test VALUES ('Top.Collections.Pictures.Astronomy.Astronauts');
30/// CREATE INDEX path_gist_idx ON test USING GIST (path);
31/// CREATE INDEX path_idx ON test USING BTREE (path);
32/// ```
33///
34/// The set of queries above will generate the following tree:
35///
36/// ```ignore
37/// Top
38/// / | \
39/// Science Hobbies Collections
40/// / | \
41/// Astronomy Amateurs_Astronomy Pictures
42/// / \ |
43/// Astrophysics Cosmology Astronomy
44/// / | \
45/// Galaxies Stars Astronauts
46/// ```
47/// [Source][1]
48///
49/// [1]: https://www.postgresql.org/docs/current/ltree.html
50#[derive(Debug, Clone, Eq, PartialEq)]
51pub struct PgLTree;
52
53impl Iden for PgLTree {
54 fn unquoted(&self, s: &mut dyn std::fmt::Write) {
55 write!(s, "ltree").unwrap();
56 }
57}
58
59impl From<PgLTree> for String {
60 fn from(l: PgLTree) -> Self {
61 l.to_string()
62 }
63}