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 9ebfb19f
authored
Mar 24, 2015
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change hstore and range parse to use pg types arrayparser. Provides a better fix for #3383
1 parent
ab8ca530
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
15 deletions
lib/dialects/postgres/index.js
lib/dialects/postgres/query.js
lib/dialects/postgres/index.js
View file @
9ebfb19
...
@@ -11,6 +11,10 @@ var PostgresDialect = function(sequelize) {
...
@@ -11,6 +11,10 @@ var PostgresDialect = function(sequelize) {
this
.
sequelize
=
sequelize
;
this
.
sequelize
=
sequelize
;
this
.
connectionManager
=
new
ConnectionManager
(
this
,
sequelize
);
this
.
connectionManager
=
new
ConnectionManager
(
this
,
sequelize
);
this
.
connectionManager
.
initPools
();
this
.
connectionManager
.
initPools
();
// parseDialectSpecificFields needs access to the pg lib in order to use its array parser. We cannot simply require pg in query.js since the user can specify another library path (such as pg-native etc)
Query
.
prototype
.
parseDialectSpecificFields
.
lib
=
this
.
connectionManager
.
lib
;
this
.
QueryGenerator
=
_
.
extend
({},
QueryGenerator
,
{
this
.
QueryGenerator
=
_
.
extend
({},
QueryGenerator
,
{
options
:
sequelize
.
options
,
options
:
sequelize
.
options
,
_dialect
:
this
,
_dialect
:
this
,
...
...
lib/dialects/postgres/query.js
View file @
9ebfb19
...
@@ -18,28 +18,16 @@ parseDialectSpecificFields = {
...
@@ -18,28 +18,16 @@ parseDialectSpecificFields = {
hstore
:
function
(
value
,
options
)
{
hstore
:
function
(
value
,
options
)
{
if
(
value
===
null
)
return
null
;
if
(
value
===
null
)
return
null
;
// hstore does not require you to escape newlines, but JSON.parse does!
return
DataTypes
.
ARRAY
.
is
(
options
.
dataType
,
DataTypes
.
HSTORE
)
?
return
DataTypes
.
ARRAY
.
is
(
options
.
dataType
,
DataTypes
.
HSTORE
)
?
Utils
.
_
.
map
(
this
.
lib
.
types
.
arrayParser
.
create
(
value
,
hstore
.
parse
).
parse
()
:
hstore
.
parse
(
value
);
JSON
.
parse
(
'['
+
value
.
substring
(
1
,
value
.
length
-
1
)
.
replace
(
'\n'
,
'\\n'
)
.
replace
(
'\t'
,
'\\t'
)
.
replace
(
'\r'
,
'\\r'
)
+
']'
),
function
(
v
)
{
return
hstore
.
parse
(
v
);
})
:
hstore
.
parse
(
value
);
},
},
range
:
function
(
value
,
options
)
{
range
:
function
(
value
,
options
)
{
if
(
value
===
null
)
return
null
;
if
(
value
===
null
)
return
null
;
return
DataTypes
.
ARRAY
.
is
(
options
.
dataType
,
DataTypes
.
RANGE
)
?
return
DataTypes
.
ARRAY
.
is
(
options
.
dataType
,
DataTypes
.
RANGE
)
?
Utils
.
_
.
map
(
this
.
lib
.
types
.
arrayParser
.
create
(
value
,
function
(
v
)
{
JSON
.
parse
(
'['
+
value
.
substring
(
1
,
value
.
length
-
1
)
+
']'
),
function
(
v
)
{
return
range
.
parse
(
v
,
options
.
dataType
.
type
);
return
range
.
parse
(
v
,
options
.
dataType
.
type
);
})
:
}).
parse
()
:
range
.
parse
(
value
,
options
.
dataType
);
range
.
parse
(
value
,
options
.
dataType
);
}
}
};
};
...
@@ -93,6 +81,8 @@ module.exports = (function() {
...
@@ -93,6 +81,8 @@ module.exports = (function() {
};
};
Utils
.
inherit
(
Query
,
AbstractQuery
);
Utils
.
inherit
(
Query
,
AbstractQuery
);
Query
.
prototype
.
parseDialectSpecificFields
=
parseDialectSpecificFields
;
Query
.
prototype
.
run
=
function
(
sql
)
{
Query
.
prototype
.
run
=
function
(
sql
)
{
/* jshint -W027 */
/* jshint -W027 */
this
.
sql
=
sql
;
this
.
sql
=
sql
;
...
@@ -156,6 +146,7 @@ module.exports = (function() {
...
@@ -156,6 +146,7 @@ module.exports = (function() {
results
.
forEach
(
function
(
result
)
{
results
.
forEach
(
function
(
result
)
{
var
attributes
=
/ON .*
?
(?:
USING .*
?\s)?\((
.*
)\)
/gi
.
exec
(
result
.
definition
)[
1
].
split
(
','
)
var
attributes
=
/ON .*
?
(?:
USING .*
?\s)?\((
.*
)\)
/gi
.
exec
(
result
.
definition
)[
1
].
split
(
','
)
,
field
,
field
,
attribute
,
attribute
,
columns
;
,
columns
;
...
...
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