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