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 4e941ab0
authored
Oct 30, 2012
by
Mick Hansen
Committed by
Jan Aagaard Meier
Oct 31, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor find & argsArePrimaryKeys a bit
1 parent
54163dc3
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
6 deletions
lib/dao-factory.js
lib/utils.js
lib/dao-factory.js
View file @
4e941ab
...
...
@@ -119,21 +119,24 @@ module.exports = (function() {
var
start
=
tk
.
time
();
// no options defined?
// return an emitter which emits null
if
([
null
,
undefined
].
indexOf
(
options
)
>
-
1
)
{
if
([
null
,
undefined
].
indexOf
(
options
)
!==
-
1
)
{
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
setTimeout
(
function
()
{
emitter
.
emit
(
'success'
,
null
)
},
10
)
}).
run
()
}
var
primaryKeys
=
this
.
primaryKeys
;
// options is not a hash but an id
if
(
typeof
options
===
'number'
)
{
options
=
{
where
:
options
}
}
else
if
(
Utils
.
argsArePrimaryKeys
(
arguments
,
this
.
primaryKeys
))
{
}
else
if
(
!
Utils
.
_
.
isEmpty
(
primaryKeys
)
&&
Utils
.
argsArePrimaryKeys
(
arguments
,
primaryKeys
))
{
var
where
=
{}
,
self
=
this
,
keys
=
Utils
.
_
.
keys
(
primaryKeys
)
Utils
.
_
.
each
(
arguments
,
function
(
arg
,
i
)
{
var
key
=
Utils
.
_
.
keys
(
self
.
primaryKeys
)
[
i
]
var
key
=
keys
[
i
]
where
[
key
]
=
arg
})
...
...
@@ -231,7 +234,7 @@ module.exports = (function() {
DAOFactory
.
prototype
.
__defineGetter__
(
'primaryKeys'
,
function
()
{
var
result
=
{}
Utils
.
_
.
each
(
this
.
attributes
,
function
(
dataTypeString
,
attributeName
)
{
if
((
attributeName
!=
'id'
)
&&
(
dataTypeString
.
indexOf
(
'PRIMARY KEY'
)
>
-
1
))
{
if
((
attributeName
!=
'id'
)
&&
(
dataTypeString
.
indexOf
(
'PRIMARY KEY'
)
!==
-
1
))
{
result
[
attributeName
]
=
dataTypeString
}
})
...
...
lib/utils.js
View file @
4e941ab
...
...
@@ -66,17 +66,18 @@ var Utils = module.exports = {
].
join
(
" "
)
},
argsArePrimaryKeys
:
function
(
args
,
primaryKeys
)
{
return
false
;
var
result
=
(
args
.
length
==
Utils
.
_
.
keys
(
primaryKeys
).
length
)
if
(
result
)
{
Utils
.
_
.
each
(
args
,
function
(
arg
)
{
if
(
result
)
{
if
([
'number'
,
'string'
].
indexOf
(
typeof
arg
)
>
-
1
)
if
([
'number'
,
'string'
].
indexOf
(
typeof
arg
)
!==
-
1
)
result
=
true
else
result
=
(
arg
instanceof
Date
)
}
})
}
return
result
},
combineTableNames
:
function
(
tableName1
,
tableName2
)
{
...
...
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