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 99ea44d8
authored
Apr 17, 2015
by
Ruben Bridgewater
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor .on('sql', fn) to use logging instead
1 parent
cc439041
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
426 additions
and
291 deletions
test/integration/associations/belongs-to-many.test.js
test/integration/associations/self.test.js
test/integration/dialects/postgres/dao.test.js
test/integration/instance.test.js
test/integration/model.test.js
test/integration/model/and-or-where.test.js
test/integration/model/attributes/types.test.js
test/integration/model/create.test.js
test/integration/model/find.test.js
test/integration/promise.test.js
test/integration/associations/belongs-to-many.test.js
View file @
99ea44d
...
...
@@ -870,9 +870,11 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), function() {
this
.
Task
.
create
({
id
:
12
,
title
:
'task1'
}),
this
.
Task
.
create
({
id
:
15
,
title
:
'task2'
})
]).
spread
(
function
(
user
,
task1
,
task2
)
{
return
user
.
setTasks
([
task1
,
task2
]).
on
(
'sql'
,
spy
);
return
user
.
setTasks
([
task1
,
task2
],
{
logging
:
spy
});
}).
then
(
function
()
{
expect
(
spy
.
called
Twice
).
to
.
be
.
ok
;
// Once for SELECT, once for INSERT
expect
(
spy
.
called
Once
).
to
.
be
.
ok
;
});
});
...
...
@@ -886,9 +888,11 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), function() {
]).
spread
(
function
(
user
,
task1
,
task2
)
{
return
user
.
setTasks
([
task1
,
task2
]).
return
(
user
);
}).
then
(
function
(
user
)
{
return
user
.
setTasks
(
null
).
on
(
'sql'
,
spy
);
return
user
.
setTasks
(
null
,
{
logging
:
spy
});
}).
then
(
function
()
{
expect
(
spy
.
called
Twice
).
to
.
be
.
ok
;
// Once for SELECT, once for DELETE
expect
(
spy
.
called
Once
).
to
.
be
.
ok
;
});
});
});
// end optimization using bulk create, destroy and update
...
...
@@ -1099,6 +1103,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), function() {
it
(
'should correctly get associations when doubly linked'
,
function
()
{
var
self
=
this
;
var
spy
=
sinon
.
spy
();
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(
function
()
{
return
Promise
.
all
([
self
.
User
.
create
({
name
:
'Matt'
}),
...
...
@@ -1114,10 +1119,11 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), function() {
var
project
=
projects
[
0
];
expect
(
project
).
to
.
be
.
ok
;
return
self
.
user
.
removeProject
(
project
).
on
(
'sql'
,
function
(
sql
)
{
// TODO: rewrite this to use logging and check the generated sql
return
self
.
user
.
removeProject
(
project
,
{
logging
:
spy
}).
return
(
project
);
}).
then
(
function
(
project
)
{
expect
(
spy
.
calledTwice
).
to
.
be
.
ok
;
// Once for SELECT, once for REMOVE
return
self
.
user
.
setProjects
([
project
]);
});
});
...
...
test/integration/associations/self.test.js
View file @
99ea44d
...
...
@@ -108,6 +108,7 @@ describe(Support.getTestDialectTeaser('Self'), function() {
expect
(
foreignIdentifiers
).
to
.
have
.
members
([
'preexisting_parent'
,
'preexisting_child'
]);
expect
(
rawAttributes
).
to
.
have
.
members
([
'preexisting_parent'
,
'preexisting_child'
]);
var
count
=
0
;
return
this
.
sequelize
.
sync
({
force
:
true
}).
bind
(
this
).
then
(
function
()
{
return
Promise
.
all
([
Person
.
create
({
name
:
'Mary'
}),
...
...
@@ -118,26 +119,36 @@ describe(Support.getTestDialectTeaser('Self'), function() {
this
.
mary
=
mary
;
this
.
chris
=
chris
;
this
.
john
=
john
;
return
mary
.
setParents
([
john
]).
on
(
'sql'
,
function
(
sql
)
{
if
(
sql
.
match
(
/INSERT/
))
{
expect
(
sql
).
to
.
have
.
string
(
'preexisting_child'
);
expect
(
sql
).
to
.
have
.
string
(
'preexisting_parent'
);
return
mary
.
setParents
([
john
],
{
logging
:
function
(
sql
)
{
if
(
sql
.
match
(
/INSERT/
))
{
count
++
;
expect
(
sql
).
to
.
have
.
string
(
'preexisting_child'
);
expect
(
sql
).
to
.
have
.
string
(
'preexisting_parent'
);
}
}
});
}).
then
(
function
()
{
return
this
.
mary
.
addParent
(
this
.
chris
).
on
(
'sql'
,
function
(
sql
)
{
if
(
sql
.
match
(
/INSERT/
))
{
expect
(
sql
).
to
.
have
.
string
(
'preexisting_child'
);
expect
(
sql
).
to
.
have
.
string
(
'preexisting_parent'
);
return
this
.
mary
.
addParent
(
this
.
chris
,
{
logging
:
function
(
sql
)
{
if
(
sql
.
match
(
/INSERT/
))
{
count
++
;
expect
(
sql
).
to
.
have
.
string
(
'preexisting_child'
);
expect
(
sql
).
to
.
have
.
string
(
'preexisting_parent'
);
}
}
});
}).
then
(
function
()
{
return
this
.
john
.
getChildren
().
on
(
'sql'
,
function
(
sql
)
{
var
whereClause
=
sql
.
split
(
'FROM'
)[
1
];
// look only in the whereClause
expect
(
whereClause
).
to
.
have
.
string
(
'preexisting_child'
);
expect
(
whereClause
).
to
.
have
.
string
(
'preexisting_parent'
);
return
this
.
john
.
getChildren
(
undefined
,
{
logging
:
function
(
sql
)
{
count
++
;
var
whereClause
=
sql
.
split
(
'FROM'
)[
1
];
// look only in the whereClause
expect
(
whereClause
).
to
.
have
.
string
(
'preexisting_child'
);
expect
(
whereClause
).
to
.
have
.
string
(
'preexisting_parent'
);
}
});
}).
then
(
function
(
children
)
{
expect
(
count
).
to
.
be
.
equal
(
3
);
expect
(
_
.
map
(
children
,
'id'
)).
to
.
have
.
members
([
this
.
mary
.
id
]);
});
});
...
...
test/integration/dialects/postgres/dao.test.js
View file @
99ea44d
...
...
@@ -39,8 +39,10 @@ if (dialect.match(/^postgres/)) {
});
it
(
'should be able to search within an array'
,
function
()
{
return
this
.
User
.
findAll
({
where
:
{
email
:
[
'hello'
,
'world'
]},
attributes
:
[
'id'
,
'username'
,
'email'
,
'settings'
,
'document'
,
'phones'
,
'emergency_contact'
,
'friends'
]}).
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
).
to
.
equal
(
'SELECT "id", "username", "email", "settings", "document", "phones", "emergency_contact", "friends" FROM "Users" AS "User" WHERE "User"."email" = ARRAY[\'hello\',\'world\']::TEXT[];'
);
return
this
.
User
.
findAll
({
where
:
{
email
:
[
'hello'
,
'world'
]},
attributes
:
[
'id'
,
'username'
,
'email'
,
'settings'
,
'document'
,
'phones'
,
'emergency_contact'
,
'friends'
]},
{
logging
:
function
(
sql
)
{
expect
(
sql
).
to
.
equal
(
'Executing (default): SELECT "id", "username", "email", "settings", "document", "phones", "emergency_contact", "friends" FROM "Users" AS "User" WHERE "User"."email" = ARRAY[\'hello\',\'world\']::TEXT[];'
);
}
});
});
...
...
@@ -95,10 +97,11 @@ if (dialect.match(/^postgres/)) {
username
:
'bob'
,
emergency_contact
:
{
name
:
'joe'
,
phones
:
[
1337
,
42
]
}
},
{
fields
:
[
'id'
,
'username'
,
'document'
,
'emergency_contact'
]
}).
on
(
'sql'
,
function
(
sql
)
{
var
expected
=
'\'{"name":"joe","phones":[1337,42]}\''
;
expect
(
sql
.
indexOf
(
expected
)).
not
.
to
.
equal
(
-
1
);
fields
:
[
'id'
,
'username'
,
'document'
,
'emergency_contact'
],
logging
:
function
(
sql
)
{
var
expected
=
'\'{"name":"joe","phones":[1337,42]}\''
;
expect
(
sql
.
indexOf
(
expected
)).
not
.
to
.
equal
(
-
1
);
}
});
});
...
...
@@ -294,9 +297,11 @@ if (dialect.match(/^postgres/)) {
username
:
'bob'
,
email
:
[
'myemail@email.com'
],
settings
:
{
mailing
:
false
,
push
:
'facebook'
,
frequency
:
3
}
}).
on
(
'sql'
,
function
(
sql
)
{
var
expected
=
'\'"mailing"=>"false","push"=>"facebook","frequency"=>"3"\',\'"default"=>"\'\'value\'\'"\''
;
expect
(
sql
.
indexOf
(
expected
)).
not
.
to
.
equal
(
-
1
);
},
{
logging
:
function
(
sql
)
{
var
expected
=
'\'"mailing"=>"false","push"=>"facebook","frequency"=>"3"\',\'"default"=>"\'\'value\'\'"\''
;
expect
(
sql
.
indexOf
(
expected
)).
not
.
to
.
equal
(
-
1
);
}
});
});
...
...
@@ -375,25 +380,26 @@ if (dialect.match(/^postgres/)) {
mood
:
DataTypes
.
ENUM
(
'neutral'
,
'happy'
,
'sad'
,
'ecstatic'
,
'meh'
,
'joyful'
)
});
return
User
.
sync
(
).
then
(
function
()
{
expect
(
User
.
rawAttributes
.
mood
.
values
).
to
.
deep
.
equal
([
'neutral'
,
'happy'
,
'sad'
,
'ecstatic'
,
'meh'
,
'joyful'
]);
count
++
;
}).
on
(
'sql'
,
function
(
sql
)
{
if
(
sql
.
indexOf
(
'neutral'
)
>
-
1
)
{
expect
(
sql
).
to
.
equal
(
"ALTER TYPE \"enum_UserEnums_mood\" ADD VALUE 'neutral' BEFORE 'happy'"
)
;
count
++
;
}
else
if
(
sql
.
indexOf
(
'ecstatic'
)
>
-
1
)
{
expect
(
sql
).
to
.
equal
(
"ALTER TYPE \"enum_UserEnums_mood\" ADD VALUE 'ecstatic' BEFORE 'meh'"
)
;
count
++
;
}
else
if
(
sql
.
indexOf
(
'joyful'
)
>
-
1
)
{
expect
(
sql
).
to
.
equal
(
"ALTER TYPE \"enum_UserEnums_mood\" ADD VALUE 'joyful' AFTER 'meh'"
)
;
count
++
;
return
User
.
sync
({
logging
:
function
(
sql
)
{
console
.
log
(
sql
)
;
if
(
sql
.
indexOf
(
'neutral'
)
>
-
1
)
{
expect
(
sql
).
to
.
equal
(
"ALTER TYPE \"enum_UserEnums_mood\" ADD VALUE 'neutral' BEFORE 'happy'"
);
count
++
;
}
else
if
(
sql
.
indexOf
(
'ecstatic'
)
>
-
1
)
{
expect
(
sql
).
to
.
equal
(
"ALTER TYPE \"enum_UserEnums_mood\" ADD VALUE 'ecstatic' BEFORE 'meh'"
);
count
++
;
}
else
if
(
sql
.
indexOf
(
'joyful'
)
>
-
1
)
{
expect
(
sql
).
to
.
equal
(
"ALTER TYPE \"enum_UserEnums_mood\" ADD VALUE 'joyful' AFTER 'meh'"
);
count
++
;
}
}
}).
then
(
function
()
{
expect
(
User
.
rawAttributes
.
mood
.
values
).
to
.
deep
.
equal
([
'neutral'
,
'happy'
,
'sad'
,
'ecstatic'
,
'meh'
,
'joyful'
]);
expect
(
count
).
to
.
equal
(
3
);
});
}).
then
(
function
()
{
expect
(
count
).
to
.
equal
(
4
);
});
});
});
...
...
@@ -475,8 +481,10 @@ if (dialect.match(/^postgres/)) {
it
(
'should use postgres "TIMESTAMP WITH TIME ZONE" instead of "DATETIME"'
,
function
()
{
return
this
.
User
.
create
({
dates
:
[]
}).
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
.
indexOf
(
'TIMESTAMP WITH TIME ZONE'
)).
to
.
be
.
greaterThan
(
0
);
},
{
logging
:
function
(
sql
)
{
expect
(
sql
.
indexOf
(
'TIMESTAMP WITH TIME ZONE'
)).
to
.
be
.
greaterThan
(
0
);
}
});
});
});
...
...
test/integration/instance.test.js
View file @
99ea44d
...
...
@@ -1767,9 +1767,11 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
return
UserDelete
.
create
({
name
:
'hallo'
,
bio
:
'welt'
}).
then
(
function
(
u
)
{
return
UserDelete
.
findAll
().
then
(
function
(
users
)
{
expect
(
users
.
length
).
to
.
equal
(
1
);
return
u
.
destroy
().
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
).
to
.
exist
;
expect
(
sql
.
toUpperCase
().
indexOf
(
'DELETE'
)).
to
.
be
.
above
(
-
1
);
return
u
.
destroy
({
logging
:
function
(
sql
)
{
expect
(
sql
).
to
.
exist
;
expect
(
sql
.
toUpperCase
().
indexOf
(
'DELETE'
)).
to
.
be
.
above
(
-
1
);
}
});
});
});
...
...
test/integration/model.test.js
View file @
99ea44d
...
...
@@ -842,16 +842,22 @@ describe(Support.getTestDialectTeaser('Model'), function() {
paranoid
:
true
});
var
test
=
false
;
return
User
.
sync
({
force
:
true
}).
then
(
function
()
{
return
User
.
create
({
username
:
'Peter'
,
secretValue
:
'42'
}).
then
(
function
(
user
)
{
return
user
.
updateAttributes
({
secretValue
:
'43'
},
[
'secretValue'
]).
on
(
'sql'
,
function
(
sql
)
{
if
(
dialect
===
'mssql'
)
{
expect
(
sql
).
to
.
not
.
contain
(
'createdAt'
);
}
else
{
expect
(
sql
).
to
.
match
(
/UPDATE
\s
+
[
`"
]
+User1s
[
`"
]
+
\s
+SET
\s
+
[
`"
]
+secretValue
[
`"
]
='43',
[
`"
]
+updatedAt
[
`"
]
+='
[^
`",
]
+'
\s
+WHERE
[
`"
]
+id
[
`"
]
+
\s
=
\s
1/
);
return
user
.
updateAttributes
({
secretValue
:
'43'
},
{
fields
:
[
'secretValue'
],
logging
:
function
(
sql
)
{
test
=
true
;
if
(
dialect
===
'mssql'
)
{
expect
(
sql
).
to
.
not
.
contain
(
'createdAt'
);
}
else
{
expect
(
sql
).
to
.
match
(
/UPDATE
\s
+
[
`"
]
+User1s
[
`"
]
+
\s
+SET
\s
+
[
`"
]
+secretValue
[
`"
]
='43',
[
`"
]
+updatedAt
[
`"
]
+='
[^
`",
]
+'
\s
+WHERE
[
`"
]
+id
[
`"
]
+
\s
=
\s
1/
);
}
}
});
});
}).
then
(
function
()
{
expect
(
test
).
to
.
be
.
true
;
});
});
...
...
@@ -862,16 +868,20 @@ describe(Support.getTestDialectTeaser('Model'), function() {
},
{
paranoid
:
true
});
var
test
=
false
;
return
User
.
sync
({
force
:
true
}).
then
(
function
()
{
return
User
.
create
({
name
:
'meg'
,
bio
:
'none'
}).
then
(
function
(
u
)
{
expect
(
u
).
to
.
exist
;
expect
(
u
).
not
.
to
.
be
.
null
;
return
u
.
updateAttributes
({
name
:
'brian'
}).
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
).
to
.
exist
;
expect
(
sql
.
toUpperCase
().
indexOf
(
'UPDATE'
)).
to
.
be
.
above
(
-
1
);
return
u
.
updateAttributes
({
name
:
'brian'
},
{
logging
:
function
(
sql
)
{
test
=
true
;
expect
(
sql
).
to
.
exist
;
expect
(
sql
.
toUpperCase
().
indexOf
(
'UPDATE'
)).
to
.
be
.
above
(
-
1
);
}
});
});
}).
then
(
function
()
{
expect
(
test
).
to
.
be
.
true
;
});
});
...
...
@@ -1572,9 +1582,15 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
it
(
'allows sql logging'
,
function
()
{
return
this
.
User
.
count
().
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
).
to
.
exist
;
expect
(
sql
.
toUpperCase
().
indexOf
(
'SELECT'
)).
to
.
be
.
above
(
-
1
);
var
test
=
false
;
return
this
.
User
.
count
({
logging
:
function
(
sql
)
{
test
=
true
;
expect
(
sql
).
not
.
to
.
exist
;
expect
(
sql
.
toUpperCase
().
indexOf
(
'SELECT'
)).
to
.
be
.
above
(
-
1
);
}
}).
then
(
function
()
{
expect
(
test
).
to
.
be
.
true
;
});
});
...
...
@@ -1659,9 +1675,15 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
it
(
'allows sql logging'
,
function
()
{
return
this
.
UserWithAge
.
min
(
'age'
).
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
).
to
.
exist
;
expect
(
sql
.
toUpperCase
().
indexOf
(
'SELECT'
)).
to
.
be
.
above
(
-
1
);
var
test
=
false
;
return
this
.
UserWithAge
.
min
(
'age'
,
{
logging
:
function
(
sql
)
{
test
=
true
;
expect
(
sql
).
not
.
to
.
exist
;
expect
(
sql
.
toUpperCase
().
indexOf
(
'SELECT'
)).
to
.
be
.
above
(
-
1
);
}
}).
then
(
function
()
{
expect
(
test
).
to
.
be
.
true
;
});
});
...
...
@@ -1783,9 +1805,15 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
it
(
'allows sql logging'
,
function
()
{
return
this
.
UserWithAge
.
max
(
'age'
).
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
).
to
.
exist
;
expect
(
sql
.
toUpperCase
().
indexOf
(
'SELECT'
)).
to
.
be
.
above
(
-
1
);
var
logged
=
false
;
return
this
.
UserWithAge
.
max
(
'age'
,
{
logging
:
function
(
sql
)
{
expect
(
sql
).
to
.
exist
;
logged
=
true
;
expect
(
sql
.
toUpperCase
().
indexOf
(
'SELECT'
)).
to
.
be
.
above
(
-
1
);
}
}).
then
(
function
()
{
expect
(
logged
).
to
.
true
;
});
});
});
...
...
@@ -1847,9 +1875,15 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
it
(
'allows sql logging'
,
function
()
{
return
this
.
UserWithAge
.
sum
(
'age'
).
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
).
to
.
exist
;
expect
(
sql
.
toUpperCase
().
indexOf
(
'SELECT'
)).
to
.
be
.
above
(
-
1
);
var
logged
=
false
;
return
this
.
UserWithAge
.
sum
(
'age'
,
{
logging
:
function
(
sql
)
{
expect
(
sql
).
to
.
exist
;
logged
=
true
;
expect
(
sql
.
toUpperCase
().
indexOf
(
'SELECT'
)).
to
.
be
.
above
(
-
1
);
}
}).
then
(
function
()
{
expect
(
logged
).
to
.
true
;
});
});
});
...
...
@@ -1897,19 +1931,28 @@ describe(Support.getTestDialectTeaser('Model'), function() {
if
(
Support
.
dialectIsMySQL
()
||
dialect
===
'sqlite'
)
{
it
(
'should take schemaDelimiter into account if applicable'
,
function
()
{
var
test
=
0
;
var
UserSpecialUnderscore
=
this
.
sequelize
.
define
(
'UserSpecialUnderscore'
,
{
age
:
Sequelize
.
INTEGER
},
{
schema
:
'hello'
,
schemaDelimiter
:
'_'
});
var
UserSpecialDblUnderscore
=
this
.
sequelize
.
define
(
'UserSpecialDblUnderscore'
,
{
age
:
Sequelize
.
INTEGER
});
return
UserSpecialUnderscore
.
sync
({
force
:
true
}).
then
(
function
(
User
)
{
return
UserSpecialDblUnderscore
.
schema
(
'hello'
,
'__'
).
sync
({
force
:
true
}).
then
(
function
(
DblUser
)
{
return
DblUser
.
create
({
age
:
3
}).
on
(
'sql'
,
function
(
dblSql
)
{
expect
(
dblSql
).
to
.
exist
;
expect
(
dblSql
.
indexOf
(
'INSERT INTO `hello__UserSpecialDblUnderscores`'
)).
to
.
be
.
above
(
-
1
);
}).
then
(
function
()
{
return
User
.
create
({
age
:
3
}).
on
(
'sql'
,
function
(
sql
)
{
return
DblUser
.
create
({
age
:
3
},
{
logging
:
function
(
sql
)
{
expect
(
sql
).
to
.
exist
;
expect
(
sql
.
indexOf
(
'INSERT INTO `hello_UserSpecialUnderscores`'
)).
to
.
be
.
above
(
-
1
);
test
++
;
expect
(
sql
.
indexOf
(
'INSERT INTO `hello__UserSpecialDblUnderscores`'
)).
to
.
be
.
above
(
-
1
);
}
}).
then
(
function
()
{
return
User
.
create
({
age
:
3
},
{
logging
:
function
(
sql
)
{
expect
(
sql
).
to
.
exist
;
test
++
;
expect
(
sql
.
indexOf
(
'INSERT INTO `hello_UserSpecialUnderscores`'
)).
to
.
be
.
above
(
-
1
);
}
});
});
}).
then
(
function
()
{
expect
(
test
).
to
.
equal
(
2
);
});
});
});
...
...
@@ -1924,27 +1967,27 @@ describe(Support.getTestDialectTeaser('Model'), function() {
return
UserPublic
.
sync
({
force
:
true
}).
then
(
function
()
{
return
UserPublic
.
schema
(
'special'
).
sync
({
force
:
true
}).
then
(
function
()
{
return
self
.
sequelize
.
queryInterface
.
describeTable
(
'Publics'
)
.
on
(
'sql'
,
function
(
sql
)
{
if
(
dialect
===
'sqlite'
||
Support
.
dialectIsMySQL
()
||
dialect
===
'mssql'
)
{
expect
(
sql
).
to
.
not
.
contain
(
'special'
);
count
++
;
return
self
.
sequelize
.
queryInterface
.
describeTable
(
'Publics'
,
{
logging
:
function
(
sql
)
{
if
(
dialect
===
'sqlite'
||
Support
.
dialectIsMySQL
()
||
dialect
===
'mssql'
)
{
expect
(
sql
).
to
.
not
.
contain
(
'special'
);
count
++
;
}
}
})
.
then
(
function
(
table
)
{
}).
then
(
function
(
table
)
{
if
(
dialect
===
'postgres'
)
{
expect
(
table
.
id
.
defaultValue
).
to
.
not
.
contain
(
'special'
);
count
++
;
}
return
self
.
sequelize
.
queryInterface
.
describeTable
(
'Publics'
,
'special'
)
.
on
(
'sql'
,
function
(
sql
)
{
if
(
dialect
===
'sqlite'
||
Support
.
dialectIsMySQL
()
||
dialect
===
'mssql'
)
{
expect
(
sql
).
to
.
contain
(
'special'
);
count
++
;
return
self
.
sequelize
.
queryInterface
.
describeTable
(
'Publics'
,
{
schema
:
'special'
,
logging
:
function
(
sql
)
{
if
(
dialect
===
'sqlite'
||
Support
.
dialectIsMySQL
()
||
dialect
===
'mssql'
)
{
expect
(
sql
).
to
.
contain
(
'special'
);
count
++
;
}
}
})
.
then
(
function
(
table
)
{
}).
then
(
function
(
table
)
{
if
(
dialect
===
'postgres'
)
{
expect
(
table
.
id
.
defaultValue
).
to
.
contain
(
'special'
);
count
++
;
...
...
@@ -2000,50 +2043,55 @@ describe(Support.getTestDialectTeaser('Model'), function() {
it
(
'should be able to create and update records under any valid schematic'
,
function
()
{
var
self
=
this
;
var
logged
=
0
;
return
self
.
UserPublic
.
sync
({
force
:
true
}).
then
(
function
(
UserPublicSync
)
{
return
UserPublicSync
.
create
({
age
:
3
}).
on
(
'sql'
,
function
(
UserPublic
)
{
expect
(
UserPublic
).
to
.
exist
;
if
(
dialect
===
'postgres'
)
{
expect
(
self
.
UserSpecialSync
.
getTableName
().
toString
()).
to
.
equal
(
'"special"."UserSpecials"'
);
expect
(
UserPublic
.
indexOf
(
'INSERT INTO "UserPublics"'
)).
to
.
be
.
above
(
-
1
);
}
else
if
(
dialect
===
'sqlite'
)
{
expect
(
self
.
UserSpecialSync
.
getTableName
().
toString
()).
to
.
equal
(
'`special.UserSpecials`'
);
expect
(
UserPublic
.
indexOf
(
'INSERT INTO `UserPublics`'
)).
to
.
be
.
above
(
-
1
);
}
else
if
(
dialect
===
'mssql'
)
{
expect
(
self
.
UserSpecialSync
.
getTableName
().
toString
()).
to
.
equal
(
'[special].[UserSpecials]'
);
expect
(
UserPublic
.
indexOf
(
'INSERT INTO [UserPublics]'
)).
to
.
be
.
above
(
-
1
);
}
else
{
expect
(
self
.
UserSpecialSync
.
getTableName
().
toString
()).
to
.
equal
(
'`special.UserSpecials`'
);
expect
(
UserPublic
.
indexOf
(
'INSERT INTO `UserPublics`'
)).
to
.
be
.
above
(
-
1
);
}
})
.
then
(
function
()
{
return
self
.
UserSpecialSync
.
schema
(
'special'
).
create
({
age
:
3
})
.
on
(
'sql'
,
function
(
UserSpecial
)
{
expect
(
UserSpecial
).
to
.
exist
;
return
UserPublicSync
.
create
({
age
:
3
},
{
logging
:
function
(
UserPublic
)
{
logged
++
;
if
(
dialect
===
'postgres'
)
{
expect
(
UserSpecial
.
indexOf
(
'INSERT INTO "special"."UserSpecials"'
)).
to
.
be
.
above
(
-
1
);
expect
(
self
.
UserSpecialSync
.
getTableName
().
toString
()).
to
.
equal
(
'"special"."UserSpecials"'
);
expect
(
UserPublic
.
indexOf
(
'INSERT INTO "UserPublics"'
)).
to
.
be
.
above
(
-
1
);
}
else
if
(
dialect
===
'sqlite'
)
{
expect
(
UserSpecial
.
indexOf
(
'INSERT INTO `special.UserSpecials`'
)).
to
.
be
.
above
(
-
1
);
expect
(
self
.
UserSpecialSync
.
getTableName
().
toString
()).
to
.
equal
(
'`special.UserSpecials`'
);
expect
(
UserPublic
.
indexOf
(
'INSERT INTO `UserPublics`'
)).
to
.
be
.
above
(
-
1
);
}
else
if
(
dialect
===
'mssql'
)
{
expect
(
UserSpecial
.
indexOf
(
'INSERT INTO [special].[UserSpecials]'
)).
to
.
be
.
above
(
-
1
);
expect
(
self
.
UserSpecialSync
.
getTableName
().
toString
()).
to
.
equal
(
'[special].[UserSpecials]'
);
expect
(
UserPublic
.
indexOf
(
'INSERT INTO [UserPublics]'
)).
to
.
be
.
above
(
-
1
);
}
else
{
expect
(
UserSpecial
.
indexOf
(
'INSERT INTO `special.UserSpecials`'
)).
to
.
be
.
above
(
-
1
);
expect
(
self
.
UserSpecialSync
.
getTableName
().
toString
()).
to
.
equal
(
'`special.UserSpecials`'
);
expect
(
UserPublic
.
indexOf
(
'INSERT INTO `UserPublics`'
)).
to
.
be
.
above
(
-
1
);
}
}
)
.
then
(
function
(
UserSpecial
)
{
return
UserSpecial
.
updateAttributes
({
age
:
5
})
.
on
(
'sql'
,
function
(
user
)
{
expect
(
user
).
to
.
exist
;
}
}).
then
(
function
(
UserPublic
)
{
return
self
.
UserSpecialSync
.
schema
(
'special'
).
create
({
age
:
3
},
{
logging
:
function
(
UserSpecial
)
{
logged
++
;
if
(
dialect
===
'postgres'
)
{
expect
(
user
.
indexOf
(
'UPDATE "special"."UserSpecials"'
)).
to
.
be
.
above
(
-
1
);
expect
(
UserSpecial
.
indexOf
(
'INSERT INTO "special"."UserSpecials"'
)).
to
.
be
.
above
(
-
1
);
}
else
if
(
dialect
===
'sqlite'
)
{
expect
(
UserSpecial
.
indexOf
(
'INSERT INTO `special.UserSpecials`'
)).
to
.
be
.
above
(
-
1
);
}
else
if
(
dialect
===
'mssql'
)
{
expect
(
user
.
indexOf
(
'UPDATE
[special].[UserSpecials]'
)).
to
.
be
.
above
(
-
1
);
expect
(
UserSpecial
.
indexOf
(
'INSERT INTO
[special].[UserSpecials]'
)).
to
.
be
.
above
(
-
1
);
}
else
{
expect
(
user
.
indexOf
(
'UPDATE `special.UserSpecials`'
)).
to
.
be
.
above
(
-
1
);
expect
(
UserSpecial
.
indexOf
(
'INSERT INTO `special.UserSpecials`'
)).
to
.
be
.
above
(
-
1
);
}
}
}).
then
(
function
(
UserSpecial
)
{
return
UserSpecial
.
updateAttributes
({
age
:
5
},
{
logging
:
function
(
user
)
{
logged
++
;
if
(
dialect
===
'postgres'
)
{
expect
(
user
.
indexOf
(
'UPDATE "special"."UserSpecials"'
)).
to
.
be
.
above
(
-
1
);
}
else
if
(
dialect
===
'mssql'
)
{
expect
(
user
.
indexOf
(
'UPDATE [special].[UserSpecials]'
)).
to
.
be
.
above
(
-
1
);
}
else
{
expect
(
user
.
indexOf
(
'UPDATE `special.UserSpecials`'
)).
to
.
be
.
above
(
-
1
);
}
}
});
});
}).
then
(
function
()
{
expect
(
logged
).
to
.
equal
(
3
);
});
});
});
...
...
test/integration/model/and-or-where.test.js
View file @
99ea44d
...
...
@@ -31,11 +31,13 @@ describe(Support.getTestDialectTeaser('Model'), function() {
it
(
'can handle plain strings'
,
function
()
{
return
this
.
User
.
find
({
where
:
Sequelize
[
method
](
'1=1'
,
'2=2'
)
}).
on
(
'sql'
,
function
(
sql
)
{
if
(
dialect
===
'mssql'
)
{
expect
(
sql
).
to
.
contain
(
'WHERE (1=1 '
+
word
+
' 2=2)'
);
}
else
{
expect
(
sql
).
to
.
contain
(
'WHERE (1=1 '
+
word
+
' 2=2) LIMIT 1'
);
},
{
logging
:
function
(
sql
)
{
if
(
dialect
===
'mssql'
)
{
expect
(
sql
).
to
.
contain
(
'WHERE (1=1 '
+
word
+
' 2=2)'
);
}
else
{
expect
(
sql
).
to
.
contain
(
'WHERE (1=1 '
+
word
+
' 2=2) LIMIT 1'
);
}
}
});
});
...
...
@@ -43,11 +45,13 @@ describe(Support.getTestDialectTeaser('Model'), function() {
it
(
'can handle arrays'
,
function
()
{
return
this
.
User
.
find
({
where
:
Sequelize
[
method
]([
'1=?'
,
1
],
[
'2=?'
,
2
])
}).
on
(
'sql'
,
function
(
sql
)
{
if
(
dialect
===
'mssql'
)
{
expect
(
sql
).
to
.
contain
(
'WHERE (1=1 '
+
word
+
' 2=2)'
);
}
else
{
expect
(
sql
).
to
.
contain
(
'WHERE (1=1 '
+
word
+
' 2=2) LIMIT 1'
);
},
{
logging
:
function
(
sql
)
{
if
(
dialect
===
'mssql'
)
{
expect
(
sql
).
to
.
contain
(
'WHERE (1=1 '
+
word
+
' 2=2)'
);
}
else
{
expect
(
sql
).
to
.
contain
(
'WHERE (1=1 '
+
word
+
' 2=2) LIMIT 1'
);
}
}
});
});
...
...
@@ -55,42 +59,44 @@ describe(Support.getTestDialectTeaser('Model'), function() {
it
(
'can handle objects'
,
function
()
{
return
this
.
User
.
find
({
where
:
Sequelize
[
method
]({
username
:
'foo'
,
intVal
:
2
},
{
secretValue
:
'bar'
})
}).
on
(
'sql'
,
function
(
sql
)
{
var
expectation
=
({
mysql
:
"WHERE (`User`.`username`='foo' AND `User`.`intVal`=2 "
+
word
+
" `User`.`secretValue`='bar')"
,
mssql
:
'WHERE ([User].[username]=\'foo\' AND [User].[intVal]=2 '
+
word
+
' [User].[secretValue]=\'bar\')'
,
sqlite
:
"WHERE (`User`.`username`='foo' AND `User`.`intVal`=2 "
+
word
+
" `User`.`secretValue`='bar')"
,
postgres
:
'WHERE ("User"."username"=\'foo\' AND "User"."intVal"=2 '
+
word
+
' "User"."secretValue"=\'bar\')'
,
mariadb
:
"WHERE (`User`.`username`='foo' AND `User`.`intVal`=2 "
+
word
+
" `User`.`secretValue`='bar')"
})[
Support
.
getTestDialect
()];
},
{
logging
:
function
(
sql
)
{
var
expectation
=
({
mysql
:
"WHERE (`User`.`username`='foo' AND `User`.`intVal`=2 "
+
word
+
" `User`.`secretValue`='bar')"
,
mssql
:
'WHERE ([User].[username]=\'foo\' AND [User].[intVal]=2 '
+
word
+
' [User].[secretValue]=\'bar\')'
,
sqlite
:
"WHERE (`User`.`username`='foo' AND `User`.`intVal`=2 "
+
word
+
" `User`.`secretValue`='bar')"
,
postgres
:
'WHERE ("User"."username"=\'foo\' AND "User"."intVal"=2 '
+
word
+
' "User"."secretValue"=\'bar\')'
,
mariadb
:
"WHERE (`User`.`username`='foo' AND `User`.`intVal`=2 "
+
word
+
" `User`.`secretValue`='bar')"
})[
Support
.
getTestDialect
()];
if
(
!
expectation
)
{
console
.
log
(
sql
);
throw
new
Error
(
'Undefined expectation for '
+
Support
.
getTestDialect
());
if
(
!
expectation
)
{
console
.
log
(
sql
);
throw
new
Error
(
'Undefined expectation for '
+
Support
.
getTestDialect
());
}
expect
(
sql
).
to
.
contain
(
expectation
);
}
expect
(
sql
).
to
.
contain
(
expectation
);
});
});
it
(
'can handle numbers'
,
function
()
{
return
this
.
User
.
find
({
where
:
Sequelize
[
method
](
1
,
2
)
}).
on
(
'sql'
,
function
(
sql
)
{
var
expectation
=
({
mysql
:
'WHERE (`User`.`id`=1 '
+
word
+
' `User`.`id`=2)'
,
sqlite
:
'WHERE (`User`.`id`=1 '
+
word
+
' `User`.`id`=2)'
,
postgres
:
'WHERE ("User"."id"=1 '
+
word
+
' "User"."id"=2)'
,
mssql
:
'WHERE ([User].[id]=1 '
+
word
+
' [User].[id]=2)'
,
mariadb
:
'WHERE (`User`.`id`=1 '
+
word
+
' `User`.`id`=2)'
})[
Support
.
getTestDialect
()];
},
{
logging
:
function
(
sql
)
{
var
expectation
=
({
mysql
:
'WHERE (`User`.`id`=1 '
+
word
+
' `User`.`id`=2)'
,
sqlite
:
'WHERE (`User`.`id`=1 '
+
word
+
' `User`.`id`=2)'
,
postgres
:
'WHERE ("User"."id"=1 '
+
word
+
' "User"."id"=2)'
,
mssql
:
'WHERE ([User].[id]=1 '
+
word
+
' [User].[id]=2)'
,
mariadb
:
'WHERE (`User`.`id`=1 '
+
word
+
' `User`.`id`=2)'
})[
Support
.
getTestDialect
()];
if
(
!
expectation
)
{
console
.
log
(
sql
);
throw
new
Error
(
'Undefined expectation for '
+
Support
.
getTestDialect
());
if
(
!
expectation
)
{
console
.
log
(
sql
);
throw
new
Error
(
'Undefined expectation for '
+
Support
.
getTestDialect
());
}
expect
(
sql
).
to
.
contain
(
expectation
);
}
expect
(
sql
).
to
.
contain
(
expectation
);
});
});
});
...
...
@@ -100,11 +106,13 @@ describe(Support.getTestDialectTeaser('Model'), function() {
it
(
'allows nesting of Sequelize.or'
,
function
()
{
return
this
.
User
.
find
({
where
:
Sequelize
.
and
(
Sequelize
.
or
(
'1=1'
,
'2=2'
),
Sequelize
.
or
(
'3=3'
,
'4=4'
))
}).
on
(
'sql'
,
function
(
sql
)
{
if
(
dialect
===
'mssql'
)
{
expect
(
sql
).
to
.
contain
(
'WHERE ((1=1 OR 2=2) AND (3=3 OR 4=4))'
);
}
else
{
expect
(
sql
).
to
.
contain
(
'WHERE ((1=1 OR 2=2) AND (3=3 OR 4=4)) LIMIT 1'
);
},
{
logging
:
function
(
sql
)
{
if
(
dialect
===
'mssql'
)
{
expect
(
sql
).
to
.
contain
(
'WHERE ((1=1 OR 2=2) AND (3=3 OR 4=4))'
);
}
else
{
expect
(
sql
).
to
.
contain
(
'WHERE ((1=1 OR 2=2) AND (3=3 OR 4=4)) LIMIT 1'
);
}
}
});
});
...
...
@@ -113,32 +121,36 @@ describe(Support.getTestDialectTeaser('Model'), function() {
return
this
.
User
.
find
({
where
:
Sequelize
.
and
(
Sequelize
.
or
({
username
:
{
eq
:
'foo'
}},
{
username
:
{
eq
:
'bar'
}}),
Sequelize
.
or
({
id
:
{
eq
:
1
}},
{
id
:
{
eq
:
4
}}))
}).
on
(
'sql'
,
function
(
sql
)
{
var
expectation
=
({
mysql
:
"WHERE ((`User`.`username` = 'foo' OR `User`.`username` = 'bar') AND (`User`.`id` = 1 OR `User`.`id` = 4)) LIMIT 1"
,
sqlite
:
"WHERE ((`User`.`username` = 'foo' OR `User`.`username` = 'bar') AND (`User`.`id` = 1 OR `User`.`id` = 4)) LIMIT 1"
,
postgres
:
'WHERE (("User"."username" = \'foo\' OR "User"."username" = \'bar\') AND ("User"."id" = 1 OR "User"."id" = 4)) LIMIT 1'
,
mssql
:
'WHERE (([User].[username] = \'foo\' OR [User].[username] = \'bar\') AND ([User].[id] = 1 OR [User].[id] = 4))'
,
mariadb
:
"WHERE ((`User`.`username` = 'foo' OR `User`.`username` = 'bar') AND (`User`.`id` = 1 OR `User`.`id` = 4)) LIMIT 1"
})[
Support
.
getTestDialect
()];
if
(
!
expectation
)
{
console
.
log
(
sql
);
throw
new
Error
(
'Undefined expectation for '
+
Support
.
getTestDialect
());
}
},
{
logging
:
function
(
sql
)
{
var
expectation
=
({
mysql
:
"WHERE ((`User`.`username` = 'foo' OR `User`.`username` = 'bar') AND (`User`.`id` = 1 OR `User`.`id` = 4)) LIMIT 1"
,
sqlite
:
"WHERE ((`User`.`username` = 'foo' OR `User`.`username` = 'bar') AND (`User`.`id` = 1 OR `User`.`id` = 4)) LIMIT 1"
,
postgres
:
'WHERE (("User"."username" = \'foo\' OR "User"."username" = \'bar\') AND ("User"."id" = 1 OR "User"."id" = 4)) LIMIT 1'
,
mssql
:
'WHERE (([User].[username] = \'foo\' OR [User].[username] = \'bar\') AND ([User].[id] = 1 OR [User].[id] = 4))'
,
mariadb
:
"WHERE ((`User`.`username` = 'foo' OR `User`.`username` = 'bar') AND (`User`.`id` = 1 OR `User`.`id` = 4)) LIMIT 1"
})[
Support
.
getTestDialect
()];
if
(
!
expectation
)
{
console
.
log
(
sql
);
throw
new
Error
(
'Undefined expectation for '
+
Support
.
getTestDialect
());
}
expect
(
sql
).
to
.
contain
(
expectation
);
expect
(
sql
).
to
.
contain
(
expectation
);
}
});
});
it
(
'allows nesting of Sequelize.and'
,
function
()
{
return
this
.
User
.
find
({
where
:
Sequelize
.
or
(
Sequelize
.
and
(
'1=1'
,
'2=2'
),
Sequelize
.
and
(
'3=3'
,
'4=4'
))
}).
on
(
'sql'
,
function
(
sql
)
{
if
(
dialect
===
'mssql'
)
{
expect
(
sql
).
to
.
contain
(
'WHERE ((1=1 AND 2=2) OR (3=3 AND 4=4))'
);
}
else
{
expect
(
sql
).
to
.
contain
(
'WHERE ((1=1 AND 2=2) OR (3=3 AND 4=4)) LIMIT 1'
);
},
{
logging
:
function
(
sql
)
{
if
(
dialect
===
'mssql'
)
{
expect
(
sql
).
to
.
contain
(
'WHERE ((1=1 AND 2=2) OR (3=3 AND 4=4))'
);
}
else
{
expect
(
sql
).
to
.
contain
(
'WHERE ((1=1 AND 2=2) OR (3=3 AND 4=4)) LIMIT 1'
);
}
}
});
});
...
...
@@ -147,21 +159,23 @@ describe(Support.getTestDialectTeaser('Model'), function() {
return
this
.
User
.
find
({
where
:
Sequelize
.
or
(
Sequelize
.
and
({
username
:
{
eq
:
'foo'
}},
{
username
:
{
eq
:
'bar'
}}),
Sequelize
.
and
({
id
:
{
eq
:
1
}},
{
id
:
{
eq
:
4
}}))
}).
on
(
'sql'
,
function
(
sql
)
{
var
expectation
=
({
mysql
:
"WHERE ((`User`.`username` = 'foo' AND `User`.`username` = 'bar') OR (`User`.`id` = 1 AND `User`.`id` = 4)) LIMIT 1"
,
sqlite
:
"WHERE ((`User`.`username` = 'foo' AND `User`.`username` = 'bar') OR (`User`.`id` = 1 AND `User`.`id` = 4)) LIMIT 1"
,
postgres
:
'WHERE (("User"."username" = \'foo\' AND "User"."username" = \'bar\') OR ("User"."id" = 1 AND "User"."id" = 4)) LIMIT 1'
,
mssql
:
'WHERE (([User].[username] = \'foo\' AND [User].[username] = \'bar\') OR ([User].[id] = 1 AND [User].[id] = 4))'
,
mariadb
:
"WHERE ((`User`.`username` = 'foo' AND `User`.`username` = 'bar') OR (`User`.`id` = 1 AND `User`.`id` = 4)) LIMIT 1"
})[
Support
.
getTestDialect
()];
if
(
!
expectation
)
{
console
.
log
(
sql
);
throw
new
Error
(
'Undefined expectation for '
+
Support
.
getTestDialect
());
}
},
{
logging
:
function
(
sql
)
{
var
expectation
=
({
mysql
:
"WHERE ((`User`.`username` = 'foo' AND `User`.`username` = 'bar') OR (`User`.`id` = 1 AND `User`.`id` = 4)) LIMIT 1"
,
sqlite
:
"WHERE ((`User`.`username` = 'foo' AND `User`.`username` = 'bar') OR (`User`.`id` = 1 AND `User`.`id` = 4)) LIMIT 1"
,
postgres
:
'WHERE (("User"."username" = \'foo\' AND "User"."username" = \'bar\') OR ("User"."id" = 1 AND "User"."id" = 4)) LIMIT 1'
,
mssql
:
'WHERE (([User].[username] = \'foo\' AND [User].[username] = \'bar\') OR ([User].[id] = 1 AND [User].[id] = 4))'
,
mariadb
:
"WHERE ((`User`.`username` = 'foo' AND `User`.`username` = 'bar') OR (`User`.`id` = 1 AND `User`.`id` = 4)) LIMIT 1"
})[
Support
.
getTestDialect
()];
expect
(
sql
).
to
.
contain
(
expectation
);
if
(
!
expectation
)
{
console
.
log
(
sql
);
throw
new
Error
(
'Undefined expectation for '
+
Support
.
getTestDialect
());
}
expect
(
sql
).
to
.
contain
(
expectation
);
}
});
});
...
...
@@ -169,8 +183,10 @@ describe(Support.getTestDialectTeaser('Model'), function() {
it
(
'still allows simple arrays lookups'
,
function
()
{
return
this
.
User
.
find
({
where
:
[
'id IN (?) OR id IN (?)'
,
[
1
,
2
],
[
3
,
4
]]
}).
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
).
to
.
contain
(
'id IN (1, 2) OR id IN (3, 4)'
);
},
{
logging
:
function
(
sql
)
{
expect
(
sql
).
to
.
contain
(
'id IN (1, 2) OR id IN (3, 4)'
);
}
});
});
}
...
...
@@ -191,58 +207,60 @@ describe(Support.getTestDialectTeaser('Model'), function() {
Sequelize
.
and
(
42
,
'2=2'
,
[
'1=?'
,
1
],
{
username
:
'foo'
})
)
]
}).
on
(
'sql'
,
function
(
sql
)
{
if
(
dialect
===
'postgres'
)
{
expect
(
sql
).
to
.
contain
(
'WHERE ('
+
[
'"User"."id"=42 AND 2=2 AND 1=1 AND "User"."username"=\'foo\' AND '
,
'('
,
'"User"."id"=42 OR 2=2 OR 1=1 OR "User"."username"=\'foo\' OR '
,
'("User"."id"=42 AND 2=2 AND 1=1 AND "User"."username"=\'foo\') OR '
,
'("User"."id"=42 OR 2=2 OR 1=1 OR "User"."username"=\'foo\')'
,
') AND '
,
'('
,
'"User"."id"=42 AND 2=2 AND 1=1 AND "User"."username"=\'foo\' AND '
,
'("User"."id"=42 OR 2=2 OR 1=1 OR "User"."username"=\'foo\') AND '
,
'("User"."id"=42 AND 2=2 AND 1=1 AND "User"."username"=\'foo\')'
,
')'
].
join
(
''
)
+
')'
);
}
else
if
(
dialect
===
'mssql'
)
{
expect
(
sql
).
to
.
contain
(
'WHERE ('
+
[
'[User].[id]=42 AND 2=2 AND 1=1 AND [User].[username]=\'foo\' AND '
,
'('
,
'[User].[id]=42 OR 2=2 OR 1=1 OR [User].[username]=\'foo\' OR '
,
'([User].[id]=42 AND 2=2 AND 1=1 AND [User].[username]=\'foo\') OR '
,
'([User].[id]=42 OR 2=2 OR 1=1 OR [User].[username]=\'foo\')'
,
') AND '
,
'('
,
'[User].[id]=42 AND 2=2 AND 1=1 AND [User].[username]=\'foo\' AND '
,
'([User].[id]=42 OR 2=2 OR 1=1 OR [User].[username]=\'foo\') AND '
,
'([User].[id]=42 AND 2=2 AND 1=1 AND [User].[username]=\'foo\')'
,
')'
].
join
(
''
)
+
')'
);
}
else
{
expect
(
sql
).
to
.
contain
(
'WHERE ('
+
[
"`User`.`id`=42 AND 2=2 AND 1=1 AND `User`.`username`='foo' AND "
,
'('
,
"`User`.`id`=42 OR 2=2 OR 1=1 OR `User`.`username`='foo' OR "
,
"(`User`.`id`=42 AND 2=2 AND 1=1 AND `User`.`username`='foo') OR "
,
"(`User`.`id`=42 OR 2=2 OR 1=1 OR `User`.`username`='foo')"
,
') AND '
,
'('
,
"`User`.`id`=42 AND 2=2 AND 1=1 AND `User`.`username`='foo' AND "
,
"(`User`.`id`=42 OR 2=2 OR 1=1 OR `User`.`username`='foo') AND "
,
"(`User`.`id`=42 AND 2=2 AND 1=1 AND `User`.`username`='foo')"
,
')'
].
join
(
''
)
+
')'
);
},
{
logging
:
function
(
sql
)
{
if
(
dialect
===
'postgres'
)
{
expect
(
sql
).
to
.
contain
(
'WHERE ('
+
[
'"User"."id"=42 AND 2=2 AND 1=1 AND "User"."username"=\'foo\' AND '
,
'('
,
'"User"."id"=42 OR 2=2 OR 1=1 OR "User"."username"=\'foo\' OR '
,
'("User"."id"=42 AND 2=2 AND 1=1 AND "User"."username"=\'foo\') OR '
,
'("User"."id"=42 OR 2=2 OR 1=1 OR "User"."username"=\'foo\')'
,
') AND '
,
'('
,
'"User"."id"=42 AND 2=2 AND 1=1 AND "User"."username"=\'foo\' AND '
,
'("User"."id"=42 OR 2=2 OR 1=1 OR "User"."username"=\'foo\') AND '
,
'("User"."id"=42 AND 2=2 AND 1=1 AND "User"."username"=\'foo\')'
,
')'
].
join
(
''
)
+
')'
);
}
else
if
(
dialect
===
'mssql'
)
{
expect
(
sql
).
to
.
contain
(
'WHERE ('
+
[
'[User].[id]=42 AND 2=2 AND 1=1 AND [User].[username]=\'foo\' AND '
,
'('
,
'[User].[id]=42 OR 2=2 OR 1=1 OR [User].[username]=\'foo\' OR '
,
'([User].[id]=42 AND 2=2 AND 1=1 AND [User].[username]=\'foo\') OR '
,
'([User].[id]=42 OR 2=2 OR 1=1 OR [User].[username]=\'foo\')'
,
') AND '
,
'('
,
'[User].[id]=42 AND 2=2 AND 1=1 AND [User].[username]=\'foo\' AND '
,
'([User].[id]=42 OR 2=2 OR 1=1 OR [User].[username]=\'foo\') AND '
,
'([User].[id]=42 AND 2=2 AND 1=1 AND [User].[username]=\'foo\')'
,
')'
].
join
(
''
)
+
')'
);
}
else
{
expect
(
sql
).
to
.
contain
(
'WHERE ('
+
[
"`User`.`id`=42 AND 2=2 AND 1=1 AND `User`.`username`='foo' AND "
,
'('
,
"`User`.`id`=42 OR 2=2 OR 1=1 OR `User`.`username`='foo' OR "
,
"(`User`.`id`=42 AND 2=2 AND 1=1 AND `User`.`username`='foo') OR "
,
"(`User`.`id`=42 OR 2=2 OR 1=1 OR `User`.`username`='foo')"
,
') AND '
,
'('
,
"`User`.`id`=42 AND 2=2 AND 1=1 AND `User`.`username`='foo' AND "
,
"(`User`.`id`=42 OR 2=2 OR 1=1 OR `User`.`username`='foo') AND "
,
"(`User`.`id`=42 AND 2=2 AND 1=1 AND `User`.`username`='foo')"
,
')'
].
join
(
''
)
+
')'
);
}
}
});
});
...
...
test/integration/model/attributes/types.test.js
View file @
99ea44d
...
...
@@ -71,18 +71,26 @@ describe(Support.getTestDialectTeaser('Model'), function() {
it
(
'should be ignored in find, findAll and includes'
,
function
()
{
return
Promise
.
all
([
this
.
User
.
find
().
on
(
'sql'
,
this
.
sqlAssert
),
this
.
User
.
findAll
().
on
(
'sql'
,
this
.
sqlAssert
),
this
.
User
.
find
(
null
,
{
logging
:
this
.
sqlAssert
}),
this
.
User
.
findAll
(
null
,
{
logging
:
this
.
sqlAssert
}),
this
.
Task
.
findAll
({
include
:
[
this
.
User
]
}).
on
(
'sql'
,
this
.
sqlAssert
),
},
{
logging
:
this
.
sqlAssert
}),
this
.
Project
.
findAll
({
include
:
[
this
.
User
]
}).
on
(
'sql'
,
this
.
sqlAssert
)
},
{
logging
:
this
.
sqlAssert
})
]);
});
...
...
@@ -132,7 +140,9 @@ describe(Support.getTestDialectTeaser('Model'), function() {
var
self
=
this
;
return
this
.
User
.
bulkCreate
([{
field1
:
'something'
}]).
on
(
'sql'
,
this
.
sqlAssert
).
then
(
function
()
{
}],
{
logging
:
this
.
sqlAssert
}).
then
(
function
()
{
return
self
.
User
.
findAll
();
}).
then
(
function
(
users
)
{
expect
(
users
[
0
].
storage
).
to
.
equal
(
'something'
);
...
...
test/integration/model/create.test.js
View file @
99ea44d
...
...
@@ -675,11 +675,12 @@ describe(Support.getTestDialectTeaser('Model'), function() {
return
this
.
User
.
create
({
intVal
:
this
.
sequelize
.
cast
(
'1'
,
type
)
}).
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
).
to
.
match
(
new
RegExp
(
"CAST\\('1' AS "
+
type
.
toUpperCase
()
+
'\\)'
));
match
=
true
;
})
.
then
(
function
(
user
)
{
},
{
logging
:
function
(
sql
)
{
expect
(
sql
).
to
.
match
(
new
RegExp
(
"CAST\\('1' AS "
+
type
.
toUpperCase
()
+
'\\)'
));
match
=
true
;
}
}).
then
(
function
(
user
)
{
return
self
.
User
.
find
(
user
.
id
).
then
(
function
(
user
)
{
expect
(
user
.
intVal
).
to
.
equal
(
1
);
expect
(
match
).
to
.
equal
(
true
);
...
...
@@ -698,14 +699,15 @@ describe(Support.getTestDialectTeaser('Model'), function() {
return
this
.
User
.
create
({
intVal
:
type
}).
on
(
'sql'
,
function
(
sql
)
{
if
(
Support
.
dialectIsMySQL
())
{
expect
(
sql
).
to
.
contain
(
'CAST(CAST(1-2 AS UNSIGNED) AS SIGNED)'
);
}
else
{
expect
(
sql
).
to
.
contain
(
'CAST(CAST(1-2 AS INTEGER) AS INTEGER)'
);
},
{
logging
:
function
(
sql
)
{
if
(
Support
.
dialectIsMySQL
())
{
expect
(
sql
).
to
.
contain
(
'CAST(CAST(1-2 AS UNSIGNED) AS SIGNED)'
);
}
else
{
expect
(
sql
).
to
.
contain
(
'CAST(CAST(1-2 AS INTEGER) AS INTEGER)'
);
}
match
=
true
;
}
match
=
true
;
}).
then
(
function
(
user
)
{
return
self
.
User
.
find
(
user
.
id
).
then
(
function
(
user
)
{
expect
(
user
.
intVal
).
to
.
equal
(
-
1
);
...
...
@@ -811,11 +813,17 @@ describe(Support.getTestDialectTeaser('Model'), function() {
mystr
:
{
type
:
Sequelize
.
ARRAY
(
Sequelize
.
STRING
)
}
});
var
test
=
false
;
return
User
.
sync
({
force
:
true
}).
then
(
function
()
{
return
User
.
create
({
myvals
:
[],
mystr
:
[]}).
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
.
indexOf
(
'ARRAY[]::INTEGER[]'
)).
to
.
be
.
above
(
-
1
);
expect
(
sql
.
indexOf
(
'ARRAY[]::VARCHAR[]'
)).
to
.
be
.
above
(
-
1
);
return
User
.
create
({
myvals
:
[],
mystr
:
[]},
{
logging
:
function
(
sql
)
{
test
=
true
;
expect
(
sql
.
indexOf
(
'ARRAY[]::INTEGER[]'
)).
to
.
be
.
above
(
-
1
);
expect
(
sql
.
indexOf
(
'ARRAY[]::VARCHAR[]'
)).
to
.
be
.
above
(
-
1
);
}
});
}).
then
(
function
()
{
expect
(
test
).
to
.
be
.
true
;
});
});
...
...
@@ -829,16 +837,22 @@ describe(Support.getTestDialectTeaser('Model'), function() {
myvals
:
{
type
:
Sequelize
.
ARRAY
(
Sequelize
.
INTEGER
)
},
mystr
:
{
type
:
Sequelize
.
ARRAY
(
Sequelize
.
STRING
)
}
});
var
test
=
false
;
return
User
.
sync
({
force
:
true
}).
then
(
function
()
{
return
User
.
create
({
myvals
:
[
1
,
2
,
3
,
4
],
mystr
:
[
'One'
,
'Two'
,
'Three'
,
'Four'
]}).
then
(
function
(
user
)
{
user
.
myvals
=
[];
user
.
mystr
=
[];
return
user
.
save
().
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
.
indexOf
(
'ARRAY[]::INTEGER[]'
)).
to
.
be
.
above
(
-
1
);
expect
(
sql
.
indexOf
(
'ARRAY[]::VARCHAR[]'
)).
to
.
be
.
above
(
-
1
);
return
user
.
save
(
undefined
,
{
logging
:
function
(
sql
)
{
test
=
true
;
expect
(
sql
.
indexOf
(
'ARRAY[]::INTEGER[]'
)).
to
.
be
.
above
(
-
1
);
expect
(
sql
.
indexOf
(
'ARRAY[]::VARCHAR[]'
)).
to
.
be
.
above
(
-
1
);
}
});
});
}).
then
(
function
()
{
expect
(
test
).
to
.
be
.
true
;
});
});
...
...
@@ -986,13 +1000,18 @@ describe(Support.getTestDialectTeaser('Model'), function() {
smth
:
{
type
:
Sequelize
.
STRING
,
allowNull
:
false
}
});
var
test
=
false
;
return
User
.
sync
({
force
:
true
}).
then
(
function
()
{
return
User
.
create
({
name
:
'Fluffy Bunny'
,
smth
:
'else'
})
.
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
).
to
.
exist
;
expect
(
sql
.
toUpperCase
().
indexOf
(
'INSERT'
)).
to
.
be
.
above
(
-
1
);
.
create
({
name
:
'Fluffy Bunny'
,
smth
:
'else'
},
{
logging
:
function
(
sql
)
{
expect
(
sql
).
to
.
exist
;
test
=
true
;
expect
(
sql
.
toUpperCase
().
indexOf
(
'INSERT'
)).
to
.
be
.
above
(
-
1
);
}
});
}).
then
(
function
()
{
expect
(
test
).
to
.
be
.
true
;
});
});
...
...
test/integration/model/find.test.js
View file @
99ea44d
...
...
@@ -117,10 +117,16 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
it
(
'treats questionmarks in an array'
,
function
()
{
var
test
=
false
;
return
this
.
UserPrimary
.
find
({
where
:
[
'specialkey = ?'
,
'awesome'
]
}).
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
).
to
.
contain
(
"WHERE specialkey = 'awesome'"
);
},
{
logging
:
function
(
sql
)
{
test
=
true
;
expect
(
sql
).
to
.
contain
(
"WHERE specialkey = 'awesome'"
);
}
}).
then
(
function
()
{
expect
(
test
).
to
.
be
.
true
;
});
});
...
...
@@ -190,9 +196,15 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
it
(
'allows sql logging'
,
function
()
{
return
this
.
User
.
find
({
where
:
{
username
:
'foo'
}
}).
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
).
to
.
exist
;
expect
(
sql
.
toUpperCase
().
indexOf
(
'SELECT'
)).
to
.
be
.
above
(
-
1
);
var
test
=
false
;
return
this
.
User
.
find
({
where
:
{
username
:
'foo'
}
},
{
logging
:
function
(
sql
)
{
test
=
true
;
expect
(
sql
).
to
.
exist
;
expect
(
sql
.
toUpperCase
().
indexOf
(
'SELECT'
)).
to
.
be
.
above
(
-
1
);
}
}).
then
(
function
()
{
expect
(
test
).
to
.
be
.
true
;
});
});
...
...
@@ -257,16 +269,17 @@ describe(Support.getTestDialectTeaser('Model'), function() {
return
this
.
User
.
bulkCreate
([{
username
:
'jack'
},
{
username
:
'jack'
}]).
then
(
function
()
{
return
self
.
sequelize
.
Promise
.
map
(
permutations
,
function
(
perm
)
{
return
self
.
User
.
find
(
perm
).
then
(
function
(
user
)
{
return
self
.
User
.
find
(
perm
,
{
logging
:
function
(
s
)
{
expect
(
s
.
indexOf
(
0
)).
not
.
to
.
equal
(
-
1
);
count
++
;
}
}).
then
(
function
(
user
)
{
expect
(
user
).
to
.
be
.
null
;
count
++
;
}).
on
(
'sql'
,
function
(
s
)
{
expect
(
s
.
indexOf
(
0
)).
not
.
to
.
equal
(
-
1
);
count
++
;
});
});
}).
then
(
function
()
{
expect
(
count
).
to
.
be
.
equal
(
2
*
permutations
.
length
);
expect
(
count
).
to
.
be
.
equal
(
permutations
.
length
);
});
});
...
...
test/integration/promise.test.js
View file @
99ea44d
...
...
@@ -10,7 +10,7 @@ var chai = require('chai')
chai
.
config
.
includeStack
=
true
;
describe
(
Support
.
getTestDialectTeaser
(
'Promise'
),
function
()
{
describe
.
skip
(
Support
.
getTestDialectTeaser
(
'Promise'
),
function
()
{
beforeEach
(
function
()
{
return
Support
.
prepareTransactionTest
(
this
.
sequelize
).
bind
(
this
).
then
(
function
(
sequelize
)
{
this
.
sequelize
=
sequelize
;
...
...
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