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 96610f71
authored
Sep 03, 2013
by
Daniel Durante
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into milestones/2.0.0
2 parents
6f838022
1c16932d
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
3 deletions
changelog.md
lib/dialects/postgres/query-generator.js
test/postgres/dao.test.js
changelog.md
View file @
96610f7
...
...
@@ -35,6 +35,7 @@
-
[
BUG
]
Default schemas should now be utilized when describing tables
[
#812
](
https://github.com/sequelize/sequelize/pull/812
)
. thanks to durango
-
[
BUG
]
Fixed eager loading for many-to-many associations.
[
#834
](
https://github.com/sequelize/sequelize/pull/834
)
. thanks to lemon-tree
-
[
BUG
]
allowNull: true enums can now be null
[
#857
](
https://github.com/sequelize/sequelize/pull/857
)
. thanks to durango
-
[
BUG
]
Fixes Postgres' ability to search within arrays.
[
#879
](
https://github.com/sequelize/sequelize/pull/879
)
. thanks to durango
-
[
FEATURE
]
Validate a model before it gets saved.
[
#601
](
https://github.com/sequelize/sequelize/pull/601
)
. thanks to durango
-
[
FEATURE
]
Schematics.
[
#564
](
https://github.com/sequelize/sequelize/pull/564
)
. thanks to durango
-
[
FEATURE
]
Foreign key constraints.
[
#595
](
https://github.com/sequelize/sequelize/pull/595
)
. thanks to optilude
...
...
lib/dialects/postgres/query-generator.js
View file @
96610f7
...
...
@@ -526,7 +526,7 @@ module.exports = (function() {
if
(
Utils
.
isHash
(
smth
))
{
smth
=
Utils
.
prependTableNameToHash
(
tableName
,
smth
)
result
=
this
.
hashToWhereConditions
(
smth
)
result
=
this
.
hashToWhereConditions
(
smth
,
factory
)
}
else
if
(
typeof
smth
===
'number'
)
{
var
primaryKeys
=
!!
factory
?
Object
.
keys
(
factory
.
primaryKeys
)
:
[]
if
(
primaryKeys
.
length
>
0
)
{
...
...
@@ -549,7 +549,7 @@ module.exports = (function() {
return
result
},
hashToWhereConditions
:
function
(
hash
)
{
hashToWhereConditions
:
function
(
hash
,
factory
)
{
var
result
=
[]
for
(
var
key
in
hash
)
{
...
...
@@ -561,10 +561,21 @@ module.exports = (function() {
if
(
Array
.
isArray
(
value
))
{
if
(
value
.
length
===
0
)
{
value
=
[
null
]
}
_value
=
"("
+
value
.
map
(
this
.
escape
).
join
(
','
)
+
")"
// Special conditions for searching within an array column type
var
_realKey
=
key
.
split
(
'.'
).
pop
()
if
(
!!
factory
&&
!!
factory
.
rawAttributes
[
_realKey
])
{
var
col
=
factory
.
rawAttributes
[
_realKey
]
if
((
!!
col
.
type
&&
col
.
type
.
match
(
/
\[\]
$/
)
!==
null
)
||
(
col
.
toString
().
match
(
/
\[\]
$/
)
!==
null
))
{
_value
=
'ARRAY['
+
value
.
map
(
this
.
escape
).
join
(
','
)
+
']::'
+
(
!!
col
.
type
?
col
.
type
:
col
.
toString
())
result
.
push
([
_key
,
_value
].
join
(
" && "
))
}
}
else
{
_value
=
"("
+
value
.
map
(
this
.
escape
).
join
(
','
)
+
")"
result
.
push
([
_key
,
_value
].
join
(
" IN "
))
}
}
else
if
((
value
)
&&
(
typeof
value
===
"object"
))
{
if
(
!!
value
.
join
)
{
//using as sentinel for join column => value
...
...
test/postgres/dao.test.js
View file @
96610f7
...
...
@@ -26,6 +26,28 @@ if (dialect.match(/^postgres/)) {
done
()
})
it
(
'should be able to search within an array'
,
function
(
done
)
{
this
.
User
.
all
({
where
:
{
email
:
[
'hello'
,
'world'
]}}).
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
).
to
.
equal
(
'SELECT * FROM "Users" WHERE "Users"."email" && ARRAY[\'hello\',\'world\']::TEXT[];'
)
done
()
})
})
it
(
'should be able to find a record while searching in an array'
,
function
(
done
)
{
var
self
=
this
this
.
User
.
bulkCreate
([
{
username
:
'bob'
,
email
:
[
'myemail@email.com'
]},
{
username
:
'tony'
,
email
:
[
'wrongemail@email.com'
]}
]).
success
(
function
()
{
self
.
User
.
all
({
where
:
{
email
:
[
'myemail@email.com'
]}}).
success
(
function
(
user
)
{
expect
(
user
).
to
.
be
.
instanceof
(
Array
)
expect
(
user
).
to
.
have
.
length
(
1
)
expect
(
user
[
0
].
username
).
to
.
equal
(
'bob'
)
done
()
})
})
})
it
(
'describeTable should tell me that a column is hstore and not USER-DEFINED'
,
function
(
done
)
{
this
.
sequelize
.
queryInterface
.
describeTable
(
'Users'
).
success
(
function
(
table
)
{
expect
(
table
.
document
.
type
).
to
.
equal
(
'HSTORE'
)
...
...
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