Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit 5d2ba05f
authored
Aug 29, 2017
by
Timshel Knoll-Miller
Committed by
Sushant
Aug 29, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(datatypes/range): don't stringify infinite and null bounds (fixes: #8192) (#8210)
1 parent
9866921f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
98 additions
and
1 deletions
lib/dialects/postgres/data-types.js
test/integration/dialects/postgres/range.test.js
test/unit/sql/where.test.js
lib/dialects/postgres/data-types.js
View file @
5d2ba05
...
...
@@ -422,7 +422,10 @@ module.exports = BaseTypes => {
this
.
toCastType
();
}
const
valuesStringified
=
values
.
map
(
value
=>
{
if
(
this
.
options
.
subtype
.
stringify
)
{
if
(
_
.
includes
([
null
,
-
Infinity
,
Infinity
],
value
))
{
// Pass through "unbounded" bounds unchanged
return
value
;
}
else
if
(
this
.
options
.
subtype
.
stringify
)
{
return
this
.
options
.
subtype
.
stringify
(
value
,
options
);
}
else
{
return
options
.
escape
(
value
);
...
...
test/integration/dialects/postgres/range.test.js
View file @
5d2ba05
...
...
@@ -103,6 +103,78 @@ if (dialect.match(/^postgres/)) {
expect
(
Range
.
stringify
(
new
Date
(
Date
.
UTC
(
2000
,
1
,
1
)),
{
timezone
:
'+02:00'
})).
to
.
equal
(
'\'2000-02-01 02:00:00.000 +02:00\'::timestamptz'
);
});
describe
(
'with null range bounds'
,
()
=>
{
const
infiniteRange
=
[
null
,
null
];
const
infiniteRangeSQL
=
"'[,)'"
;
it
(
'should stringify integer range to infinite range'
,
()
=>
{
const
Range
=
new
DataTypes
.
postgres
.
RANGE
(
DataTypes
.
INTEGER
);
expect
(
Range
.
stringify
(
infiniteRange
)).
to
.
equal
(
infiniteRangeSQL
);
});
it
(
'should stringify bigint range to infinite range'
,
()
=>
{
const
Range
=
new
DataTypes
.
postgres
.
RANGE
(
DataTypes
.
BIGINT
);
expect
(
Range
.
stringify
(
infiniteRange
)).
to
.
equal
(
infiniteRangeSQL
);
});
it
(
'should stringify numeric range to infinite range'
,
()
=>
{
const
Range
=
new
DataTypes
.
postgres
.
RANGE
(
DataTypes
.
DECIMAL
);
expect
(
Range
.
stringify
(
infiniteRange
)).
to
.
equal
(
infiniteRangeSQL
);
});
it
(
'should stringify dateonly ranges appropriately'
,
()
=>
{
const
Range
=
new
DataTypes
.
postgres
.
RANGE
(
DataTypes
.
DATEONLY
);
expect
(
Range
.
stringify
(
infiniteRange
)).
to
.
equal
(
infiniteRangeSQL
);
});
it
(
'should be stringified to appropriate unbounded postgres range'
,
()
=>
{
const
Range
=
new
DataTypes
.
postgres
.
RANGE
(
DataTypes
.
DATEONLY
);
expect
(
Range
.
stringify
(
infiniteRange
)).
to
.
equal
(
infiniteRangeSQL
);
});
it
(
'should stringify date values with appropriate casting'
,
()
=>
{
const
Range
=
new
DataTypes
.
postgres
.
RANGE
(
DataTypes
.
DATE
);
expect
(
Range
.
stringify
(
infiniteRange
,
{
timezone
:
'+02:00'
})).
to
.
equal
(
infiniteRangeSQL
);
});
});
describe
(
'with infinite range bounds'
,
()
=>
{
const
infiniteRange
=
[
-
Infinity
,
Infinity
];
const
infiniteRangeSQL
=
"'[-infinity,infinity)'"
;
it
(
'should stringify integer range to infinite range'
,
()
=>
{
const
Range
=
new
DataTypes
.
postgres
.
RANGE
(
DataTypes
.
INTEGER
);
expect
(
Range
.
stringify
(
infiniteRange
)).
to
.
equal
(
infiniteRangeSQL
);
});
it
(
'should stringify bigint range to infinite range'
,
()
=>
{
const
Range
=
new
DataTypes
.
postgres
.
RANGE
(
DataTypes
.
BIGINT
);
expect
(
Range
.
stringify
(
infiniteRange
)).
to
.
equal
(
infiniteRangeSQL
);
});
it
(
'should stringify numeric range to infinite range'
,
()
=>
{
const
Range
=
new
DataTypes
.
postgres
.
RANGE
(
DataTypes
.
DECIMAL
);
expect
(
Range
.
stringify
(
infiniteRange
)).
to
.
equal
(
infiniteRangeSQL
);
});
it
(
'should stringify dateonly ranges appropriately'
,
()
=>
{
const
Range
=
new
DataTypes
.
postgres
.
RANGE
(
DataTypes
.
DATEONLY
);
expect
(
Range
.
stringify
(
infiniteRange
)).
to
.
equal
(
infiniteRangeSQL
);
});
it
(
'should be stringified to appropriate unbounded postgres range'
,
()
=>
{
const
Range
=
new
DataTypes
.
postgres
.
RANGE
(
DataTypes
.
DATEONLY
);
expect
(
Range
.
stringify
(
infiniteRange
)).
to
.
equal
(
infiniteRangeSQL
);
});
it
(
'should stringify date values with appropriate casting'
,
()
=>
{
const
Range
=
new
DataTypes
.
postgres
.
RANGE
(
DataTypes
.
DATE
);
expect
(
Range
.
stringify
(
infiniteRange
,
{
timezone
:
'+02:00'
})).
to
.
equal
(
infiniteRangeSQL
);
});
});
});
describe
(
'parse'
,
()
=>
{
...
...
test/unit/sql/where.test.js
View file @
5d2ba05
...
...
@@ -673,6 +673,28 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
postgres
:
"\"Timeline\".\"range\" <@ '[\"2000-02-01 00:00:00.000 +00:00\",\"2000-03-01 00:00:00.000 +00:00\")'"
});
testsql
(
'unboundedRange'
,
{
$contains
:
[
new
Date
(
Date
.
UTC
(
2000
,
1
,
1
)),
null
]
},
{
field
:
{
type
:
new
DataTypes
.
postgres
.
RANGE
(
DataTypes
.
DATE
)
},
prefix
:
'Timeline'
},
{
postgres
:
"\"Timeline\".\"unboundedRange\" @> '[\"2000-02-01 00:00:00.000 +00:00\",)'"
});
testsql
(
'unboundedRange'
,
{
$contains
:
[
-
Infinity
,
Infinity
]
},
{
field
:
{
type
:
new
DataTypes
.
postgres
.
RANGE
(
DataTypes
.
DATE
)
},
prefix
:
'Timeline'
},
{
postgres
:
"\"Timeline\".\"unboundedRange\" @> '[-infinity,infinity)'"
});
testsql
(
'reservedSeats'
,
{
$overlap
:
[
1
,
4
]
},
{
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment