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
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
13 deletions
lib/dao-factory.js
lib/utils.js
lib/dao-factory.js
View file @
4e941ab
...
@@ -119,21 +119,24 @@ module.exports = (function() {
...
@@ -119,21 +119,24 @@ module.exports = (function() {
var
start
=
tk
.
time
();
var
start
=
tk
.
time
();
// no options defined?
// no options defined?
// return an emitter which emits null
// return an emitter which emits null
if
([
null
,
undefined
].
indexOf
(
options
)
>
-
1
)
{
if
([
null
,
undefined
].
indexOf
(
options
)
!==
-
1
)
{
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
setTimeout
(
function
()
{
emitter
.
emit
(
'success'
,
null
)
},
10
)
setTimeout
(
function
()
{
emitter
.
emit
(
'success'
,
null
)
},
10
)
}).
run
()
}).
run
()
}
}
var
primaryKeys
=
this
.
primaryKeys
;
// options is not a hash but an id
// options is not a hash but an id
if
(
typeof
options
===
'number'
)
{
if
(
typeof
options
===
'number'
)
{
options
=
{
where
:
options
}
options
=
{
where
:
options
}
}
else
if
(
Utils
.
argsArePrimaryKeys
(
arguments
,
this
.
primaryKeys
))
{
}
else
if
(
!
Utils
.
_
.
isEmpty
(
primaryKeys
)
&&
Utils
.
argsArePrimaryKeys
(
arguments
,
primaryKeys
))
{
var
where
=
{}
var
where
=
{}
,
self
=
this
,
self
=
this
,
keys
=
Utils
.
_
.
keys
(
primaryKeys
)
Utils
.
_
.
each
(
arguments
,
function
(
arg
,
i
)
{
Utils
.
_
.
each
(
arguments
,
function
(
arg
,
i
)
{
var
key
=
Utils
.
_
.
keys
(
self
.
primaryKeys
)
[
i
]
var
key
=
keys
[
i
]
where
[
key
]
=
arg
where
[
key
]
=
arg
})
})
...
@@ -231,7 +234,7 @@ module.exports = (function() {
...
@@ -231,7 +234,7 @@ module.exports = (function() {
DAOFactory
.
prototype
.
__defineGetter__
(
'primaryKeys'
,
function
()
{
DAOFactory
.
prototype
.
__defineGetter__
(
'primaryKeys'
,
function
()
{
var
result
=
{}
var
result
=
{}
Utils
.
_
.
each
(
this
.
attributes
,
function
(
dataTypeString
,
attributeName
)
{
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
result
[
attributeName
]
=
dataTypeString
}
}
})
})
...
...
lib/utils.js
View file @
4e941ab
...
@@ -66,17 +66,18 @@ var Utils = module.exports = {
...
@@ -66,17 +66,18 @@ var Utils = module.exports = {
].
join
(
" "
)
].
join
(
" "
)
},
},
argsArePrimaryKeys
:
function
(
args
,
primaryKeys
)
{
argsArePrimaryKeys
:
function
(
args
,
primaryKeys
)
{
return
false
;
var
result
=
(
args
.
length
==
Utils
.
_
.
keys
(
primaryKeys
).
length
)
var
result
=
(
args
.
length
==
Utils
.
_
.
keys
(
primaryKeys
).
length
)
Utils
.
_
.
each
(
args
,
function
(
arg
)
{
if
(
result
)
{
if
(
result
)
{
Utils
.
_
.
each
(
args
,
function
(
arg
)
{
if
([
'number'
,
'string'
].
indexOf
(
typeof
arg
)
>
-
1
)
if
(
result
)
{
result
=
true
if
([
'number'
,
'string'
].
indexOf
(
typeof
arg
)
!==
-
1
)
else
result
=
true
result
=
(
arg
instanceof
Date
)
else
result
=
(
arg
instanceof
Date
)
}
}
})
})
}
return
result
return
result
},
},
combineTableNames
:
function
(
tableName1
,
tableName2
)
{
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