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 315bea7b
authored
Jan 31, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into milestones/2.0.0
2 parents
d1e7998b
3a149658
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
9 deletions
lib/dao-factory.js
lib/dialects/mysql/query-generator.js
test/dao-factory/create.test.js
test/query-interface.test.js
lib/dao-factory.js
View file @
315bea7
...
@@ -725,29 +725,31 @@ module.exports = (function() {
...
@@ -725,29 +725,31 @@ module.exports = (function() {
DAOFactory
.
prototype
.
findOrCreate
=
function
(
where
,
defaults
,
options
)
{
DAOFactory
.
prototype
.
findOrCreate
=
function
(
where
,
defaults
,
options
)
{
var
self
=
this
var
self
=
this
,
param
s
=
{}
,
value
s
=
{}
options
=
Utils
.
_
.
extend
({
options
=
Utils
.
_
.
extend
({
transaction
:
null
transaction
:
null
},
options
||
{})
},
options
||
{})
for
(
var
attrname
in
where
)
{
if
(
!
(
where
instanceof
Utils
.
or
)
&&
!
(
where
instanceof
Utils
.
and
)
&&
!
Array
.
isArray
(
where
))
{
params
[
attrname
]
=
where
[
attrname
]
for
(
var
attrname
in
where
)
{
values
[
attrname
]
=
where
[
attrname
]
}
}
}
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
self
.
find
({
self
.
find
({
where
:
params
where
:
where
},
{
},
{
transaction
:
options
.
transaction
transaction
:
options
.
transaction
}).
success
(
function
(
instance
)
{
}).
success
(
function
(
instance
)
{
if
(
instance
===
null
)
{
if
(
instance
===
null
)
{
for
(
var
attrname
in
defaults
)
{
for
(
var
attrname
in
defaults
)
{
param
s
[
attrname
]
=
defaults
[
attrname
]
value
s
[
attrname
]
=
defaults
[
attrname
]
}
}
self
self
.
create
(
param
s
,
options
)
.
create
(
value
s
,
options
)
.
success
(
function
(
instance
)
{
.
success
(
function
(
instance
)
{
emitter
.
emit
(
'success'
,
instance
,
true
)
emitter
.
emit
(
'success'
,
instance
,
true
)
})
})
...
...
lib/dialects/mysql/query-generator.js
View file @
315bea7
...
@@ -243,7 +243,7 @@ module.exports = (function() {
...
@@ -243,7 +243,7 @@ module.exports = (function() {
addIndexQuery
:
function
(
tableName
,
attributes
,
options
)
{
addIndexQuery
:
function
(
tableName
,
attributes
,
options
)
{
var
transformedAttributes
=
attributes
.
map
(
function
(
attribute
)
{
var
transformedAttributes
=
attributes
.
map
(
function
(
attribute
)
{
if
(
typeof
attribute
===
'string'
)
{
if
(
typeof
attribute
===
'string'
)
{
return
attribute
return
this
.
quoteIdentifier
(
attribute
)
}
else
{
}
else
{
var
result
=
""
var
result
=
""
...
@@ -251,7 +251,7 @@ module.exports = (function() {
...
@@ -251,7 +251,7 @@ module.exports = (function() {
throw
new
Error
(
'The following index attribute has no attribute: '
+
util
.
inspect
(
attribute
))
throw
new
Error
(
'The following index attribute has no attribute: '
+
util
.
inspect
(
attribute
))
}
}
result
+=
attribute
.
attribute
result
+=
this
.
quoteIdentifier
(
attribute
.
attribute
)
if
(
attribute
.
length
)
{
if
(
attribute
.
length
)
{
result
+=
'('
+
attribute
.
length
+
')'
result
+=
'('
+
attribute
.
length
+
')'
...
...
test/dao-factory/create.test.js
View file @
315bea7
...
@@ -112,6 +112,20 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
...
@@ -112,6 +112,20 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
done
()
done
()
})
})
})
})
it
(
"supports .or() (only using default values)"
,
function
(
done
)
{
this
.
User
.
findOrCreate
(
Sequelize
.
or
({
username
:
'Fooobzz'
},
{
secretValue
:
'Yolo'
}),
{
username
:
'Fooobzz'
,
secretValue
:
'Yolo'
}
).
done
(
function
(
err
,
user
,
created
)
{
expect
(
err
).
not
.
to
.
be
.
ok
expect
(
user
.
username
).
to
.
equal
(
'Fooobzz'
)
expect
(
user
.
secretValue
).
to
.
equal
(
'Yolo'
)
expect
(
created
).
to
.
be
.
true
done
()
})
})
})
})
describe
(
'create'
,
function
()
{
describe
(
'create'
,
function
()
{
...
...
test/query-interface.test.js
View file @
315bea7
...
@@ -71,7 +71,8 @@ describe(Support.getTestDialectTeaser("QueryInterface"), function () {
...
@@ -71,7 +71,8 @@ describe(Support.getTestDialectTeaser("QueryInterface"), function () {
this
.
queryInterface
.
dropTable
(
'Users'
).
success
(
function
()
{
this
.
queryInterface
.
dropTable
(
'Users'
).
success
(
function
()
{
self
.
queryInterface
.
createTable
(
'Users'
,
{
self
.
queryInterface
.
createTable
(
'Users'
,
{
username
:
DataTypes
.
STRING
,
username
:
DataTypes
.
STRING
,
isAdmin
:
DataTypes
.
BOOLEAN
isAdmin
:
DataTypes
.
BOOLEAN
,
from
:
DataTypes
.
STRING
}).
success
(
function
()
{
}).
success
(
function
()
{
done
()
done
()
})
})
...
@@ -105,6 +106,14 @@ describe(Support.getTestDialectTeaser("QueryInterface"), function () {
...
@@ -105,6 +106,14 @@ describe(Support.getTestDialectTeaser("QueryInterface"), function () {
})
})
})
})
})
})
it
(
'does not fail on reserved keywords'
,
function
(
done
)
{
this
.
queryInterface
.
addIndex
(
'Users'
,
[
'from'
]).
done
(
function
(
err
)
{
expect
(
err
).
to
.
be
.
null
done
()
})
})
})
})
describe
(
'describeTable'
,
function
()
{
describe
(
'describeTable'
,
function
()
{
...
...
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