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