Skip to content

Commit

Permalink
feat(postgres): better handling of time types
Browse files Browse the repository at this point in the history
  • Loading branch information
calebmer committed Oct 9, 2016
1 parent 248e823 commit ee57864
Show file tree
Hide file tree
Showing 19 changed files with 522 additions and 454 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"pg": "^6.1.0",
"pg-connection-string": "^0.1.3",
"pg-minify": "^0.3.3",
"pluralize": "^3.0.0"
"pluralize": "^3.0.0",
"postgres-interval": "^1.0.2"
},
"devDependencies": {
"@types/change-case": "0.0.29",
Expand Down
4 changes: 2 additions & 2 deletions resources/introspection-query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ with
typ.typtype as "type",
typ.typcategory as "category",
typ.typnotnull as "domainIsNotNull",
nullif(typ.typelem, 0) as "arrayItemId",
nullif(typ.typelem, 0) as "arrayItemTypeId",
nullif(typ.typrelid, 0) as "classId",
nullif(typ.typbasetype, 0) as "domainBaseTypeId",
-- If this type is an enum type, let鈥檚 select all of its enum variants.
Expand Down Expand Up @@ -194,7 +194,7 @@ with
-- We also do this for range sub types and array item types.
typ.id in (select "domainBaseTypeId" from type_all) or
typ.id in (select "rangeSubTypeId" from type_all) or
typ.id in (select "arrayItemId" from type_all)
typ.id in (select "arrayItemTypeId" from type_all)
order by
"namespaceId", "name"
),
Expand Down
8 changes: 7 additions & 1 deletion resources/kitchen-sink-data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,14 @@ insert into b.types values (
'{"a":1,"b":2,"c":3,"d":{"e":4,"f":5,"g":[6,7,8,"x",false,null]}}',
'{"1":"a","2":"b","3":"c","4":{"5":"d","6":"e","7":["f","g","h",42,true,null]}}',
numrange(-10, 52),
-- daterange('1998-07-12', '2016-10-07'),
daterange('1998-07-12', '2016-10-07'),
'[20, 53]',
'1999-01-08 04:05:06',
'1999-01-08 04:05:06 -8:00',
'2016-10-07',
'04:05:06',
'04:05:06 -8:00',
'1 year 2 months 3 days 4 hours 5 minutes 6 seconds',
(1, '2', 'blue', '4be8a712-3ff7-432e-aa34-fdb43fbd838d', 8),
((3, '456', 'red', 'aed18400-2a92-46df-8204-b70c728b3520', 93), (42, 'Hello, world!', 'blue', 'd34df5e0-83f1-11e6-8dd0-abee917ffd1e', -5), 7)
);
12 changes: 9 additions & 3 deletions resources/kitchen-sink-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,15 @@ create table b.types (
"text_array" text[] not null,
"json" json not null,
"jsonb" jsonb not null,
"numrange" numrange,
-- TODO: "daterange" daterange,
"an_int_range" a.an_int_range,
"numrange" numrange not null,
"daterange" daterange not null,
"an_int_range" a.an_int_range not null,
"timestamp" timestamp not null,
"timestamptz" timestamptz not null,
"date" date not null,
"time" time not null,
"timetz" timetz not null,
"interval" interval not null,
"compound_type" c.compound_type not null,
"nested_compound_type" b.nested_compound_type not null
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,29 @@ Object {
"d": "ec4a9fae-4ec5-4763-98eb-0327fb2dc9bf",
"fooBar": 20,
},
"date": "2016-10-15",
"daterange": Object {
"end": Object {
"inclusive": false,
"value": "1927-11-07",
},
"start": Object {
"inclusive": true,
"value": "1927-11-06",
},
},
"domain": 6,
"domain2": 5,
"enum": "RED",
"id": 201,
"interval": Object {
"days": 4,
"hours": 3,
"minutes": 2,
"months": 5,
"seconds": 1,
"years": 6,
},
"json": "{\"x\":1,\"y\":2,\"z\":3}",
"jsonb": "{\"a\":1,\"b\":2,\"c\":3}",
"nestedCompoundType": Object {
Expand Down Expand Up @@ -568,6 +587,10 @@ Object {
"spout",
"?",
],
"time": "19:13:18.625699",
"timestamp": "2016-10-07T16:12:21.747269",
"timestamptz": "2016-10-09T16:12:45.218676-04:00",
"timetz": "13:13:29.585176-04",
"varchar": "abc",
},
},
Expand Down
Loading

0 comments on commit ee57864

Please sign in to comment.