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