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 bc108f9b
authored
Jan 06, 2015
by
Mick Hansen
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'kleinsch-postgres-json-custom-field'
2 parents
129fc898
fa19ed9d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
2 deletions
lib/dialects/abstract/query-generator.js
lib/dialects/postgres/query-generator.js
test/dialects/postgres/dao.test.js
lib/dialects/abstract/query-generator.js
View file @
bc108f9
...
@@ -315,7 +315,7 @@ module.exports = (function() {
...
@@ -315,7 +315,7 @@ module.exports = (function() {
}
}
var
value
=
attrValueHash
[
key
];
var
value
=
attrValueHash
[
key
];
values
.
push
(
this
.
quoteIdentifier
(
key
)
+
'='
+
this
.
escape
(
value
,
(
!!
attributes
&&
!!
attributes
[
key
]
?
attributes
[
key
]
:
undefined
)));
values
.
push
(
this
.
quoteIdentifier
(
key
)
+
'='
+
this
.
escape
(
value
,
(
modelAttributeMap
&&
modelAttributeMap
[
key
]
||
undefined
)));
}
}
var
replacements
=
{
var
replacements
=
{
...
...
lib/dialects/postgres/query-generator.js
View file @
bc108f9
...
@@ -896,7 +896,7 @@ module.exports = (function() {
...
@@ -896,7 +896,7 @@ module.exports = (function() {
}
else
if
(
field
.
type
===
DataTypes
.
ARRAY
(
DataTypes
.
HSTORE
)){
}
else
if
(
field
.
type
===
DataTypes
.
ARRAY
(
DataTypes
.
HSTORE
)){
return
"ARRAY["
+
Utils
.
_
.
map
(
value
,
function
(
v
){
return
"'"
+
hstore
.
stringify
(
v
)
+
"'::hstore"
;}).
join
(
","
)
+
"]::HSTORE[]"
;
return
"ARRAY["
+
Utils
.
_
.
map
(
value
,
function
(
v
){
return
"'"
+
hstore
.
stringify
(
v
)
+
"'::hstore"
;}).
join
(
","
)
+
"]::HSTORE[]"
;
}
}
}
else
if
(
Utils
.
_
.
isObject
(
value
)
&&
field
&&
(
field
.
type
===
DataTypes
.
JSON
))
{
}
else
if
(
Utils
.
_
.
isObject
(
value
)
&&
field
&&
(
field
.
type
===
DataTypes
.
JSON
||
field
.
type
===
DataTypes
.
JSONB
))
{
value
=
JSON
.
stringify
(
value
);
value
=
JSON
.
stringify
(
value
);
}
}
...
...
test/dialects/postgres/dao.test.js
View file @
bc108f9
...
@@ -72,6 +72,39 @@ if (dialect.match(/^postgres/)) {
...
@@ -72,6 +72,39 @@ if (dialect.match(/^postgres/)) {
});
});
});
});
it
(
'should insert json using a custom field name'
,
function
()
{
var
self
=
this
;
this
.
UserFields
=
this
.
sequelize
.
define
(
'UserFields'
,
{
emergencyContact
:
{
type
:
DataTypes
.
JSON
,
field
:
'emergy_contact'
}
});
return
this
.
UserFields
.
sync
({
force
:
true
}).
then
(
function
()
{
return
self
.
UserFields
.
create
({
emergencyContact
:
{
name
:
'joe'
,
phones
:
[
1337
,
42
]
}
}).
then
(
function
(
user
)
{
expect
(
user
.
emergencyContact
.
name
).
to
.
equal
(
'joe'
);
});
});
});
it
(
'should update json using a custom field name'
,
function
()
{
var
self
=
this
;
this
.
UserFields
=
this
.
sequelize
.
define
(
'UserFields'
,
{
emergencyContact
:
{
type
:
DataTypes
.
JSON
,
field
:
'emergy_contact'
}
});
return
this
.
UserFields
.
sync
({
force
:
true
}).
then
(
function
()
{
return
self
.
UserFields
.
create
({
emergencyContact
:
{
name
:
'joe'
,
phones
:
[
1337
,
42
]
}
}).
then
(
function
(
user
)
{
user
.
emergencyContact
=
{
name
:
'larry'
};
return
user
.
save
();
}).
then
(
function
(
user
)
{
expect
(
user
.
emergencyContact
.
name
).
to
.
equal
(
'larry'
);
});
});
});
it
(
'should be able retrieve json value as object'
,
function
()
{
it
(
'should be able retrieve json value as object'
,
function
()
{
var
self
=
this
;
var
self
=
this
;
var
emergencyContact
=
{
name
:
'kate'
,
phone
:
1337
};
var
emergencyContact
=
{
name
:
'kate'
,
phone
:
1337
};
...
...
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