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 cc65070d
authored
Apr 21, 2015
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jsonb integration tests
1 parent
d7152f77
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
205 additions
and
3 deletions
lib/dialects/abstract/query-generator.js
lib/dialects/postgres/index.js
lib/model.js
test/integration/model/json.test.js
test/unit/sql/where.test.js
lib/dialects/abstract/query-generator.js
View file @
cc65070
...
@@ -1608,7 +1608,7 @@ module.exports = (function() {
...
@@ -1608,7 +1608,7 @@ module.exports = (function() {
,
comparatorMap
,
comparatorMap
,
aliasMap
,
aliasMap
,
comparator
=
'='
,
comparator
=
'='
,
field
=
options
.
field
||
options
.
model
&&
options
.
model
.
rawAttributes
&&
options
.
model
.
rawAttributes
[
key
]
,
field
=
options
.
field
||
options
.
model
&&
options
.
model
.
rawAttributes
&&
options
.
model
.
rawAttributes
[
key
]
||
options
.
model
&&
options
.
model
.
fieldRawAttributesMap
&&
options
.
model
.
fieldRawAttributesMap
[
key
]
,
fieldType
=
options
.
type
||
(
field
&&
field
.
type
)
,
fieldType
=
options
.
type
||
(
field
&&
field
.
type
)
,
tmp
;
,
tmp
;
...
@@ -1745,7 +1745,6 @@ module.exports = (function() {
...
@@ -1745,7 +1745,6 @@ module.exports = (function() {
}
}
if
(
_
.
isPlainObject
(
value
)
&&
fieldType
instanceof
DataTypes
.
JSON
&&
options
.
json
!==
false
)
{
if
(
_
.
isPlainObject
(
value
)
&&
fieldType
instanceof
DataTypes
.
JSON
&&
options
.
json
!==
false
)
{
//console.log(key, value);
return
(
function
()
{
return
(
function
()
{
var
$items
=
[]
var
$items
=
[]
,
result
,
result
...
...
lib/dialects/postgres/index.js
View file @
cc65070
...
@@ -38,7 +38,8 @@ PostgresDialect.prototype.supports = _.merge(_.cloneDeep(Abstract.prototype.supp
...
@@ -38,7 +38,8 @@ PostgresDialect.prototype.supports = _.merge(_.cloneDeep(Abstract.prototype.supp
concurrently
:
true
,
concurrently
:
true
,
using
:
2
,
using
:
2
,
},
},
JSON
:
true
JSON
:
true
,
JSONB
:
true
});
});
PostgresDialect
.
prototype
.
Query
=
Query
;
PostgresDialect
.
prototype
.
Query
=
Query
;
...
...
lib/model.js
View file @
cc65070
...
@@ -287,6 +287,8 @@ module.exports = (function() {
...
@@ -287,6 +287,8 @@ module.exports = (function() {
this
.
_defaultValues
=
{};
this
.
_defaultValues
=
{};
this
.
Instance
.
prototype
.
validators
=
{};
this
.
Instance
.
prototype
.
validators
=
{};
this
.
fieldRawAttributesMap
=
{};
Utils
.
_
.
each
(
this
.
rawAttributes
,
function
(
definition
,
name
)
{
Utils
.
_
.
each
(
this
.
rawAttributes
,
function
(
definition
,
name
)
{
definition
.
type
=
self
.
sequelize
.
normalizeDataType
(
definition
.
type
);
definition
.
type
=
self
.
sequelize
.
normalizeDataType
(
definition
.
type
);
...
@@ -298,6 +300,8 @@ module.exports = (function() {
...
@@ -298,6 +300,8 @@ module.exports = (function() {
definition
.
field
=
name
;
definition
.
field
=
name
;
}
}
self
.
fieldRawAttributesMap
[
definition
.
field
]
=
definition
;
if
(
definition
.
type
instanceof
DataTypes
.
BOOLEAN
)
{
if
(
definition
.
type
instanceof
DataTypes
.
BOOLEAN
)
{
self
.
_booleanAttributes
.
push
(
name
);
self
.
_booleanAttributes
.
push
(
name
);
}
else
if
(
definition
.
type
instanceof
DataTypes
.
DATE
)
{
}
else
if
(
definition
.
type
instanceof
DataTypes
.
DATE
)
{
...
...
test/integration/model/json.test.js
0 → 100644
View file @
cc65070
'use strict'
;
/* jshint -W030 */
/* jshint -W110 */
var
chai
=
require
(
'chai'
)
,
sinon
=
require
(
'sinon'
)
,
Sequelize
=
require
(
'../../../index'
)
,
Promise
=
Sequelize
.
Promise
,
expect
=
chai
.
expect
,
Support
=
require
(
__dirname
+
'/../support'
)
,
DataTypes
=
require
(
__dirname
+
'/../../../lib/data-types'
)
,
config
=
require
(
__dirname
+
'/../../config/config'
)
,
current
=
Support
.
sequelize
;
chai
.
config
.
includeStack
=
true
;
describe
(
Support
.
getTestDialectTeaser
(
'Model'
),
function
()
{
if
(
current
.
dialect
.
supports
.
JSONB
)
{
describe
(
'JSONB'
,
function
()
{
beforeEach
(
function
()
{
this
.
Event
=
this
.
sequelize
.
define
(
'Event'
,
{
data
:
{
type
:
DataTypes
.
JSONB
,
field
:
'event_data'
,
index
:
true
}
});
return
this
.
Event
.
sync
({
force
:
true
});
});
it
(
'should create an instance with JSONB data'
,
function
()
{
return
this
.
Event
.
create
({
data
:
{
name
:
{
first
:
'Homer'
,
last
:
'Simpson'
},
employment
:
'Nuclear Safety Inspector'
}
}).
bind
(
this
).
then
(
function
()
{
return
this
.
Event
.
findAll
().
then
(
function
(
events
)
{
var
event
=
events
[
0
];
expect
(
event
.
get
(
'data'
)).
to
.
eql
({
name
:
{
first
:
'Homer'
,
last
:
'Simpson'
},
employment
:
'Nuclear Safety Inspector'
});
});
});
});
it
(
'should be possible to query a nested value'
,
function
()
{
return
Promise
.
join
(
this
.
Event
.
create
({
data
:
{
name
:
{
first
:
'Homer'
,
last
:
'Simpson'
},
employment
:
'Nuclear Safety Inspector'
}
}),
this
.
Event
.
create
({
data
:
{
name
:
{
first
:
'Marge'
,
last
:
'Simpson'
},
employment
:
'Housewife'
}
})
).
bind
(
this
).
then
(
function
()
{
return
this
.
Event
.
findAll
({
where
:
{
data
:
{
employment
:
'Housewife'
}
}
}).
then
(
function
(
events
)
{
var
event
=
events
[
0
];
expect
(
events
.
length
).
to
.
equal
(
1
);
expect
(
event
.
get
(
'data'
)).
to
.
eql
({
name
:
{
first
:
'Marge'
,
last
:
'Simpson'
},
employment
:
'Housewife'
});
});
});
});
it
(
'should be possible to query multiple nested values'
,
function
()
{
return
Promise
.
join
(
this
.
Event
.
create
({
data
:
{
name
:
{
first
:
'Homer'
,
last
:
'Simpson'
},
employment
:
'Nuclear Safety Inspector'
}
}),
this
.
Event
.
create
({
data
:
{
name
:
{
first
:
'Marge'
,
last
:
'Simpson'
},
employment
:
'Housewife'
}
}),
this
.
Event
.
create
({
data
:
{
name
:
{
first
:
'Bart'
,
last
:
'Simpson'
},
employment
:
'None'
}
})
).
bind
(
this
).
then
(
function
()
{
return
this
.
Event
.
findAll
({
where
:
{
data
:
{
name
:
{
last
:
'Simpson'
},
employment
:
{
$ne
:
'None'
}
}
},
order
:
[
[
'id'
,
'ASC'
]
]
}).
then
(
function
(
events
)
{
expect
(
events
.
length
).
to
.
equal
(
2
);
expect
(
events
[
0
].
get
(
'data'
)).
to
.
eql
({
name
:
{
first
:
'Homer'
,
last
:
'Simpson'
},
employment
:
'Nuclear Safety Inspector'
});
expect
(
events
[
1
].
get
(
'data'
)).
to
.
eql
({
name
:
{
first
:
'Marge'
,
last
:
'Simpson'
},
employment
:
'Housewife'
});
});
});
});
});
};
});
\ No newline at end of file
test/unit/sql/where.test.js
View file @
cc65070
...
@@ -476,6 +476,38 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
...
@@ -476,6 +476,38 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
default
:
"[User].[data]#>>'{nested, attribute}' = 'value'"
default
:
"[User].[data]#>>'{nested, attribute}' = 'value'"
});
});
testsql
(
'data'
,
{
nested
:
{
attribute
:
'value'
,
prop
:
{
$ne
:
'None'
}
}
},
{
field
:
{
type
:
new
DataTypes
.
JSONB
()
},
prefix
:
'User'
},
{
default
:
"([User].[data]#>>'{nested, attribute}' = 'value' AND [User].[data]#>>'{nested, prop}' != 'None')"
});
testsql
(
'data'
,
{
name
:
{
last
:
'Simpson'
},
employment
:
{
$ne
:
'None'
}
},
{
field
:
{
type
:
new
DataTypes
.
JSONB
()
},
prefix
:
'User'
},
{
default
:
"([User].[data]#>>'{name, last}' = 'Simpson' AND [User].[data]#>>'{employment}' != 'None')"
});
testsql
(
'data.nested.attribute'
,
'value'
,
{
testsql
(
'data.nested.attribute'
,
'value'
,
{
model
:
{
model
:
{
rawAttributes
:
{
rawAttributes
:
{
...
...
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