Skip to main content

drizzle_types/postgres/
mod.rs

1//! `PostgreSQL` types.
2//!
3//! - [`types`]: zero-sized SQL type markers used for compile-time checks.
4//! - [`PostgreSQLType`]: column types as written in DDL, with their metadata.
5//! - [`TypeCategory`]: how a Rust field type maps to a `PostgreSQL` column.
6//! - [`PgTypeCategory`]: categories of SQL type names, used when parsing.
7//! - [`ddl`]: schema objects (tables, columns, indexes, ...) for migrations.
8
9pub mod ddl;
10mod sql_type;
11mod type_category;
12
13/// Zero-sized SQL type markers for the `PostgreSQL` dialect.
14///
15/// Each marker stands for one SQL type at compile time; it carries no length,
16/// precision or enum values (see [`PostgreSQLType`] for those). The traits in
17/// [`crate::sql`] say which markers can be compared, assigned, or used in
18/// arithmetic. The Rust types listed are the default value mappings.
19pub mod types {
20    /// `smallint` (`int2`): 16-bit integer. Rust `i16`.
21    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
22    pub struct Int2;
23
24    /// `integer` (`int4`): 32-bit integer. Rust `i32`.
25    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
26    pub struct Int4;
27
28    /// `bigint` (`int8`): 64-bit integer. Rust `i64`.
29    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
30    pub struct Int8;
31
32    /// `real` (`float4`): 32-bit float. Rust `f32`.
33    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
34    pub struct Float4;
35
36    /// `double precision` (`float8`): 64-bit float. Rust `f64`.
37    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
38    pub struct Float8;
39
40    /// `varchar(n)`: text with a length limit.
41    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
42    pub struct Varchar;
43
44    /// `text`: unlimited text. Rust `&str`, `String`.
45    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
46    pub struct Text;
47
48    /// `char(n)`: fixed-length, blank-padded text.
49    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
50    pub struct Char;
51
52    /// `bytea`: raw bytes. Rust `&[u8]`, `Vec<u8>`.
53    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
54    pub struct Bytea;
55
56    /// `boolean`. Rust `bool`.
57    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
58    pub struct Boolean;
59
60    /// `timestamp with time zone`.
61    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
62    pub struct Timestamptz;
63
64    /// `timestamp` (without time zone).
65    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
66    pub struct Timestamp;
67
68    /// `date`.
69    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
70    pub struct Date;
71
72    /// `time` (without time zone).
73    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
74    pub struct Time;
75
76    /// `time with time zone`.
77    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
78    pub struct Timetz;
79
80    /// `numeric(p, s)`: exact decimal.
81    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
82    pub struct Numeric;
83
84    /// `uuid`.
85    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
86    pub struct Uuid;
87
88    /// `json`: JSON stored as text.
89    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
90    pub struct Json;
91
92    /// `jsonb`: binary JSON; supports containment and key operators.
93    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
94    pub struct Jsonb;
95
96    /// Untyped SQL, such as a raw `SQL` fragment. Compatible with every `PostgreSQL` marker.
97    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
98    pub struct Any;
99
100    /// `interval`: a time span.
101    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
102    pub struct Interval;
103
104    /// `inet`: an IPv4 or IPv6 host address, with optional netmask.
105    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
106    pub struct Inet;
107
108    /// `cidr`: an IPv4 or IPv6 network.
109    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
110    pub struct Cidr;
111
112    /// `macaddr`: a 6-byte MAC address.
113    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
114    pub struct MacAddr;
115
116    /// `macaddr8`: an 8-byte MAC address.
117    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
118    pub struct MacAddr8;
119
120    /// `point`: a geometric point.
121    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
122    pub struct Point;
123
124    /// `path`: an open or closed geometric path.
125    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
126    pub struct LineString;
127
128    /// `box`: a rectangle.
129    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
130    pub struct Rect;
131
132    /// `bit(n)` / `bit varying(n)`: a bit string.
133    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
134    pub struct BitString;
135
136    /// `line`: an infinite geometric line.
137    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
138    pub struct Line;
139
140    /// `lseg`: a line segment.
141    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
142    pub struct LineSegment;
143
144    /// `polygon`.
145    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
146    pub struct Polygon;
147
148    /// `circle`.
149    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
150    pub struct Circle;
151
152    /// A user-defined enum type (`CREATE TYPE ... AS ENUM`).
153    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
154    pub struct Enum;
155}
156
157pub use sql_type::PostgreSQLType;
158pub use type_category::{PgTypeCategory, TypeCategory};