Skip to content

Commit d0b7670

Browse files
feat: add postgres multirange column types (#10627)
* feat: add postgres multirange column types Adds int4-, int8-, num-, ts-, tstz-, date-multirange column types for postgres Update docs to include multirange column types Update functional column-types-postgres test to test multirange column types Closes: #10556 * style: run npm run format --------- Co-authored-by: Dmitry Zotov <[email protected]>
1 parent 54d8d9e commit d0b7670

File tree

6 files changed

+118
-33
lines changed

6 files changed

+118
-33
lines changed

docs/entities.md

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
# Entities
22

3-
- [What is Entity?](#what-is-entity)
4-
- [Entity columns](#entity-columns)
5-
- [Primary columns](#primary-columns)
6-
- [Special columns](#special-columns)
7-
- [Spatial columns](#spatial-columns)
8-
- [Column types](#column-types)
9-
- [Column types for `mysql` / `mariadb`](#column-types-for-mysql--mariadb)
10-
- [Column types for `postgres` / `cockroachdb`](#column-types-for-postgres)
11-
- [Column types for `sqlite` / `cordova` / `react-native` / `expo`](#column-types-for-sqlite--cordova--react-native--expo)
12-
- [Column types for `mssql`](#column-types-for-mssql)
13-
- [`enum` column type](#enum-column-type)
14-
- [`simple-array` column type](#simple-array-column-type)
15-
- [`simple-json` column type](#simple-json-column-type)
16-
- [Columns with generated values](#columns-with-generated-values)
17-
- [Column options](#column-options)
3+
- [Entities](#entities)
4+
- [What is Entity?](#what-is-entity)
5+
- [Entity columns](#entity-columns)
6+
- [Primary columns](#primary-columns)
7+
- [Special columns](#special-columns)
8+
- [Spatial columns](#spatial-columns)
9+
- [Column types](#column-types)
10+
- [Column types for `mysql` / `mariadb`](#column-types-for-mysql--mariadb)
11+
- [Column types for `postgres`](#column-types-for-postgres)
12+
- [Column types for `cockroachdb`](#column-types-for-cockroachdb)
13+
- [Column types for `sqlite` / `cordova` / `react-native` / `expo`](#column-types-for-sqlite--cordova--react-native--expo)
14+
- [Column types for `mssql`](#column-types-for-mssql)
15+
- [Column types for `oracle`](#column-types-for-oracle)
16+
- [Column types for `spanner`](#column-types-for-spanner)
17+
- [`enum` column type](#enum-column-type)
18+
- [`set` column type](#set-column-type)
19+
- [`simple-array` column type](#simple-array-column-type)
20+
- [`simple-json` column type](#simple-json-column-type)
21+
- [Columns with generated values](#columns-with-generated-values)
22+
- [Column options](#column-options)
23+
- [Entity inheritance](#entity-inheritance)
24+
- [Tree entities](#tree-entities)
25+
- [Adjacency list](#adjacency-list)
26+
- [Closure table](#closure-table)
1827

1928
## What is Entity?
2029

@@ -381,7 +390,8 @@ or
381390
`date`, `time`, `time without time zone`, `time with time zone`, `interval`, `bool`, `boolean`,
382391
`enum`, `point`, `line`, `lseg`, `box`, `path`, `polygon`, `circle`, `cidr`, `inet`, `macaddr`,
383392
`tsvector`, `tsquery`, `uuid`, `xml`, `json`, `jsonb`, `int4range`, `int8range`, `numrange`,
384-
`tsrange`, `tstzrange`, `daterange`, `geometry`, `geography`, `cube`, `ltree`
393+
`tsrange`, `tstzrange`, `daterange`, `int4multirange`, `int8multirange`, `nummultirange`,
394+
`tsmultirange`, `tstzmultirange`, `multidaterange`, `geometry`, `geography`, `cube`, `ltree`
385395

386396
### Column types for `cockroachdb`
387397

docs/zh_CN/entities.md

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
# 实体
22

3-
* [实体是什么?](#实体是什么)
4-
* [实体列](#实体列)
5-
* [主列](#主列)
6-
* [特殊列](#特殊列)
7-
* [空间列](#空间列)
8-
* [列类型](#列类型)
9-
* [`mysql`/`mariadb`的列类型](#`mysql`/`mariadb`的列类型)
10-
* [`postgres`的列类型](#`postgres`的列类型)
11-
* [`sqlite`/`cordova`/`react-native`/`expo`的列类型](#sqlite`/`cordova`/`react-native`/`expo`的列类型)
12-
* [`mssql`的列类型](#`mssql`的列类型)
13-
* [`oracle`的列类型](#`oracle`的列类型)
14-
* [`enum`列类型](#`enum`列类型)
15-
* [`simple-array`的列类型](#`simple-array`的列类型)
16-
* [`simple-json`列类型](#`simple-json`列类型)
17-
* [具有生成值的列](#具有生成值的列)
18-
* [列选项](#列选项)
3+
- [实体](#实体)
4+
- [实体是什么?](#实体是什么)
5+
- [实体列](#实体列)
6+
- [主列](#主列)
7+
- [特殊列](#特殊列)
8+
- [空间列](#空间列)
9+
- [列类型](#列类型)
10+
- [`mysql`/`mariadb`的列类型](#mysqlmariadb的列类型)
11+
- [`postgres`的列类型](#postgres的列类型)
12+
- [`sqlite`/`cordova`/`react-native`/`expo`的列类型](#sqlitecordovareact-nativeexpo的列类型)
13+
- [`mssql`的列类型](#mssql的列类型)
14+
- [`oracle`的列类型](#oracle的列类型)
15+
- [`enum` 列类型](#enum-列类型)
16+
- [`simple-array`的列类型](#simple-array的列类型)
17+
- [`simple-json` 列类型](#simple-json-列类型)
18+
- [具有生成值的列](#具有生成值的列)
19+
- [列选项](#列选项)
20+
- [实体继承](#实体继承)
21+
- [树实体](#树实体)
22+
- [邻接列表](#邻接列表)
23+
- [Closure 表](#closure-表)
1924

2025
## 实体是什么?
2126

@@ -271,7 +276,8 @@ TypeORM 支持所有最常用的数据库支持的列类型。
271276
`date`, `time`, `time without time zone`, `time with time zone`, `interval`, `bool`, `boolean`,
272277
`enum`, `point`, `line`, `lseg`, `box`, `path`, `polygon`, `circle`, `cidr`, `inet`, `macaddr`,
273278
`tsvector`, `tsquery`, `uuid`, `xml`, `json`, `jsonb`, `int4range`, `int8range`, `numrange`,
274-
`tsrange`, `tstzrange`, `daterange`, `geometry`, `geography`
279+
`tsrange`, `tstzrange`, `daterange`, `int4multirange`, `int8multirange`, `nummultirange`,
280+
`tsmultirange`, `tstzmultirange`, `multidaterange`, `geometry`, `geography`
275281

276282
### `sqlite`/`cordova`/`react-native`/`expo`的列类型
277283

src/driver/postgres/PostgresDriver.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ export class PostgresDriver implements Driver {
180180
"tsrange",
181181
"tstzrange",
182182
"daterange",
183+
"int4multirange",
184+
"int8multirange",
185+
"nummultirange",
186+
"tsmultirange",
187+
"tstzmultirange",
188+
"datemultirange",
183189
"geometry",
184190
"geography",
185191
"cube",

src/driver/types/ColumnTypes.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ export type SimpleColumnType =
172172
| "tstzrange" // postgres
173173
| "daterange" // postgres
174174

175+
// multirange types
176+
| "int4multirange" // postgres
177+
| "int8multirange" // postgres
178+
| "nummultirange" // postgres
179+
| "tsmultirange" // postgres
180+
| "tstzmultirange" // postgres
181+
| "datemultirange" // postgres
182+
175183
// other types
176184
| "enum" // mysql, postgres
177185
| "set" // mysql

test/functional/database-schema/column-types/postgres/column-types-postgres.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ describe("database schema > column types > postgres", () => {
9898
post.tstzrange =
9999
"[2010-01-01 14:30:00+00,2010-01-01 15:30:00+00)"
100100
post.daterange = "[2010-01-01,2010-01-05)"
101+
post.int4multirange = "{[10,20),[25,30)}"
102+
post.int8multirange = "{[200000,500000),[600000,700000)}"
103+
post.nummultirange = "{(10.5,20.2),(30.5,40.2)}"
104+
post.tsmultirange =
105+
'{["2010-01-01 14:30:00","2010-01-01 15:30:00"),["2010-01-01 16:30:00","2010-01-01 17:30:00")}'
106+
post.tstzmultirange =
107+
'{["2010-01-01 14:30:00+00","2010-01-01 15:30:00+00"),["2010-01-01 16:30:00+00","2010-01-01 17:30:00+00")}'
108+
post.datemultirange =
109+
"{[2010-01-01,2010-01-05),[2010-01-10,2010-01-15)}"
101110
post.xml =
102111
"<book><title>Manual</title><chapter>...</chapter></book>"
103112
post.array = [1, 2, 3]
@@ -185,6 +194,12 @@ describe("database schema > column types > postgres", () => {
185194
`["2010-01-01 14:30:00+00","2010-01-01 15:30:00+00")`,
186195
)
187196
loadedPost.daterange.should.be.eql(post.daterange)
197+
loadedPost.int4multirange.should.be.eql(post.int4multirange)
198+
loadedPost.int8multirange.should.be.eql(post.int8multirange)
199+
loadedPost.nummultirange.should.be.eql(post.nummultirange)
200+
loadedPost.tsmultirange.should.be.eql(post.tsmultirange)
201+
loadedPost.tstzmultirange.should.be.eql(post.tstzmultirange)
202+
loadedPost.datemultirange.should.be.eql(post.datemultirange)
188203
loadedPost.xml.should.be.equal(post.xml)
189204
loadedPost.array[0].should.be.equal(post.array[0])
190205
loadedPost.array[1].should.be.equal(post.array[1])
@@ -322,6 +337,24 @@ describe("database schema > column types > postgres", () => {
322337
table!
323338
.findColumnByName("daterange")!
324339
.type.should.be.equal("daterange")
340+
table!
341+
.findColumnByName("int4multirange")!
342+
.type.should.be.equal("int4multirange")
343+
table!
344+
.findColumnByName("int8multirange")!
345+
.type.should.be.equal("int8multirange")
346+
table!
347+
.findColumnByName("nummultirange")!
348+
.type.should.be.equal("nummultirange")
349+
table!
350+
.findColumnByName("tsmultirange")!
351+
.type.should.be.equal("tsmultirange")
352+
table!
353+
.findColumnByName("tstzmultirange")!
354+
.type.should.be.equal("tstzmultirange")
355+
table!
356+
.findColumnByName("datemultirange")!
357+
.type.should.be.equal("datemultirange")
325358
table!
326359
.findColumnByName("array")!
327360
.type.should.be.equal("integer")

test/functional/database-schema/column-types/postgres/entity/Post.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,28 @@ export class Post {
234234
@Column("daterange")
235235
daterange: string
236236

237+
// -------------------------------------------------------------------------
238+
// Multirange Type
239+
// -------------------------------------------------------------------------
240+
241+
@Column("int4multirange")
242+
int4multirange: string
243+
244+
@Column("int8multirange")
245+
int8multirange: string
246+
247+
@Column("nummultirange")
248+
nummultirange: string
249+
250+
@Column("tsmultirange")
251+
tsmultirange: string
252+
253+
@Column("tstzmultirange")
254+
tstzmultirange: string
255+
256+
@Column("datemultirange")
257+
datemultirange: string
258+
237259
// -------------------------------------------------------------------------
238260
// Array Type
239261
// -------------------------------------------------------------------------

0 commit comments

Comments
 (0)