Skip to content

Commit 82a898b

Browse files
committed
feat(gb-9065): add more scalar types for postgres
1 parent 197875f commit 82a898b

File tree

7 files changed

+84362
-25158
lines changed

7 files changed

+84362
-25158
lines changed

crates/database-definition/src/type.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -255,21 +255,27 @@ impl ScalarType {
255255
use ScalarKind::*;
256256

257257
let type_name = match self.kind {
258-
Char | Text | Xml | Cidr | Macaddr8 | Macaddr | Varchar | Bit | Varbit => "String",
259-
Date | Inet | Time | Timetz => "String",
260-
Uuid | Oid => "String",
261-
Bigint | Bigserial => "BigInt",
262-
Timestamp => "String",
263-
Timestamptz => "String",
258+
Xml => "XML",
259+
Cidr => "CIDR",
260+
Macaddr | Macaddr8 => "MacAddr",
261+
Bit | Varbit => "BitString",
262+
Char | Text | Varchar => "String",
263+
Inet => "Inet",
264+
Date => "Date",
265+
Time => "Time",
266+
Timetz => "TimeWithTimezone",
267+
Timestamp => "Timestamp",
268+
Timestamptz => "DateTime",
269+
Uuid => "UUID",
270+
Oid | Bigint | Bigserial => "BigInt",
264271
Interval => "String",
265-
Decimal | Numeric | Money => "Decimal",
266-
272+
Money => "Money",
273+
Decimal | Numeric => "Decimal",
267274
Smallserial | Serial | Smallint | Int | Integer => "Int",
268275
Json | Jsonb => "JSON",
269276
Real | DoublePrecision => "Float",
270277
Boolean => "Boolean",
271278
Bytea => "Bytes",
272-
273279
_ => return None,
274280
};
275281

crates/postgres-introspection/src/render/input_types.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,26 @@ use crate::{
1212
use super::{EnabledOperations, ast::schema::Schema};
1313

1414
const SCALARS: &[&str] = &[
15-
"String", "BigInt", "Int", "Float", "Boolean", "Decimal", "Bytes", "JSON",
15+
"String",
16+
"BigInt",
17+
"Int",
18+
"Float",
19+
"Boolean",
20+
"Decimal",
21+
"Bytes",
22+
"JSON",
23+
"UUID",
24+
"Date",
25+
"Time",
26+
"TimeWithTimezone",
27+
"Timestamp",
28+
"DateTime",
29+
"Inet",
30+
"CIDR",
31+
"MacAddr",
32+
"Money",
33+
"BitString",
34+
"XML",
1635
];
1736

1837
const FILTERS: &[(&str, &str)] = &[
@@ -38,9 +57,21 @@ const ARRAYS: &[(&str, &str)] = &[
3857
("[Boolean]", "Boolean"),
3958
("[Bytes]", "Bytes"),
4059
("[JSON]", "JSON"),
60+
("[UUID]", "UUID"),
61+
("[Date]", "Date"),
62+
("[Time]", "Time"),
63+
("[TimeWithTimezone]", "TimeWithTimezone"),
64+
("[Timestamp]", "Timestamp"),
65+
("[DateTime]", "DateTime"),
66+
("[Inet]", "Inet"),
67+
("[CIDR]", "CIDR"),
68+
("[MacAddr]", "MacAddr"),
69+
("[Money]", "Money"),
70+
("[BitString]", "BitString"),
71+
("[XML]", "XML"),
4172
];
4273

43-
static NUMERIC_SCALARS: &[&str] = &["BigInt", "Float", "Decimal", "Int"];
74+
static NUMERIC_SCALARS: &[&str] = &["BigInt", "Float", "Decimal", "Int", "Money"];
4475

4576
pub fn render<'a>(
4677
database_definition: &'a DatabaseDefinition,

crates/postgres-introspection/src/render/scalars.rs

Lines changed: 91 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,112 @@ use super::ast::{scalar::Scalar, schema::Schema};
33
pub(super) fn render(rendered: &mut Schema) {
44
rendered.push_scalar({
55
let mut scalar = Scalar::new("JSON");
6-
scalar.set_description("JSON data type");
6+
scalar.set_description("Arbitrary JSON object");
77
scalar
88
});
99

1010
rendered.push_scalar({
1111
let mut scalar = Scalar::new("Bytes");
12-
scalar.set_description("Binary data type");
12+
scalar.set_description("Binary data type, represented as a string containing a hexadecimal value");
1313
scalar
1414
});
1515

1616
rendered.push_scalar({
1717
let mut scalar = Scalar::new("BigInt");
18-
scalar.set_description("Big integer data type");
18+
scalar.set_description("Big integer data type, represented as a string containing a numeric value");
1919
scalar
2020
});
2121

2222
rendered.push_scalar({
2323
let mut scalar = Scalar::new("Decimal");
24-
scalar.set_description("Decimal data type");
24+
scalar.set_description(
25+
"Decimal data type with arbitrary precision, represented as a string containing a numeric value",
26+
);
27+
scalar
28+
});
29+
30+
rendered.push_scalar({
31+
let mut scalar = Scalar::new("UUID");
32+
scalar.set_description(
33+
"UUID data type represented as a string in the format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
34+
);
35+
scalar
36+
});
37+
38+
rendered.push_scalar({
39+
let mut scalar = Scalar::new("Date");
40+
scalar.set_description("Date data type represented as a string in ISO 8601 format (YYYY-MM-DD)");
41+
scalar
42+
});
43+
44+
rendered.push_scalar({
45+
let mut scalar = Scalar::new("Time");
46+
scalar.set_description("Time data type represented as a string in ISO 8601 format (HH:MM:SS or HH:MM:SS.sss)");
47+
scalar
48+
});
49+
50+
rendered.push_scalar({
51+
let mut scalar = Scalar::new("TimeWithTimezone");
52+
scalar.set_description(
53+
"Time with time zone data type represented as a string in format (HH:MM:SS.sssZ or HH:MM:SS.sss+HH:MM)",
54+
);
55+
scalar
56+
});
57+
58+
rendered.push_scalar({
59+
let mut scalar = Scalar::new("Timestamp");
60+
scalar.set_description(
61+
"Timestamp data type represented as a string in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.sss)",
62+
);
63+
scalar
64+
});
65+
66+
rendered.push_scalar({
67+
let mut scalar = Scalar::new("DateTime");
68+
scalar
69+
.set_description("DateTime with time zone data type represented as a string in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.sssZ or YYYY-MM-DDTHH:MM:SS.sss+HH:MM)");
70+
scalar
71+
});
72+
73+
rendered.push_scalar({
74+
let mut scalar = Scalar::new("Inet");
75+
scalar.set_description(
76+
"IPv4 or IPv6 network address represented as a string (e.g., '192.168.0.1' or '2001:db8::1')",
77+
);
78+
scalar
79+
});
80+
81+
rendered.push_scalar({
82+
let mut scalar = Scalar::new("CIDR");
83+
scalar.set_description(
84+
"IPv4 or IPv6 network address space represented as a string (e.g., '192.168.0.1/24' or '2001:db8::1/64')",
85+
);
86+
scalar
87+
});
88+
89+
rendered.push_scalar({
90+
let mut scalar = Scalar::new("MacAddr");
91+
scalar.set_description("MAC address data type represented as a string in the format 'XX:XX:XX:XX:XX:XX'");
92+
scalar
93+
});
94+
95+
rendered.push_scalar({
96+
let mut scalar = Scalar::new("Money");
97+
scalar.set_description(
98+
"Currency amount data type represented as a string with a numeric value and optional currency symbol",
99+
);
100+
scalar
101+
});
102+
103+
rendered.push_scalar({
104+
let mut scalar = Scalar::new("BitString");
105+
scalar.set_description("Bit string data type represented as a string of 0s and 1s");
106+
scalar
107+
});
108+
109+
rendered.push_scalar({
110+
let mut scalar = Scalar::new("XML");
111+
scalar.set_description("XML data type represented as a string");
25112
scalar
26113
});
27114
}

extensions/postgres/tests/create_one/types.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,7 @@ async fn money() {
15461546

15471547
let mutation = indoc! {r#"
15481548
mutation {
1549-
userCreate(input: { val: "1.23" }) {
1549+
userCreate(input: { val: "$1.23" }) {
15501550
returning { val }
15511551
}
15521552
}
@@ -1589,7 +1589,7 @@ async fn money_array() {
15891589

15901590
let mutation = indoc! {r#"
15911591
mutation {
1592-
userCreate(input: { val: ["1.23", "3.14"] }) {
1592+
userCreate(input: { val: ["$1.23", "$3.14"] }) {
15931593
returning { val }
15941594
}
15951595
}
@@ -1902,7 +1902,7 @@ async fn time() {
19021902

19031903
let mutation = indoc! {r#"
19041904
mutation {
1905-
userCreate(input: { val: "16:20:00" }) {
1905+
userCreate(input: { val: "16:20:00.666" }) {
19061906
returning { val }
19071907
}
19081908
}
@@ -1919,7 +1919,7 @@ async fn time() {
19191919
"data": {
19201920
"userCreate": {
19211921
"returning": {
1922-
"val": "16:20:00"
1922+
"val": "16:20:00.666"
19231923
}
19241924
}
19251925
}
@@ -1991,7 +1991,7 @@ async fn timetz() {
19911991

19921992
let mutation = indoc! {r#"
19931993
mutation {
1994-
userCreate(input: { val: "16:20:00+00" }) {
1994+
userCreate(input: { val: "16:20:00Z" }) {
19951995
returning { val }
19961996
}
19971997
}
@@ -2004,15 +2004,15 @@ async fn timetz() {
20042004
.unwrap();
20052005

20062006
insta::assert_json_snapshot!(response, @r#"
2007-
{
2008-
"data": {
2009-
"userCreate": {
2010-
"returning": {
2011-
"val": "16:20:00+00"
2012-
}
2013-
}
2007+
{
2008+
"data": {
2009+
"userCreate": {
2010+
"returning": {
2011+
"val": "16:20:00+00"
20142012
}
20152013
}
2014+
}
2015+
}
20162016
"#);
20172017
}
20182018

0 commit comments

Comments
 (0)