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 a26450bb
authored
Jan 28, 2013
by
Sascha Depold
Browse files
Options
Browse Files
Download
Plain Diff
merge
2 parents
dc76a89f
3591d078
Show whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
213 additions
and
157 deletions
lib/associations/belongs-to.js
lib/associations/has-many-double-linked.js
lib/associations/has-many.js
lib/associations/has-one.js
lib/dao-factory.js
lib/dao.js
lib/dialects/abstract/query.js
lib/dialects/mysql/connector-manager.js
lib/dialects/mysql/query-generator.js
lib/dialects/mysql/query.js
lib/dialects/postgres/connector-manager.js
lib/dialects/postgres/query-generator.js
lib/dialects/postgres/query.js
lib/dialects/sqlite/connector-manager.js
lib/dialects/sqlite/query-generator.js
lib/dialects/sqlite/query.js
lib/migration.js
lib/migrator.js
lib/query-chainer.js
lib/query-interface.js
lib/sequelize.js
lib/utils.js
lib/associations/belongs-to.js
View file @
a26450b
...
...
@@ -9,7 +9,7 @@ module.exports = (function() {
this
.
options
=
options
this
.
isSelfAssociation
=
(
this
.
source
.
tableName
==
this
.
target
.
tableName
)
if
(
this
.
isSelfAssociation
&&
!
this
.
options
.
foreignKey
&&
!!
this
.
options
.
as
)
{
if
(
this
.
isSelfAssociation
&&
!
this
.
options
.
foreignKey
&&
!!
this
.
options
.
as
)
{
this
.
options
.
foreignKey
=
Utils
.
_
.
underscoredIf
(
Utils
.
singularize
(
this
.
options
.
as
)
+
"Id"
,
this
.
source
.
options
.
underscored
)
}
...
...
lib/associations/has-many-double-linked.js
View file @
a26450b
...
...
@@ -79,7 +79,7 @@ module.exports = (function() {
var
foreignIdentifier
=
self
.
__factory
.
target
.
associations
[
self
.
__factory
.
associationAccessor
].
identifier
var
obsoleteAssociations
=
oldAssociations
.
filter
(
function
(
obj
)
{
return
!
obj
.
equalsOneOf
(
newAssociations
)
})
if
(
obsoleteAssociations
.
length
===
0
)
{
if
(
obsoleteAssociations
.
length
===
0
)
{
return
emitter
.
emit
(
'success'
,
null
)
}
...
...
@@ -95,13 +95,13 @@ module.exports = (function() {
self
.
__factory
.
connectorDAO
.
find
({
where
:
where
})
.
success
(
function
(
connector
)
{
if
(
connector
===
null
)
{
if
(
connector
===
null
)
{
notFoundEmitters
.
push
(
null
)
}
else
{
chainer
.
add
(
connector
.
destroy
())
}
if
((
chainer
.
emitters
.
length
+
notFoundEmitters
.
length
)
===
obsoleteAssociations
.
length
)
{
if
((
chainer
.
emitters
.
length
+
notFoundEmitters
.
length
)
===
obsoleteAssociations
.
length
)
{
// found all obsolete connectors and will delete them now
chainer
.
run
()
...
...
lib/associations/has-many.js
View file @
a26450b
...
...
@@ -41,7 +41,7 @@ module.exports = (function() {
// or is the association on the model itself?
if
((
this
.
isSelfAssociation
&&
this
.
useJunctionTable
)
||
multiAssociation
)
{
// remove the obsolete association identifier from the source
if
(
this
.
isSelfAssociation
)
{
if
(
this
.
isSelfAssociation
)
{
this
.
foreignIdentifier
=
Utils
.
_
.
underscoredIf
((
this
.
options
.
as
||
this
.
target
.
tableName
)
+
'Id'
,
this
.
options
.
underscored
)
}
else
{
this
.
foreignIdentifier
=
this
.
target
.
associations
[
this
.
associationAccessor
].
identifier
...
...
@@ -55,11 +55,11 @@ module.exports = (function() {
this
.
connectorDAO
=
this
.
source
.
daoFactoryManager
.
sequelize
.
define
(
this
.
combinedName
,
combinedTableAttributes
,
this
.
options
)
if
(
!
this
.
isSelfAssociation
)
{
if
(
!
this
.
isSelfAssociation
)
{
this
.
target
.
associations
[
this
.
associationAccessor
].
connectorDAO
=
this
.
connectorDAO
}
if
(
this
.
options
.
syncOnAssociation
)
{
if
(
this
.
options
.
syncOnAssociation
)
{
this
.
connectorDAO
.
sync
()
}
}
else
{
...
...
@@ -127,7 +127,7 @@ module.exports = (function() {
var
self
=
this
obj
[
this
.
accessors
.
set
]
=
function
(
newAssociatedObjects
)
{
if
(
newAssociatedObjects
===
null
)
{
if
(
newAssociatedObjects
===
null
)
{
newAssociatedObjects
=
[]
}
...
...
@@ -155,7 +155,7 @@ module.exports = (function() {
instance
[
self
.
accessors
.
get
]()
.
error
(
function
(
err
){
customEventEmitter
.
emit
(
'error'
,
err
)})
.
success
(
function
(
currentAssociatedObjects
)
{
if
(
!
newAssociatedObject
.
equalsOneOf
(
currentAssociatedObjects
))
if
(
!
newAssociatedObject
.
equalsOneOf
(
currentAssociatedObjects
))
currentAssociatedObjects
.
push
(
newAssociatedObject
)
instance
[
self
.
accessors
.
set
](
currentAssociatedObjects
)
...
...
@@ -173,7 +173,7 @@ module.exports = (function() {
var
newAssociations
=
[]
currentAssociatedObjects
.
forEach
(
function
(
association
)
{
if
(
!
Utils
.
_
.
isEqual
(
oldAssociatedObject
.
identifiers
,
association
.
identifiers
))
if
(
!
Utils
.
_
.
isEqual
(
oldAssociatedObject
.
identifiers
,
association
.
identifiers
))
newAssociations
.
push
(
association
)
})
...
...
lib/associations/has-one.js
View file @
a26450b
...
...
@@ -9,7 +9,7 @@ module.exports = (function() {
this
.
options
=
options
this
.
isSelfAssociation
=
(
this
.
source
.
tableName
==
this
.
target
.
tableName
)
if
(
this
.
isSelfAssociation
&&
!
this
.
options
.
foreignKey
&&
!!
this
.
options
.
as
)
{
if
(
this
.
isSelfAssociation
&&
!
this
.
options
.
foreignKey
&&
!!
this
.
options
.
as
)
{
this
.
options
.
foreignKey
=
Utils
.
_
.
underscoredIf
(
Utils
.
singularize
(
this
.
options
.
as
)
+
"Id"
,
this
.
options
.
underscored
)
}
...
...
@@ -68,12 +68,12 @@ module.exports = (function() {
var
instance
=
this
;
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
instance
[
self
.
accessors
.
get
]().
success
(
function
(
oldObj
)
{
if
(
oldObj
)
{
if
(
oldObj
)
{
oldObj
[
self
.
identifier
]
=
null
oldObj
.
save
()
}
if
(
associatedObject
)
{
if
(
associatedObject
)
{
associatedObject
[
self
.
identifier
]
=
instance
.
id
associatedObject
.
save
()
...
...
lib/dao-factory.js
View file @
a26450b
...
...
@@ -20,7 +20,7 @@ module.exports = (function() {
},
options
||
{})
this
.
name
=
name
if
(
!
this
.
options
.
tableName
)
{
if
(
!
this
.
options
.
tableName
)
{
this
.
tableName
=
this
.
options
.
freezeTableName
?
name
:
Utils
.
pluralize
(
name
)
}
else
{
this
.
tableName
=
this
.
options
.
tableName
...
...
@@ -55,8 +55,11 @@ module.exports = (function() {
this
.
primaryKeys
=
{};
Utils
.
_
.
each
(
this
.
attributes
,
function
(
dataTypeString
,
attributeName
)
{
// If you don't specify a valid data type lets help you debug it
if
(
dataTypeString
===
undefined
)
throw
new
Error
(
"Unrecognized data type for field "
+
attributeName
);
if
((
attributeName
!=
'id'
)
&&
(
dataTypeString
.
indexOf
(
'PRIMARY KEY'
)
!==
-
1
))
{
if
(
dataTypeString
===
undefined
)
{
throw
new
Error
(
"Unrecognized data type for field "
+
attributeName
);
}
if
((
attributeName
!==
'id'
)
&&
(
dataTypeString
.
indexOf
(
'PRIMARY KEY'
)
!==
-
1
))
{
self
.
primaryKeys
[
attributeName
]
=
dataTypeString
}
})
...
...
@@ -86,10 +89,10 @@ module.exports = (function() {
this
.
DAO
.
prototype
.
defaultValues
=
{};
this
.
DAO
.
prototype
.
validators
=
{};
Utils
.
_
.
each
(
this
.
rawAttributes
,
function
(
definition
,
name
)
{
if
(((
definition
===
DataTypes
.
BOOLEAN
)
||
(
definition
.
type
===
DataTypes
.
BOOLEAN
)))
{
if
(((
definition
===
DataTypes
.
BOOLEAN
)
||
(
definition
.
type
===
DataTypes
.
BOOLEAN
)))
{
self
.
DAO
.
prototype
.
booleanValues
.
push
(
name
);
}
if
(
definition
.
hasOwnProperty
(
'defaultValue'
))
{
if
(
definition
.
hasOwnProperty
(
'defaultValue'
))
{
self
.
DAO
.
prototype
.
defaultValues
[
name
]
=
function
()
{
return
Utils
.
toDefaultValue
(
definition
.
defaultValue
);
}
...
...
@@ -119,11 +122,11 @@ module.exports = (function() {
.
on
(
'sql'
,
function
(
sql
)
{
emitter
.
emit
(
'sql'
,
sql
)
})
}
if
(
options
.
force
)
if
(
options
.
force
)
{
self
.
drop
().
success
(
doQuery
).
error
(
function
(
err
)
{
emitter
.
emit
(
'error'
,
err
)
})
else
}
else
{
doQuery
()
}
}).
run
()
}
...
...
@@ -175,7 +178,7 @@ module.exports = (function() {
var
hasJoin
=
false
;
// 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
()
...
...
@@ -184,7 +187,7 @@ module.exports = (function() {
var
primaryKeys
=
this
.
primaryKeys
;
// options is not a hash but an id
if
(
typeof
options
===
'number'
)
{
if
(
typeof
options
===
'number'
)
{
options
=
{
where
:
options
}
}
else
if
(
Utils
.
_
.
size
(
primaryKeys
)
&&
Utils
.
argsArePrimaryKeys
(
arguments
,
primaryKeys
))
{
var
where
=
{}
...
...
@@ -200,7 +203,7 @@ module.exports = (function() {
}
else
if
((
typeof
options
===
'string'
)
&&
(
parseInt
(
options
,
10
).
toString
()
===
options
))
{
var
parsedId
=
parseInt
(
options
,
10
);
if
(
!
Utils
.
_
.
isFinite
(
parsedId
))
{
if
(
!
Utils
.
_
.
isFinite
(
parsedId
))
{
throw
new
Error
(
'Invalid argument to find(). Must be an id or an options object.'
)
}
...
...
@@ -329,13 +332,15 @@ module.exports = (function() {
}
}
if
(
this
.
hasPrimaryKeys
)
defaultAttributes
=
{}
if
(
this
.
hasPrimaryKeys
)
{
defaultAttributes
=
{}
}
if
(
this
.
options
.
timestamps
)
{
if
(
this
.
options
.
timestamps
)
{
defaultAttributes
[
Utils
.
_
.
underscoredIf
(
'createdAt'
,
this
.
options
.
underscored
)]
=
{
type
:
DataTypes
.
DATE
,
allowNull
:
false
}
defaultAttributes
[
Utils
.
_
.
underscoredIf
(
'updatedAt'
,
this
.
options
.
underscored
)]
=
{
type
:
DataTypes
.
DATE
,
allowNull
:
false
}
if
(
this
.
options
.
paranoid
)
if
(
this
.
options
.
paranoid
)
defaultAttributes
[
Utils
.
_
.
underscoredIf
(
'deletedAt'
,
this
.
options
.
underscored
)]
=
{
type
:
DataTypes
.
DATE
}
}
...
...
lib/dao.js
View file @
a26450b
...
...
@@ -14,7 +14,7 @@ module.exports = (function() {
if
(
this
.
hasDefaultValues
)
{
Utils
.
_
.
each
(
this
.
defaultValues
,
function
(
value
,
name
)
{
if
(
typeof
self
[
name
]
===
'undefined'
)
{
if
(
typeof
self
[
name
]
===
'undefined'
)
{
self
.
addAttribute
(
name
,
value
());
}
})
...
...
@@ -78,8 +78,9 @@ module.exports = (function() {
,
result
=
{}
,
self
=
this
if
(
!
this
.
__factory
.
hasPrimaryKeys
)
if
(
!
this
.
__factory
.
hasPrimaryKeys
)
{
primaryKeys
=
[
'id'
]
}
primaryKeys
.
forEach
(
function
(
identifier
)
{
result
[
identifier
]
=
self
[
identifier
]
...
...
@@ -114,17 +115,18 @@ module.exports = (function() {
})
}
if
(
this
.
__options
.
timestamps
&&
this
.
hasOwnProperty
(
updatedAtAttr
))
{
if
(
this
.
__options
.
timestamps
&&
this
.
hasOwnProperty
(
updatedAtAttr
))
{
this
[
updatedAtAttr
]
=
values
[
updatedAtAttr
]
=
new
Date
()
}
if
(
this
.
isNewRecord
)
{
if
(
this
.
isNewRecord
)
{
return
this
.
QueryInterface
.
insert
(
this
,
this
.
__factory
.
tableName
,
values
)
}
else
{
var
identifier
=
this
.
__options
.
hasPrimaryKeys
?
this
.
primaryKeyValues
:
this
.
id
;
if
(
identifier
===
null
&&
this
.
__options
.
whereCollection
!==
null
)
if
(
identifier
===
null
&&
this
.
__options
.
whereCollection
!==
null
)
{
identifier
=
this
.
__options
.
whereCollection
;
}
var
tableName
=
this
.
__factory
.
tableName
,
query
=
this
.
QueryInterface
.
update
(
this
,
tableName
,
values
,
identifier
)
...
...
@@ -225,7 +227,7 @@ module.exports = (function() {
}
DAO
.
prototype
.
destroy
=
function
()
{
if
(
this
.
__options
.
timestamps
&&
this
.
__options
.
paranoid
)
{
if
(
this
.
__options
.
timestamps
&&
this
.
__options
.
paranoid
)
{
var
attr
=
this
.
__options
.
underscored
?
'deleted_at'
:
'deletedAt'
this
[
attr
]
=
new
Date
()
return
this
.
save
()
...
...
@@ -281,11 +283,11 @@ module.exports = (function() {
// a newly created dao has no id
var
defaults
=
this
.
hasPrimaryKeys
?
{}
:
{
id
:
null
}
if
(
this
.
__options
.
timestamps
)
{
if
(
this
.
__options
.
timestamps
)
{
defaults
[
this
.
__options
.
underscored
?
'created_at'
:
'createdAt'
]
=
new
Date
()
defaults
[
this
.
__options
.
underscored
?
'updated_at'
:
'updatedAt'
]
=
new
Date
()
if
(
this
.
__options
.
paranoid
)
{
if
(
this
.
__options
.
paranoid
)
{
defaults
[
this
.
__options
.
underscored
?
'deleted_at'
:
'deletedAt'
]
=
null
}
}
...
...
@@ -294,7 +296,7 @@ module.exports = (function() {
for
(
var
attr
in
defaults
)
{
var
value
=
defaults
[
attr
]
if
(
!
this
.
hasOwnProperty
(
attr
))
{
if
(
!
this
.
hasOwnProperty
(
attr
))
{
this
.
addAttribute
(
attr
,
Utils
.
toDefaultValue
(
value
))
}
}
...
...
lib/dialects/abstract/query.js
View file @
a26450b
...
...
@@ -29,12 +29,12 @@ module.exports = (function() {
* @return {void}
*/
AbstractQuery
.
prototype
.
checkLoggingOption
=
function
()
{
if
(
this
.
options
.
logging
===
true
)
{
if
(
this
.
options
.
logging
===
true
)
{
console
.
log
(
'DEPRECATION WARNING: The logging-option should be either a function or false. Default: console.log'
)
this
.
options
.
logging
=
console
.
log
}
if
(
this
.
options
.
logging
==
console
.
log
)
{
if
(
this
.
options
.
logging
=
==
console
.
log
)
{
// using just console.log will break in node < 0.6
this
.
options
.
logging
=
function
(
s
)
{
console
.
log
(
s
)
}
}
...
...
@@ -253,7 +253,7 @@ module.exports = (function() {
}
// return the first real model instance if options.plain is set (e.g. Model.find)
if
(
this
.
options
.
plain
)
{
if
(
this
.
options
.
plain
)
{
result
=
(
result
.
length
===
0
)
?
null
:
result
[
0
]
}
...
...
lib/dialects/mysql/connector-manager.js
View file @
a26450b
...
...
@@ -133,7 +133,9 @@ module.exports = (function() {
var
isConnecting
=
false
;
ConnectorManager
.
prototype
.
query
=
function
(
sql
,
callee
,
options
)
{
if
(
!
this
.
isConnected
&&
!
this
.
pool
)
this
.
connect
();
if
(
!
this
.
isConnected
&&
!
this
.
pool
)
{
this
.
connect
()
}
if
(
this
.
useQueue
)
{
var
queueItem
=
{
...
...
@@ -160,7 +162,10 @@ module.exports = (function() {
}
});
if
(
!
this
.
pool
)
query
.
run
(
sql
);
if
(
!
this
.
pool
)
{
query
.
run
(
sql
);
}
else
{
this
.
pool
.
acquire
(
function
(
err
,
client
)
{
if
(
err
)
return
query
.
emit
(
'error'
,
err
);
...
...
@@ -197,9 +202,14 @@ module.exports = (function() {
var
disconnect
=
function
(
client
)
{
var
self
=
this
;
if
(
!
this
.
useQueue
)
this
.
client
=
null
;
if
(
!
this
.
useQueue
)
{
this
.
client
=
null
;
}
client
.
end
(
function
()
{
if
(
!
self
.
useQueue
)
return
client
.
destroy
();
if
(
!
self
.
useQueue
)
{
return
client
.
destroy
();
}
var
intervalObj
=
null
var
cleanup
=
function
()
{
...
...
@@ -238,7 +248,7 @@ module.exports = (function() {
var
enqueue
=
function
(
queueItem
,
options
)
{
options
=
options
||
{}
if
(
this
.
activeQueue
.
length
<
this
.
maxConcurrentQueries
)
{
if
(
this
.
activeQueue
.
length
<
this
.
maxConcurrentQueries
)
{
this
.
activeQueue
.
push
(
queueItem
)
if
(
this
.
pool
)
{
var
self
=
this
...
...
@@ -254,9 +264,7 @@ module.exports = (function() {
execQueueItem
.
call
(
self
,
queueItem
)
return
},
undefined
,
options
.
type
)
}
else
{
}
else
{
execQueueItem
.
call
(
this
,
queueItem
)
}
}
else
{
...
...
@@ -275,7 +283,7 @@ module.exports = (function() {
var
transferQueuedItems
=
function
(
count
)
{
for
(
var
i
=
0
;
i
<
count
;
i
++
)
{
var
queueItem
=
this
.
queue
.
shift
();
if
(
queueItem
)
{
if
(
queueItem
)
{
enqueue
.
call
(
this
,
queueItem
)
}
}
...
...
lib/dialects/mysql/query-generator.js
View file @
a26450b
...
...
@@ -35,7 +35,7 @@ module.exports = (function() {
}
,
pkString
=
primaryKeys
.
map
(
function
(
pk
)
{
return
Utils
.
addTicks
(
pk
)
}).
join
(
", "
)
if
(
pkString
.
length
>
0
)
{
if
(
pkString
.
length
>
0
)
{
values
.
attributes
+=
", PRIMARY KEY ("
+
pkString
+
")"
}
...
...
@@ -178,23 +178,23 @@ module.exports = (function() {
options
.
attributes
=
optAttributes
.
join
(
', '
)
}
if
(
options
.
where
)
{
if
(
options
.
where
)
{
options
.
where
=
this
.
getWhereConditions
(
options
.
where
,
tableName
)
query
+=
" WHERE <%= where %>"
}
if
(
options
.
group
)
{
if
(
options
.
group
)
{
options
.
group
=
Utils
.
addTicks
(
options
.
group
)
query
+=
" GROUP BY <%= group %>"
}
if
(
options
.
order
)
{
if
(
options
.
order
)
{
query
+=
" ORDER BY <%= order %>"
}
if
(
options
.
limit
&&
!
(
options
.
include
&&
(
options
.
limit
===
1
)))
{
if
(
options
.
offset
)
{
if
(
options
.
limit
&&
!
(
options
.
include
&&
(
options
.
limit
===
1
)))
{
if
(
options
.
offset
)
{
query
+=
" LIMIT <%= offset %>, <%= limit %>"
}
else
{
query
+=
" LIMIT <%= limit %>"
...
...
@@ -260,28 +260,31 @@ module.exports = (function() {
addIndexQuery
:
function
(
tableName
,
attributes
,
options
)
{
var
transformedAttributes
=
attributes
.
map
(
function
(
attribute
)
{
if
(
typeof
attribute
==
'string'
)
if
(
typeof
attribute
==
=
'string'
)
{
return
attribute
else
{
}
else
{
var
result
=
""
if
(
!
attribute
.
attribute
)
if
(
!
attribute
.
attribute
)
{
throw
new
Error
(
'The following index attribute has no attribute: '
+
util
.
inspect
(
attribute
))
}
result
+=
attribute
.
attribute
if
(
attribute
.
length
)
if
(
attribute
.
length
)
{
result
+=
'('
+
attribute
.
length
+
')'
}
if
(
attribute
.
order
)
if
(
attribute
.
order
)
{
result
+=
' '
+
attribute
.
order
}
return
result
}
})
var
onlyAttributeNames
=
attributes
.
map
(
function
(
attribute
)
{
return
(
typeof
attribute
==
'string'
)
?
attribute
:
attribute
.
attribute
return
(
typeof
attribute
==
=
'string'
)
?
attribute
:
attribute
.
attribute
})
options
=
Utils
.
_
.
extend
({
...
...
@@ -310,8 +313,9 @@ module.exports = (function() {
var
sql
=
"DROP INDEX <%= indexName %> ON <%= tableName %>"
,
indexName
=
indexNameOrAttributes
if
(
typeof
indexName
!=
'string'
)
if
(
typeof
indexName
!==
'string'
)
{
indexName
=
Utils
.
_
.
underscored
(
tableName
+
'_'
+
indexNameOrAttributes
.
join
(
'_'
))
}
return
Utils
.
_
.
template
(
sql
)({
tableName
:
tableName
,
indexName
:
indexName
})
},
...
...
@@ -319,7 +323,7 @@ module.exports = (function() {
getWhereConditions
:
function
(
smth
,
tableName
)
{
var
result
=
null
if
(
Utils
.
isHash
(
smth
))
{
if
(
Utils
.
isHash
(
smth
))
{
smth
=
Utils
.
prependTableNameToHash
(
tableName
,
smth
)
result
=
this
.
hashToWhereConditions
(
smth
)
}
else
if
(
typeof
smth
===
'number'
)
{
...
...
@@ -346,7 +350,7 @@ module.exports = (function() {
if
(
Array
.
isArray
(
value
))
{
// is value an array?
if
(
value
.
length
==
0
)
{
value
=
[
null
]
}
if
(
value
.
length
==
0
)
{
value
=
[
null
]
}
_value
=
"("
+
value
.
map
(
function
(
subValue
)
{
return
Utils
.
escape
(
subValue
);
}).
join
(
','
)
+
")"
...
...
@@ -373,28 +377,28 @@ module.exports = (function() {
for
(
var
name
in
attributes
)
{
var
dataType
=
attributes
[
name
]
if
(
Utils
.
isHash
(
dataType
))
{
if
(
Utils
.
isHash
(
dataType
))
{
var
template
=
"<%= type %>"
,
replacements
=
{
type
:
dataType
.
type
}
if
(
dataType
.
hasOwnProperty
(
'allowNull'
)
&&
(
!
dataType
.
allowNull
))
{
if
(
dataType
.
hasOwnProperty
(
'allowNull'
)
&&
(
!
dataType
.
allowNull
))
{
template
+=
" NOT NULL"
}
if
(
dataType
.
autoIncrement
)
{
if
(
dataType
.
autoIncrement
)
{
template
+=
" auto_increment"
}
if
((
dataType
.
defaultValue
!=
undefined
)
&&
(
dataType
.
defaultValue
!=
DataTypes
.
NOW
))
{
if
((
dataType
.
defaultValue
!=
undefined
)
&&
(
dataType
.
defaultValue
!=
DataTypes
.
NOW
))
{
template
+=
" DEFAULT <%= defaultValue %>"
replacements
.
defaultValue
=
Utils
.
escape
(
dataType
.
defaultValue
)
}
if
(
dataType
.
unique
)
{
if
(
dataType
.
unique
)
{
template
+=
" UNIQUE"
}
if
(
dataType
.
primaryKey
)
{
if
(
dataType
.
primaryKey
)
{
template
+=
" PRIMARY KEY"
}
...
...
lib/dialects/mysql/query.js
View file @
a26450b
...
...
@@ -19,7 +19,7 @@ module.exports = (function() {
Query
.
prototype
.
run
=
function
(
sql
)
{
this
.
sql
=
sql
if
(
this
.
options
.
logging
!==
false
)
{
if
(
this
.
options
.
logging
!==
false
)
{
this
.
options
.
logging
(
'Executing: '
+
this
.
sql
)
}
...
...
lib/dialects/postgres/connector-manager.js
View file @
a26450b
...
...
@@ -26,7 +26,10 @@ module.exports = (function() {
ConnectorManager
.
prototype
.
query
=
function
(
sql
,
callee
,
options
)
{
var
self
=
this
if
(
this
.
client
==
null
)
this
.
connect
()
if
(
this
.
client
==
null
)
{
this
.
connect
()
}
var
query
=
new
Query
(
this
.
client
,
this
.
sequelize
,
callee
,
options
||
{})
self
.
pendingQueries
+=
1
return
query
.
run
(
sql
)
...
...
@@ -48,7 +51,10 @@ module.exports = (function() {
var
self
=
this
// in case database is slow to connect, prevent orphaning the client
if
(
this
.
isConnecting
)
return
if
(
this
.
isConnecting
)
{
return
}
this
.
isConnecting
=
true
this
.
isConnected
=
false
...
...
lib/dialects/postgres/query-generator.js
View file @
a26450b
...
...
@@ -192,8 +192,8 @@ module.exports = (function() {
options
=
options
||
{}
options
.
table
=
table
=
Array
.
isArray
(
tableName
)
?
tableName
.
map
(
function
(
t
){
return
addQuotes
(
t
);}).
join
(
", "
)
:
addQuotes
(
tableName
)
options
.
attributes
=
options
.
attributes
&&
options
.
attributes
.
map
(
function
(
attr
){
if
(
Array
.
isArray
(
attr
)
&&
attr
.
length
==
2
)
{
options
.
attributes
=
options
.
attributes
&&
options
.
attributes
.
map
(
function
(
attr
)
{
if
(
Array
.
isArray
(
attr
)
&&
attr
.
length
=
==
2
)
{
return
[
attr
[
0
],
addQuotes
(
removeQuotes
(
attr
[
1
],
'`'
))].
join
(
' as '
)
}
else
if
(
attr
.
indexOf
(
'`'
)
>=
0
)
{
return
attr
.
replace
(
/`/g
,
'"'
)
...
...
@@ -359,28 +359,31 @@ module.exports = (function() {
addIndexQuery
:
function
(
tableName
,
attributes
,
options
)
{
var
transformedAttributes
=
attributes
.
map
(
function
(
attribute
)
{
if
(
typeof
attribute
==
'string'
)
if
(
typeof
attribute
===
'string'
)
{
return
addQuotes
(
attribute
)
else
{
}
else
{
var
result
=
""
if
(
!
attribute
.
attribute
)
if
(
!
attribute
.
attribute
)
{
throw
new
Error
(
'The following index attribute has no attribute: '
+
util
.
inspect
(
attribute
))
}
result
+=
addQuotes
(
attribute
.
attribute
)
if
(
attribute
.
length
)
if
(
attribute
.
length
)
{
result
+=
'('
+
attribute
.
length
+
')'
}
if
(
attribute
.
order
)
if
(
attribute
.
order
)
{
result
+=
' '
+
attribute
.
order
}
return
result
}
})
var
onlyAttributeNames
=
attributes
.
map
(
function
(
attribute
)
{
return
(
typeof
attribute
==
'string'
)
?
attribute
:
attribute
.
attribute
return
(
typeof
attribute
==
=
"string"
)
?
attribute
:
attribute
.
attribute
})
var
indexTable
=
tableName
.
split
(
'.'
)
...
...
@@ -406,8 +409,9 @@ module.exports = (function() {
var
sql
=
"DROP INDEX IF EXISTS <%= indexName %>"
,
indexName
=
indexNameOrAttributes
if
(
typeof
indexName
!=
'string'
)
if
(
typeof
indexName
!==
"string"
)
{
indexName
=
Utils
.
_
.
underscored
(
tableName
+
'_'
+
indexNameOrAttributes
.
join
(
'_'
))
}
return
Utils
.
_
.
template
(
sql
)({
tableName
:
addQuotes
(
tableName
),
indexName
:
addQuotes
(
indexName
)
})
},
...
...
@@ -415,14 +419,18 @@ module.exports = (function() {
getWhereConditions
:
function
(
smth
)
{
var
result
=
null
if
(
Utils
.
isHash
(
smth
))
if
(
Utils
.
isHash
(
smth
))
{
result
=
QueryGenerator
.
hashToWhereConditions
(
smth
)
else
if
(
typeof
smth
==
'number'
)
}
else
if
(
typeof
smth
===
"number"
)
{
result
=
'\"id\"'
+
"="
+
pgEscape
(
smth
)
else
if
(
typeof
smth
==
"string"
)
}
else
if
(
typeof
smth
===
"string"
)
{
result
=
smth
else
if
(
Array
.
isArray
(
smth
))
}
else
if
(
Array
.
isArray
(
smth
))
{
result
=
Utils
.
format
(
smth
)
}
return
result
},
...
...
@@ -437,15 +445,15 @@ module.exports = (function() {
var
_key
=
key
.
split
(
'.'
).
map
(
function
(
col
){
return
addQuotes
(
col
)}).
join
(
"."
)
,
_value
=
null
if
(
Array
.
isArray
(
value
))
{
if
(
value
.
length
==
0
)
{
value
=
[
null
]
}
if
(
Array
.
isArray
(
value
))
{
if
(
value
.
length
==
0
)
{
value
=
[
null
]
}
_value
=
"("
+
value
.
map
(
function
(
subValue
)
{
return
pgEscape
(
subValue
);
}).
join
(
','
)
+
")"
result
.
push
([
_key
,
_value
].
join
(
" IN "
))
}
else
if
((
value
)
&&
(
typeof
value
==
'object'
))
{
else
if
((
value
)
&&
(
typeof
value
==
=
"object"
))
{
//using as sentinel for join column => value
_value
=
value
.
join
.
split
(
'.'
).
map
(
function
(
col
){
return
addQuotes
(
col
)}).
join
(
"."
)
result
.
push
([
_key
,
_value
].
join
(
"="
))
...
...
@@ -468,17 +476,34 @@ module.exports = (function() {
var
template
=
"<%= type %>"
,
replacements
=
{
type
:
dataType
.
type
}
if
(
dataType
.
type
==
'TINYINT(1)'
)
dataType
.
type
=
'BOOLEAN'
if
(
dataType
.
type
==
'DATETIME'
)
dataType
.
type
=
'TIMESTAMP'
if
(
dataType
.
type
===
"TINYINT(1)"
)
{
dataType
.
type
=
'BOOLEAN'
}
if
(
dataType
.
type
===
"DATETIME"
)
{
dataType
.
type
=
'TIMESTAMP'
}
if
(
dataType
.
hasOwnProperty
(
'allowNull'
)
&&
(
!
dataType
.
allowNull
))
{
template
+=
" NOT NULL"
}
if
(
dataType
.
autoIncrement
)
{
template
+=
" SERIAL"
}
if
(
dataType
.
hasOwnProperty
(
'allowNull'
)
&&
(
!
dataType
.
allowNull
))
template
+=
" NOT NULL"
if
(
dataType
.
autoIncrement
)
template
+=
" SERIAL"
if
(
dataType
.
defaultValue
!=
undefined
)
{
if
(
dataType
.
defaultValue
!==
undefined
)
{
template
+=
" DEFAULT <%= defaultValue %>"
replacements
.
defaultValue
=
pgEscape
(
dataType
.
defaultValue
)
}
if
(
dataType
.
unique
)
template
+=
" UNIQUE"
if
(
dataType
.
primaryKey
)
template
+=
" PRIMARY KEY"
if
(
dataType
.
unique
)
{
template
+=
" UNIQUE"
}
if
(
dataType
.
primaryKey
)
{
template
+=
" PRIMARY KEY"
}
result
[
name
]
=
Utils
.
_
.
template
(
template
)(
replacements
)
}
else
{
...
...
lib/dialects/postgres/query.js
View file @
a26450b
...
...
@@ -19,7 +19,7 @@ module.exports = (function() {
Query
.
prototype
.
run
=
function
(
sql
)
{
this
.
sql
=
sql
if
(
this
.
options
.
logging
!==
false
)
{
if
(
this
.
options
.
logging
!==
false
)
{
this
.
options
.
logging
(
'Executing: '
+
this
.
sql
)
}
...
...
lib/dialects/sqlite/connector-manager.js
View file @
a26450b
...
...
@@ -15,8 +15,3 @@ module.exports = (function() {
return
ConnectorManager
})()
lib/dialects/sqlite/query-generator.js
View file @
a26450b
...
...
@@ -119,7 +119,7 @@ module.exports = (function() {
for
(
var
name
in
attributes
)
{
var
dataType
=
attributes
[
name
]
if
(
Utils
.
isHash
(
dataType
))
{
if
(
Utils
.
isHash
(
dataType
))
{
var
template
=
"<%= type %>"
,
replacements
=
{
type
:
dataType
.
type
}
...
...
@@ -127,7 +127,7 @@ module.exports = (function() {
template
+=
" NOT NULL"
}
if
(
dataType
.
defaultValue
!
=
undefined
)
{
if
(
dataType
.
defaultValue
!=
=
undefined
)
{
template
+=
" DEFAULT <%= defaultValue %>"
replacements
.
defaultValue
=
Utils
.
escape
(
dataType
.
defaultValue
)
}
...
...
lib/dialects/sqlite/query.js
View file @
a26450b
...
...
@@ -25,7 +25,7 @@ module.exports = (function() {
this
.
sql
=
sql
if
(
this
.
options
.
logging
!==
false
)
{
if
(
this
.
options
.
logging
!==
false
)
{
this
.
options
.
logging
(
'Executing: '
+
this
.
sql
)
}
...
...
@@ -83,7 +83,7 @@ module.exports = (function() {
this
.
send
(
'handleInsertQuery'
,
results
,
metaData
)
}
if
(
this
.
sql
.
indexOf
(
'sqlite_master'
)
!=
-
1
)
{
if
(
this
.
sql
.
indexOf
(
'sqlite_master'
)
!=
=
-
1
)
{
result
=
results
.
map
(
function
(
resultSet
)
{
return
resultSet
.
name
})
}
else
if
(
this
.
send
(
'isSelectQuery'
))
{
// we need to convert the timestamps into actual date objects
...
...
lib/migration.js
View file @
a26450b
...
...
@@ -26,7 +26,7 @@ module.exports = (function() {
Migration
.
parseFilename
=
function
(
s
)
{
var
matches
=
s
.
match
(
/^
((\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2}))[
-_
]
.+/
)
if
(
matches
===
null
)
{
if
(
matches
===
null
)
{
throw
new
Error
(
s
+
' is not a valid migration name! Use YYYYMMDDHHmmss-migration-name format.'
)
}
...
...
@@ -72,7 +72,7 @@ module.exports = (function() {
extendMigrationWithQueryInterfaceMethods
.
call
(
self
,
onSuccess
)
func
.
call
(
null
,
self
,
DataTypes
)
if
(
!
Migration
.
migrationHasInterfaceCalls
(
func
))
if
(
!
Migration
.
migrationHasInterfaceCalls
(
func
))
onSuccess
()
}).
run
()
}
...
...
@@ -115,10 +115,11 @@ module.exports = (function() {
// the event will have the same name like the method
self
.
queryInterface
.
on
(
_method
,
function
(
err
)
{
self
.
undoneMethods
--
if
(
err
)
if
(
err
)
{
throw
new
Error
(
err
)
else
}
else
{
(
self
.
undoneMethods
==
0
)
&&
callback
&&
callback
()
}
})
return
self
.
queryInterface
[
_method
].
apply
(
self
.
queryInterface
,
args
)
...
...
lib/migrator.js
View file @
a26450b
...
...
@@ -16,12 +16,12 @@ module.exports = (function() {
logging
:
console
.
log
},
options
||
{})
if
(
this
.
options
.
logging
===
true
)
{
if
(
this
.
options
.
logging
===
true
)
{
console
.
log
(
'DEPRECATION WARNING: The logging-option should be either a function or false. Default: console.log'
)
this
.
options
.
logging
=
console
.
log
}
if
(
this
.
options
.
logging
==
console
.
log
)
{
if
(
this
.
options
.
logging
==
console
.
log
)
{
// using just console.log will break in node < 0.6
this
.
options
.
logging
=
function
(
s
)
{
console
.
log
(
s
)
}
}
...
...
@@ -42,13 +42,13 @@ module.exports = (function() {
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
self
.
getUndoneMigrations
(
function
(
err
,
migrations
)
{
if
(
err
)
{
if
(
err
)
{
emitter
.
emit
(
'error'
,
err
)
}
else
{
var
chainer
=
new
Utils
.
QueryChainer
,
from
=
migrations
[
0
]
if
(
options
.
method
==
'down'
)
{
if
(
options
.
method
=
==
'down'
)
{
from
=
migrations
[
0
]
migrations
.
reverse
()
}
...
...
@@ -56,19 +56,22 @@ module.exports = (function() {
migrations
.
forEach
(
function
(
migration
)
{
chainer
.
add
(
migration
,
'execute'
,
[
options
],
{
before
:
function
(
migration
)
{
if
(
self
.
options
.
logging
!==
false
)
if
(
self
.
options
.
logging
!==
false
)
{
self
.
options
.
logging
(
'Executing migration: '
+
migration
.
filename
)
}
},
after
:
function
(
migration
)
{
if
(
self
.
options
.
logging
!==
false
)
if
(
self
.
options
.
logging
!==
false
)
{
self
.
options
.
logging
(
'Executed migration: '
+
migration
.
filename
)
}
},
success
:
function
(
migration
,
callback
)
{
if
(
options
.
method
==
'down'
)
if
(
options
.
method
===
'down'
)
{
deleteUndoneMigration
.
call
(
self
,
from
,
migration
,
callback
)
else
}
else
{
saveSuccessfulMigration
.
call
(
self
,
from
,
migration
,
callback
)
}
}
})
})
...
...
@@ -105,28 +108,31 @@ module.exports = (function() {
return
parseInt
(
a
.
filename
.
split
(
'-'
)[
0
])
-
parseInt
(
b
.
filename
.
split
(
'-'
)[
0
])
})
if
(
this
.
options
.
from
)
{
if
(
this
.
options
.
from
)
{
filterFrom
(
migrations
,
this
.
options
.
from
,
function
(
err
,
migrations
)
{
if
(
self
.
options
.
to
)
if
(
self
.
options
.
to
)
{
filterTo
(
migrations
,
self
.
options
.
to
,
callback
)
else
}
else
{
callback
&&
callback
(
null
,
migrations
)
}
})
}
else
{
getLastMigrationIdFromDatabase
.
call
(
this
).
success
(
function
(
lastMigrationId
)
{
if
(
lastMigrationId
)
{
if
(
lastMigrationId
)
{
filterFrom
(
migrations
,
lastMigrationId
,
function
(
err
,
migrations
)
{
if
(
self
.
options
.
to
)
if
(
self
.
options
.
to
)
{
filterTo
(
migrations
,
self
.
options
.
to
,
callback
)
else
}
else
{
callback
&&
callback
(
null
,
migrations
)
}
},
{
withoutEqual
:
true
})
}
else
{
if
(
self
.
options
.
to
)
if
(
self
.
options
.
to
)
{
filterTo
(
migrations
,
self
.
options
.
to
,
callback
)
else
}
else
{
callback
&&
callback
(
null
,
migrations
)
}
}
}).
error
(
function
(
err
)
{
callback
&&
callback
(
err
,
null
)
})
...
...
@@ -140,7 +146,7 @@ module.exports = (function() {
var
storedDAO
=
self
.
sequelize
.
daoFactoryManager
.
getDAO
(
'SequelizeMeta'
)
,
SequelizeMeta
=
storedDAO
if
(
!
storedDAO
)
{
if
(
!
storedDAO
)
{
SequelizeMeta
=
self
.
sequelize
.
define
(
'SequelizeMeta'
,
{
from
:
DataTypes
.
STRING
,
to
:
DataTypes
.
STRING
...
...
@@ -150,7 +156,7 @@ module.exports = (function() {
}
// force sync when model has newly created or if syncOptions are passed
if
(
!
storedDAO
||
syncOptions
)
{
if
(
!
storedDAO
||
syncOptions
)
{
SequelizeMeta
.
sync
(
syncOptions
||
{})
.
success
(
function
()
{
emitter
.
emit
(
'success'
,
SequelizeMeta
)
})
...
...
lib/query-chainer.js
View file @
a26450b
...
...
@@ -16,7 +16,7 @@ module.exports = (function() {
emitters
=
emitters
||
[]
emitters
.
forEach
(
function
(
emitter
)
{
if
(
Array
.
isArray
(
emitter
))
{
if
(
Array
.
isArray
(
emitter
))
{
self
.
add
.
apply
(
self
,
emitter
)
}
else
{
self
.
add
(
emitter
)
...
...
@@ -25,7 +25,7 @@ module.exports = (function() {
}
QueryChainer
.
prototype
.
add
=
function
(
emitterOrKlass
,
method
,
params
,
options
)
{
if
(
!!
method
)
{
if
(
!!
method
)
{
this
.
serials
.
push
({
klass
:
emitterOrKlass
,
method
:
method
,
params
:
params
,
options
:
options
})
}
else
{
observeEmitter
.
call
(
this
,
emitterOrKlass
)
...
...
@@ -55,7 +55,7 @@ module.exports = (function() {
var
exec
=
function
()
{
var
serial
=
self
.
serials
.
pop
()
if
(
serial
)
{
if
(
serial
)
{
serial
.
options
=
serial
.
options
||
{}
serial
.
options
.
before
&&
serial
.
options
.
before
(
serial
.
klass
)
...
...
@@ -72,7 +72,7 @@ module.exports = (function() {
exec
()
}
if
(
options
.
skipOnError
&&
(
self
.
fails
.
length
>
0
))
{
if
(
options
.
skipOnError
&&
(
self
.
fails
.
length
>
0
))
{
onError
(
'Skipped due to earlier error!'
)
}
else
{
var
emitter
=
serial
.
klass
[
serial
.
method
].
apply
(
serial
.
klass
,
serial
.
params
)
...
...
@@ -80,7 +80,7 @@ module.exports = (function() {
emitter
.
success
(
function
(
result
)
{
self
.
serialResults
[
serialCopy
.
indexOf
(
serial
)]
=
result
if
(
serial
.
options
.
success
)
{
if
(
serial
.
options
.
success
)
{
serial
.
options
.
success
(
serial
.
klass
,
onSuccess
)
}
else
{
onSuccess
()
...
...
@@ -115,7 +115,7 @@ module.exports = (function() {
finish
.
call
(
self
,
'emitterResults'
)
})
.
on
(
'sql'
,
function
(
sql
)
{
if
(
self
.
eventEmitter
)
{
if
(
self
.
eventEmitter
)
{
self
.
eventEmitter
.
emit
(
'sql'
,
sql
)
}
})
...
...
@@ -124,13 +124,14 @@ module.exports = (function() {
var
finish
=
function
(
resultsName
)
{
this
.
finished
=
true
if
(
this
.
emitters
.
length
>
0
)
{
if
(
this
.
emitters
.
length
>
0
)
{
this
.
finished
=
(
this
.
finishedEmits
==
this
.
emitters
.
length
)
}
else
if
(
this
.
serials
.
length
>
0
)
{
}
else
if
(
this
.
serials
.
length
>
0
)
{
this
.
finished
=
(
this
.
finishedEmits
==
this
.
serials
.
length
)
}
if
(
this
.
finished
&&
this
.
wasRunning
)
{
if
(
this
.
finished
&&
this
.
wasRunning
)
{
var
status
=
(
this
.
fails
.
length
==
0
?
'success'
:
'error'
)
,
result
=
(
this
.
fails
.
length
==
0
?
this
[
resultsName
]
:
this
.
fails
)
...
...
lib/query-interface.js
View file @
a26450b
...
...
@@ -13,10 +13,11 @@ module.exports = (function() {
var
attributeHashes
=
{}
Utils
.
_
.
each
(
attributes
,
function
(
dataTypeOrOptions
,
attributeName
)
{
if
(
Utils
.
_
.
values
(
DataTypes
).
indexOf
(
dataTypeOrOptions
)
>
-
1
)
if
(
Utils
.
_
.
values
(
DataTypes
).
indexOf
(
dataTypeOrOptions
)
>
-
1
)
{
attributeHashes
[
attributeName
]
=
{
type
:
dataTypeOrOptions
}
else
}
else
{
attributeHashes
[
attributeName
]
=
dataTypeOrOptions
}
})
attributes
=
this
.
QueryGenerator
.
attributesToSQL
(
attributeHashes
)
...
...
@@ -98,10 +99,11 @@ module.exports = (function() {
QueryInterface
.
prototype
.
addColumn
=
function
(
tableName
,
attributeName
,
dataTypeOrOptions
)
{
var
attributes
=
{}
if
(
Utils
.
_
.
values
(
DataTypes
).
indexOf
(
dataTypeOrOptions
)
>
-
1
)
if
(
Utils
.
_
.
values
(
DataTypes
).
indexOf
(
dataTypeOrOptions
)
>
-
1
)
{
attributes
[
attributeName
]
=
{
type
:
dataTypeOrOptions
,
allowNull
:
false
}
else
}
else
{
attributes
[
attributeName
]
=
dataTypeOrOptions
}
var
options
=
this
.
QueryGenerator
.
attributesToSQL
(
attributes
)
,
sql
=
this
.
QueryGenerator
.
addColumnQuery
(
tableName
,
options
)
...
...
@@ -117,10 +119,11 @@ module.exports = (function() {
QueryInterface
.
prototype
.
changeColumn
=
function
(
tableName
,
attributeName
,
dataTypeOrOptions
)
{
var
attributes
=
{}
if
(
Utils
.
_
.
values
(
DataTypes
).
indexOf
(
dataTypeOrOptions
)
>
-
1
)
if
(
Utils
.
_
.
values
(
DataTypes
).
indexOf
(
dataTypeOrOptions
)
>
-
1
)
{
attributes
[
attributeName
]
=
{
type
:
dataTypeOrOptions
,
allowNull
:
false
}
else
}
else
{
attributes
[
attributeName
]
=
dataTypeOrOptions
}
var
options
=
this
.
QueryGenerator
.
attributesToSQL
(
attributes
)
,
sql
=
this
.
QueryGenerator
.
changeColumnQuery
(
tableName
,
options
)
...
...
@@ -202,7 +205,7 @@ module.exports = (function() {
QueryInterface
.
prototype
.
rawSelect
=
function
(
tableName
,
options
,
attributeSelector
)
{
var
self
=
this
if
(
attributeSelector
==
undefined
)
{
if
(
attributeSelector
==
undefined
)
{
throw
new
Error
(
'Please pass an attribute selector!'
)
}
...
...
@@ -244,7 +247,7 @@ module.exports = (function() {
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
var
query
=
null
if
(
Array
.
isArray
(
sqlOrQueryParams
))
{
if
(
Array
.
isArray
(
sqlOrQueryParams
))
{
if
(
sqlOrQueryParams
.
length
===
1
)
{
sqlOrQueryParams
.
push
(
null
)
}
...
...
lib/sequelize.js
View file @
a26450b
...
...
@@ -5,7 +5,7 @@ var Utils = require("./utils")
,
Migrator
=
require
(
"./migrator"
)
,
QueryInterface
=
require
(
"./query-interface"
)
if
(
parseFloat
(
process
.
version
.
replace
(
'v'
,
''
))
<
0.6
)
{
if
(
parseFloat
(
process
.
version
.
replace
(
'v'
,
''
))
<
0.6
)
{
console
.
log
(
"DEPRECATION WARNING: Support for Node.JS < v0.6 will be canceled in the next minor release."
)
}
...
...
@@ -43,7 +43,7 @@ module.exports = (function() {
pool
:
{}
},
options
||
{})
if
(
this
.
options
.
logging
===
true
)
{
if
(
this
.
options
.
logging
===
true
)
{
console
.
log
(
'DEPRECATION WARNING: The logging-option should be either a function or false. Default: console.log'
)
this
.
options
.
logging
=
console
.
log
}
...
...
@@ -85,7 +85,7 @@ module.exports = (function() {
}
Sequelize
.
prototype
.
getMigrator
=
function
(
options
,
force
)
{
if
(
force
)
{
if
(
force
)
{
this
.
migrator
=
new
Migrator
(
this
,
options
)
}
else
{
this
.
migrator
=
this
.
migrator
||
new
Migrator
(
this
,
options
)
...
...
@@ -98,10 +98,10 @@ module.exports = (function() {
options
=
options
||
{}
var
globalOptions
=
this
.
options
if
(
globalOptions
.
define
)
{
if
(
globalOptions
.
define
)
{
options
=
Utils
.
_
.
extend
({},
globalOptions
.
define
,
options
)
Utils
.
_
([
'classMethods'
,
'instanceMethods'
]).
each
(
function
(
key
)
{
if
(
globalOptions
.
define
[
key
])
{
if
(
globalOptions
.
define
[
key
])
{
options
[
key
]
=
options
[
key
]
||
{}
Utils
.
_
.
extend
(
options
[
key
],
globalOptions
.
define
[
key
])
}
...
...
@@ -153,7 +153,7 @@ module.exports = (function() {
Sequelize
.
prototype
.
sync
=
function
(
options
)
{
options
=
options
||
{}
if
(
this
.
options
.
sync
)
{
if
(
this
.
options
.
sync
)
{
options
=
Utils
.
_
.
extend
({},
this
.
options
.
sync
,
options
)
}
...
...
lib/utils.js
View file @
a26450b
...
...
@@ -14,7 +14,7 @@ var Utils = module.exports = {
camelizeIf
:
function
(
string
,
condition
)
{
var
result
=
string
if
(
condition
)
{
if
(
condition
)
{
result
=
_
.
camelize
(
string
)
}
...
...
@@ -23,7 +23,7 @@ var Utils = module.exports = {
underscoredIf
:
function
(
string
,
condition
)
{
var
result
=
string
if
(
condition
)
{
if
(
condition
)
{
result
=
_
.
underscored
(
string
)
}
...
...
@@ -66,12 +66,12 @@ var Utils = module.exports = {
var
result
=
(
args
.
length
==
Object
.
keys
(
primaryKeys
).
length
)
if
(
result
)
{
Utils
.
_
.
each
(
args
,
function
(
arg
)
{
if
(
result
)
{
if
([
'number'
,
'string'
].
indexOf
(
typeof
arg
)
!==
-
1
)
if
(
result
)
{
if
([
'number'
,
'string'
].
indexOf
(
typeof
arg
)
!==
-
1
)
{
result
=
true
else
}
else
{
result
=
(
arg
instanceof
Date
)
}
}
})
}
...
...
@@ -116,7 +116,7 @@ var Utils = module.exports = {
removeNullValuesFromHash
:
function
(
hash
,
omitNull
)
{
var
result
=
hash
if
(
omitNull
)
{
if
(
omitNull
)
{
var
_hash
=
{}
Utils
.
_
.
each
(
hash
,
function
(
val
,
key
)
{
...
...
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