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 401adaf2
authored
Jul 25, 2015
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(datatypes) Select oids dynamically for hstore and geometry in postgres
1 parent
2ab9439d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
7 deletions
lib/dialects/postgres/connection-manager.js
lib/dialects/postgres/data-types.js
lib/dialects/postgres/connection-manager.js
View file @
401adaf
...
@@ -6,8 +6,7 @@ var AbstractConnectionManager = require('../abstract/connection-manager')
...
@@ -6,8 +6,7 @@ var AbstractConnectionManager = require('../abstract/connection-manager')
,
Promise
=
require
(
'../../promise'
)
,
Promise
=
require
(
'../../promise'
)
,
sequelizeErrors
=
require
(
'../../errors'
)
,
sequelizeErrors
=
require
(
'../../errors'
)
,
semver
=
require
(
'semver'
)
,
semver
=
require
(
'semver'
)
,
dataTypes
=
require
(
'../../data-types'
).
postgres
,
dataTypes
=
require
(
'../../data-types'
);
,
_
=
require
(
'lodash'
);
ConnectionManager
=
function
(
dialect
,
sequelize
)
{
ConnectionManager
=
function
(
dialect
,
sequelize
)
{
AbstractConnectionManager
.
call
(
this
,
dialect
,
sequelize
);
AbstractConnectionManager
.
call
(
this
,
dialect
,
sequelize
);
...
@@ -20,7 +19,7 @@ ConnectionManager = function(dialect, sequelize) {
...
@@ -20,7 +19,7 @@ ConnectionManager = function(dialect, sequelize) {
throw
new
Error
(
'Please install \''
+
(
sequelize
.
config
.
dialectModulePath
||
'pg'
)
+
'\' module manually'
);
throw
new
Error
(
'Please install \''
+
(
sequelize
.
config
.
dialectModulePath
||
'pg'
)
+
'\' module manually'
);
}
}
this
.
refreshTypeParser
(
dataTypes
);
this
.
refreshTypeParser
(
dataTypes
.
postgres
);
};
};
Utils
.
_
.
extend
(
ConnectionManager
.
prototype
,
AbstractConnectionManager
.
prototype
);
Utils
.
_
.
extend
(
ConnectionManager
.
prototype
,
AbstractConnectionManager
.
prototype
);
...
@@ -130,12 +129,27 @@ ConnectionManager.prototype.connect = function(config) {
...
@@ -130,12 +129,27 @@ ConnectionManager.prototype.connect = function(config) {
}
}
if
(
!
self
.
sequelize
.
config
.
keepDefaultTimezone
)
{
if
(
!
self
.
sequelize
.
config
.
keepDefaultTimezone
)
{
query
+=
'SET client_min_messages TO warning; SET TIME ZONE INTERVAL \''
+
self
.
sequelize
.
options
.
timezone
+
'\' HOUR TO MINUTE'
;
query
+=
'SET client_min_messages TO warning; SET TIME ZONE INTERVAL \''
+
self
.
sequelize
.
options
.
timezone
+
'\' HOUR TO MINUTE;'
;
}
// oids for hstore and geometry are dynamic - so select them at connection time
if
(
dataTypes
.
HSTORE
.
types
.
postgres
.
oids
.
length
===
0
)
{
query
+=
'SELECT typname, oid, typarray FROM pg_type WHERE typtype = \'b\' AND typname IN (\'hstore\', \'geometry\')'
;
}
}
return
new
Promise
(
function
(
resolve
,
reject
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
connection
.
query
(
query
).
on
(
'error'
,
function
(
err
)
{
connection
.
query
(
query
).
on
(
'error'
,
function
(
err
)
{
reject
(
err
);
reject
(
err
);
}).
on
(
'row'
,
function
(
row
)
{
var
type
;
if
(
row
.
typname
===
'geometry'
)
{
type
=
dataTypes
.
GEOMETRY
;
}
else
if
(
row
.
typname
===
'hstore'
)
{
type
=
dataTypes
.
HSTORE
;
}
type
.
types
.
postgres
.
oids
.
push
(
row
.
oid
);
type
.
types
.
postgres
.
array_oids
.
push
(
row
.
typarray
);
}).
on
(
'end'
,
function
()
{
}).
on
(
'end'
,
function
()
{
resolve
();
resolve
();
});
});
...
...
lib/dialects/postgres/data-types.js
View file @
401adaf
...
@@ -257,7 +257,8 @@ module.exports = function (BaseTypes) {
...
@@ -257,7 +257,8 @@ module.exports = function (BaseTypes) {
};
};
BaseTypes
.
GEOMETRY
.
types
.
postgres
=
{
BaseTypes
.
GEOMETRY
.
types
.
postgres
=
{
oids
:
[
2163225
]
oids
:
[],
array_oids
:
[]
};
};
GEOMETRY
.
parse
=
GEOMETRY
.
prototype
.
parse
=
function
(
value
)
{
GEOMETRY
.
parse
=
GEOMETRY
.
prototype
.
parse
=
function
(
value
)
{
...
@@ -276,8 +277,8 @@ module.exports = function (BaseTypes) {
...
@@ -276,8 +277,8 @@ module.exports = function (BaseTypes) {
};
};
BaseTypes
.
HSTORE
.
types
.
postgres
=
{
BaseTypes
.
HSTORE
.
types
.
postgres
=
{
oids
:
[
2164508
],
oids
:
[],
array_oids
:
[
2164513
]
array_oids
:
[]
};
};
var
RANGE
=
BaseTypes
.
RANGE
.
inherits
();
var
RANGE
=
BaseTypes
.
RANGE
.
inherits
();
...
...
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