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 775dd7b8
authored
Feb 06, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into milestones/2.0.0
2 parents
9577de6d
d6329d48
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
287 additions
and
126 deletions
bin/sequelize
changelog.md
lib/dao-factory.js
lib/dao.js
lib/dialects/abstract/query-generator.js
lib/dialects/mysql/query-generator.js
lib/dialects/postgres/connector-manager.js
lib/dialects/postgres/query-generator.js
lib/dialects/sqlite/query-generator.js
lib/query-interface.js
lib/sequelize.js
test/assets/migrations/20111117063700-createPerson.cs
test/dao-factory.test.js
test/dao-factory/create.test.js
test/migrator.test.js
test/postgres/dao.test.js
test/postgres/query-generator.test.js
test/sequelize.executable.test.js
test/sequelize.test.js
bin/sequelize
View file @
775dd7b
...
@@ -227,7 +227,7 @@ if (program.migrate || program.undo) {
...
@@ -227,7 +227,7 @@ if (program.migrate || program.undo) {
})
})
}
}
}
else
{
}
else
{
console
.
log
(
'Cannot find "'
+
relativeConfigFile
()
+
'". Have you run "sequelize --init"?'
)
console
.
log
(
'Cannot find "'
+
configuration
.
configFile
+
'". Have you run "sequelize --init"?'
)
process
.
exit
(
1
)
process
.
exit
(
1
)
}
}
}
else
if
(
program
.
init
)
{
}
else
if
(
program
.
init
)
{
...
...
changelog.md
View file @
775dd7b
Notice: All 1.7.x changes are present in 2.0.x aswell
Notice: All 1.7.x changes are present in 2.0.x aswell
# v1.7.0-rc5
# v1.7.0-rc5
(next)
-
sync() now correctly returns with an error when foreign key constraints reference unknown tables
-
sync() now correctly returns with an error when foreign key constraints reference unknown tables
-
sync() no longer fails with foreign key constraints references own table (toposort self-dependency error)
-
sync() no longer fails with foreign key constraints references own table (toposort self-dependency error)
-
makes it possible to specify exactly what timestamp attributes you want to utilize
[
#1334
](
https://github.com/sequelize/sequelize/pull/1334
)
# v1.7.0-rc4
# v1.7.0-rc4
-
fixes issue with postgres sync and enums
[
#1020
](
https://github.com/sequelize/sequelize/issues/1020
)
-
fixes issue with postgres sync and enums
[
#1020
](
https://github.com/sequelize/sequelize/issues/1020
)
...
...
lib/dao-factory.js
View file @
775dd7b
...
@@ -14,7 +14,6 @@ module.exports = (function() {
...
@@ -14,7 +14,6 @@ module.exports = (function() {
createdAt
:
'createdAt'
,
createdAt
:
'createdAt'
,
updatedAt
:
'updatedAt'
,
updatedAt
:
'updatedAt'
,
deletedAt
:
'deletedAt'
,
deletedAt
:
'deletedAt'
,
touchedAt
:
'touchedAt'
,
instanceMethods
:
{},
instanceMethods
:
{},
classMethods
:
{},
classMethods
:
{},
validate
:
{},
validate
:
{},
...
@@ -83,11 +82,11 @@ module.exports = (function() {
...
@@ -83,11 +82,11 @@ module.exports = (function() {
// inject the node-sql methods to the dao factory in order to
// inject the node-sql methods to the dao factory in order to
// receive the syntax sugar ...
// receive the syntax sugar ...
;(
function
()
{
;(
function
()
{
var
instance
=
sql
.
define
({
name
:
"dummy"
,
columns
:
[]
})
var
instance
=
sql
.
define
({
name
:
"dummy"
,
columns
:
[]
})
for
(
var
methodName
in
instance
)
{
for
(
var
methodName
in
instance
)
{
;(
function
(
methodName
)
{
;(
function
(
methodName
)
{
DAOFactory
.
prototype
[
methodName
]
=
function
()
{
DAOFactory
.
prototype
[
methodName
]
=
function
()
{
var
dataset
=
this
.
dataset
()
var
dataset
=
this
.
dataset
()
,
result
=
dataset
[
methodName
].
apply
(
dataset
,
arguments
)
,
result
=
dataset
[
methodName
].
apply
(
dataset
,
arguments
)
...
@@ -122,7 +121,7 @@ module.exports = (function() {
...
@@ -122,7 +121,7 @@ module.exports = (function() {
self
.
options
.
uniqueKeys
=
{}
self
.
options
.
uniqueKeys
=
{}
Utils
.
_
.
each
(
this
.
rawAttributes
,
function
(
columnValues
,
columnName
)
{
Utils
.
_
.
each
(
this
.
rawAttributes
,
function
(
columnValues
,
columnName
)
{
if
(
columnValues
.
hasOwnProperty
(
'unique'
)
&&
columnValues
.
unique
!==
true
)
{
if
(
columnValues
.
hasOwnProperty
(
'unique'
)
&&
columnValues
.
unique
!==
true
&&
columnValues
.
unique
!==
false
)
{
var
idxName
=
columnValues
.
unique
var
idxName
=
columnValues
.
unique
if
(
typeof
columnValues
.
unique
===
"object"
)
{
if
(
typeof
columnValues
.
unique
===
"object"
)
{
idxName
=
columnValues
.
unique
.
name
idxName
=
columnValues
.
unique
.
name
...
@@ -148,10 +147,6 @@ module.exports = (function() {
...
@@ -148,10 +147,6 @@ module.exports = (function() {
Utils
.
injectScope
.
call
(
this
,
this
.
options
.
defaultScope
)
Utils
.
injectScope
.
call
(
this
,
this
.
options
.
defaultScope
)
}
}
addDefaultAttributes
.
call
(
this
)
addOptionalClassMethods
.
call
(
this
)
findAutoIncrementField
.
call
(
this
)
// DAO prototype
// DAO prototype
// WTF ... ?
// WTF ... ?
this
.
DAO
=
function
()
{
this
.
DAO
=
function
()
{
...
@@ -159,22 +154,20 @@ module.exports = (function() {
...
@@ -159,22 +154,20 @@ module.exports = (function() {
}
}
Util
.
inherits
(
this
.
DAO
,
DAO
);
Util
.
inherits
(
this
.
DAO
,
DAO
);
this
.
DAO
.
prototype
.
rawAttributes
=
this
.
rawAttributes
;
this
.
_timestampAttributes
=
{}
this
.
DAO
.
prototype
.
_hasPrimaryKeys
=
this
.
options
.
hasPrimaryKeys
this
.
DAO
.
prototype
.
_isPrimaryKey
=
Utils
.
_
.
memoize
(
function
(
key
)
{
return
self
.
primaryKeyAttributes
.
indexOf
(
key
)
!==
-
1
&&
key
!==
'id'
})
if
(
this
.
options
.
timestamps
)
{
if
(
this
.
options
.
timestamps
)
{
this
.
DAO
.
prototype
.
_timestampAttributes
=
{
if
(
this
.
options
.
createdAt
)
{
createdAt
:
Utils
.
_
.
underscoredIf
(
this
.
options
.
createdAt
,
this
.
options
.
underscored
),
this
.
_timestampAttributes
.
createdAt
=
Utils
.
_
.
underscoredIf
(
this
.
options
.
createdAt
,
this
.
options
.
underscored
)
updatedAt
:
Utils
.
_
.
underscoredIf
(
this
.
options
.
updatedAt
,
this
.
options
.
underscored
),
}
deletedAt
:
Utils
.
_
.
underscoredIf
(
this
.
options
.
deletedAt
,
this
.
options
.
underscored
)
if
(
this
.
options
.
updatedAt
)
{
this
.
_timestampAttributes
.
updatedAt
=
Utils
.
_
.
underscoredIf
(
this
.
options
.
updatedAt
,
this
.
options
.
underscored
)
}
if
(
this
.
options
.
paranoid
&&
this
.
options
.
deletedAt
)
{
this
.
_timestampAttributes
.
deletedAt
=
Utils
.
_
.
underscoredIf
(
this
.
options
.
deletedAt
,
this
.
options
.
underscored
)
}
}
this
.
DAO
.
prototype
.
_readOnlyAttributes
=
Object
.
keys
(
this
.
DAO
.
prototype
.
_timestampAttributes
)
this
.
DAO
.
prototype
.
_readOnlyAttributes
=
Object
.
keys
(
this
.
_timestampAttributes
)
}
}
this
.
DAO
.
prototype
.
_hasReadOnlyAttributes
=
this
.
DAO
.
prototype
.
_readOnlyAttributes
&&
this
.
DAO
.
prototype
.
_readOnlyAttributes
.
length
this
.
DAO
.
prototype
.
_hasReadOnlyAttributes
=
this
.
DAO
.
prototype
.
_readOnlyAttributes
&&
this
.
DAO
.
prototype
.
_readOnlyAttributes
.
length
...
@@ -182,6 +175,17 @@ module.exports = (function() {
...
@@ -182,6 +175,17 @@ module.exports = (function() {
return
self
.
DAO
.
prototype
.
_hasReadOnlyAttributes
&&
self
.
DAO
.
prototype
.
_readOnlyAttributes
.
indexOf
(
key
)
!==
-
1
return
self
.
DAO
.
prototype
.
_hasReadOnlyAttributes
&&
self
.
DAO
.
prototype
.
_readOnlyAttributes
.
indexOf
(
key
)
!==
-
1
})
})
addDefaultAttributes
.
call
(
this
)
addOptionalClassMethods
.
call
(
this
)
findAutoIncrementField
.
call
(
this
)
this
.
DAO
.
prototype
.
rawAttributes
=
this
.
rawAttributes
;
this
.
DAO
.
prototype
.
_hasPrimaryKeys
=
this
.
options
.
hasPrimaryKeys
this
.
DAO
.
prototype
.
_isPrimaryKey
=
Utils
.
_
.
memoize
(
function
(
key
)
{
return
self
.
primaryKeyAttributes
.
indexOf
(
key
)
!==
-
1
&&
key
!==
'id'
})
if
(
this
.
options
.
instanceMethods
)
{
if
(
this
.
options
.
instanceMethods
)
{
Utils
.
_
.
each
(
this
.
options
.
instanceMethods
,
function
(
fct
,
name
)
{
Utils
.
_
.
each
(
this
.
options
.
instanceMethods
,
function
(
fct
,
name
)
{
self
.
DAO
.
prototype
[
name
]
=
fct
self
.
DAO
.
prototype
[
name
]
=
fct
...
@@ -453,7 +457,7 @@ module.exports = (function() {
...
@@ -453,7 +457,7 @@ module.exports = (function() {
options
=
paranoidClause
.
call
(
this
,
options
)
options
=
paranoidClause
.
call
(
this
,
options
)
return
this
.
QueryInterface
.
select
(
this
,
this
.
tableName
,
options
,
Utils
.
_
.
defaults
({
return
this
.
QueryInterface
.
select
(
this
,
this
.
getTableName
()
,
options
,
Utils
.
_
.
defaults
({
type
:
QueryTypes
.
SELECT
,
type
:
QueryTypes
.
SELECT
,
hasJoin
:
hasJoin
hasJoin
:
hasJoin
},
queryOptions
,
{
transaction
:
(
options
||
{}).
transaction
}))
},
queryOptions
,
{
transaction
:
(
options
||
{}).
transaction
}))
...
@@ -800,8 +804,8 @@ module.exports = (function() {
...
@@ -800,8 +804,8 @@ module.exports = (function() {
}
}
var
self
=
this
var
self
=
this
,
updatedAtAttr
=
Utils
.
_
.
underscoredIf
(
self
.
options
.
updatedAt
,
self
.
options
.
underscored
)
,
updatedAtAttr
=
this
.
_timestampAttributes
.
updatedAt
,
createdAtAttr
=
Utils
.
_
.
underscoredIf
(
self
.
options
.
createdAt
,
self
.
options
.
underscored
)
,
createdAtAttr
=
this
.
_timestampAttributes
.
createdAt
,
errors
=
[]
,
errors
=
[]
,
daos
=
records
.
map
(
function
(
v
)
{
return
self
.
build
(
v
)
})
,
daos
=
records
.
map
(
function
(
v
)
{
return
self
.
build
(
v
)
})
...
@@ -870,14 +874,12 @@ module.exports = (function() {
...
@@ -870,14 +874,12 @@ module.exports = (function() {
values
[
field
]
=
dao
.
dataValues
[
field
]
values
[
field
]
=
dao
.
dataValues
[
field
]
})
})
if
(
self
.
options
.
timestamps
)
{
if
(
createdAtAttr
&&
!
values
[
createdAtAttr
])
{
if
(
!
values
[
createdAtAttr
])
{
values
[
createdAtAttr
]
=
Utils
.
now
(
self
.
daoFactoryManager
.
sequelize
.
options
.
dialect
)
values
[
createdAtAttr
]
=
Utils
.
now
(
self
.
daoFactoryManager
.
sequelize
.
options
.
dialect
)
}
}
if
(
!
values
[
updatedAtAttr
])
{
if
(
updatedAtAttr
&&
!
values
[
updatedAtAttr
])
{
values
[
updatedAtAttr
]
=
Utils
.
now
(
self
.
daoFactoryManager
.
sequelize
.
options
.
dialect
)
values
[
updatedAtAttr
]
=
Utils
.
now
(
self
.
daoFactoryManager
.
sequelize
.
options
.
dialect
)
}
}
}
records
.
push
(
values
)
records
.
push
(
values
)
...
@@ -970,10 +972,9 @@ module.exports = (function() {
...
@@ -970,10 +972,9 @@ module.exports = (function() {
where
=
newWhere
||
where
where
=
newWhere
||
where
if
(
self
.
options
.
timestamps
&&
self
.
options
.
paranoid
&&
options
.
force
===
false
)
{
if
(
self
.
_timestampAttributes
.
deletedAt
&&
options
.
force
===
false
)
{
var
attr
=
Utils
.
_
.
underscoredIf
(
self
.
options
.
deletedAt
,
self
.
options
.
underscored
)
var
attrValueHash
=
{}
var
attrValueHash
=
{}
attrValueHash
[
attr
]
=
Utils
.
now
()
attrValueHash
[
self
.
_timestampAttributes
.
deletedAt
]
=
Utils
.
now
()
query
=
'bulkUpdate'
query
=
'bulkUpdate'
args
=
[
self
.
tableName
,
attrValueHash
,
where
]
args
=
[
self
.
tableName
,
attrValueHash
,
where
]
}
else
{
}
else
{
...
@@ -1082,9 +1083,8 @@ module.exports = (function() {
...
@@ -1082,9 +1083,8 @@ module.exports = (function() {
options
.
hooks
=
options
.
hooks
===
undefined
?
false
:
Boolean
(
options
.
hooks
)
options
.
hooks
=
options
.
hooks
===
undefined
?
false
:
Boolean
(
options
.
hooks
)
options
.
type
=
QueryTypes
.
BULKUPDATE
options
.
type
=
QueryTypes
.
BULKUPDATE
if
(
self
.
options
.
timestamps
)
{
if
(
self
.
_timestampAttributes
.
updatedAt
)
{
var
attr
=
Utils
.
_
.
underscoredIf
(
self
.
options
.
updatedAt
,
self
.
options
.
underscored
)
attrValueHash
[
self
.
_timestampAttributes
.
updatedAt
]
=
Utils
.
now
()
attrValueHash
[
attr
]
=
Utils
.
now
()
}
}
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
...
@@ -1235,7 +1235,7 @@ module.exports = (function() {
...
@@ -1235,7 +1235,7 @@ module.exports = (function() {
options
=
options
||
{}
options
=
options
||
{}
options
.
where
=
options
.
where
||
{}
options
.
where
=
options
.
where
||
{}
var
deletedAtCol
=
Utils
.
_
.
underscoredIf
(
this
.
options
.
deletedAt
,
this
.
options
.
underscored
)
var
deletedAtCol
=
this
.
_timestampAttributes
.
deletedAt
,
quoteIdentifiedDeletedAtCol
=
this
.
QueryInterface
.
quoteIdentifier
(
deletedAtCol
)
,
quoteIdentifiedDeletedAtCol
=
this
.
QueryInterface
.
quoteIdentifier
(
deletedAtCol
)
// Don't overwrite our explicit deletedAt search value if we provide one
// Don't overwrite our explicit deletedAt search value if we provide one
...
@@ -1272,7 +1272,6 @@ module.exports = (function() {
...
@@ -1272,7 +1272,6 @@ module.exports = (function() {
var
addDefaultAttributes
=
function
()
{
var
addDefaultAttributes
=
function
()
{
var
self
=
this
var
self
=
this
,
head
=
{}
,
tail
=
{}
,
tail
=
{}
,
head
=
{
,
head
=
{
id
:
{
id
:
{
...
@@ -1288,12 +1287,14 @@ module.exports = (function() {
...
@@ -1288,12 +1287,14 @@ module.exports = (function() {
head
=
{}
head
=
{}
}
}
if
(
this
.
options
.
timestamps
)
{
if
(
this
.
_timestampAttributes
.
createdAt
)
{
tail
[
Utils
.
_
.
underscoredIf
(
this
.
options
.
createdAt
,
this
.
options
.
underscored
)]
=
{
type
:
DataTypes
.
DATE
,
allowNull
:
false
}
tail
[
this
.
_timestampAttributes
.
createdAt
]
=
{
type
:
DataTypes
.
DATE
,
allowNull
:
false
}
tail
[
Utils
.
_
.
underscoredIf
(
this
.
options
.
updatedAt
,
this
.
options
.
underscored
)]
=
{
type
:
DataTypes
.
DATE
,
allowNull
:
false
}
}
if
(
this
.
_timestampAttributes
.
updatedAt
)
{
if
(
this
.
options
.
paranoid
)
tail
[
this
.
_timestampAttributes
.
updatedAt
]
=
{
type
:
DataTypes
.
DATE
,
allowNull
:
false
}
tail
[
Utils
.
_
.
underscoredIf
(
this
.
options
.
deletedAt
,
this
.
options
.
underscored
)]
=
{
type
:
DataTypes
.
DATE
}
}
if
(
this
.
_timestampAttributes
.
deletedAt
)
{
tail
[
this
.
_timestampAttributes
.
deletedAt
]
=
{
type
:
DataTypes
.
DATE
}
}
}
var
existingAttributes
=
Utils
.
_
.
clone
(
self
.
rawAttributes
)
var
existingAttributes
=
Utils
.
_
.
clone
(
self
.
rawAttributes
)
...
...
lib/dao.js
View file @
775dd7b
...
@@ -17,7 +17,7 @@ module.exports = (function() {
...
@@ -17,7 +17,7 @@ module.exports = (function() {
this
.
__eagerlyLoadedAssociations
=
[]
this
.
__eagerlyLoadedAssociations
=
[]
this
.
isNewRecord
=
options
.
isNewRecord
this
.
isNewRecord
=
options
.
isNewRecord
initValues
.
call
(
this
,
values
,
options
)
initValues
.
call
(
this
,
values
,
options
)
;
}
}
Utils
.
_
.
extend
(
DAO
.
prototype
,
Mixin
.
prototype
)
Utils
.
_
.
extend
(
DAO
.
prototype
,
Mixin
.
prototype
)
...
@@ -32,10 +32,7 @@ module.exports = (function() {
...
@@ -32,10 +32,7 @@ module.exports = (function() {
Object
.
defineProperty
(
DAO
.
prototype
,
'isDeleted'
,
{
Object
.
defineProperty
(
DAO
.
prototype
,
'isDeleted'
,
{
get
:
function
()
{
get
:
function
()
{
var
result
=
this
.
__options
.
timestamps
&&
this
.
__options
.
paranoid
return
this
.
Model
.
_timestampAttributes
.
deletedAt
&&
this
.
dataValues
[
this
.
Model
.
_timestampAttributes
.
deletedAt
]
!==
null
result
=
result
&&
this
.
dataValues
[
Utils
.
_
.
underscoredIf
(
this
.
__options
.
deletedAt
,
this
.
__options
.
underscored
)]
!==
null
return
result
}
}
})
})
...
@@ -191,7 +188,9 @@ module.exports = (function() {
...
@@ -191,7 +188,9 @@ module.exports = (function() {
value
=
new
Date
(
value
)
value
=
new
Date
(
value
)
}
}
if
(
originalValue
!==
value
)
this
.
_previousDataValues
[
key
]
=
originalValue
if
(
originalValue
!==
value
)
{
this
.
_previousDataValues
[
key
]
=
originalValue
}
this
.
dataValues
[
key
]
=
value
this
.
dataValues
[
key
]
=
value
}
}
}
}
...
@@ -237,14 +236,14 @@ module.exports = (function() {
...
@@ -237,14 +236,14 @@ module.exports = (function() {
value
.
forEach
(
function
(
data
)
{
value
.
forEach
(
function
(
data
)
{
var
daoInstance
=
include
.
daoFactory
.
build
(
data
,
{
var
daoInstance
=
include
.
daoFactory
.
build
(
data
,
{
isNewRecord
:
false
,
isNewRecord
:
false
,
isDirty
:
false
,
isDirty
:
false
,
include
:
include
.
include
,
include
:
include
.
include
,
includeNames
:
include
.
includeNames
,
includeNames
:
include
.
includeNames
,
includeMap
:
include
.
includeMap
,
includeMap
:
include
.
includeMap
,
includeValidated
:
true
,
includeValidated
:
true
,
raw
:
options
.
raw
raw
:
options
.
raw
})
})
,
isEmpty
=
!
Utils
.
firstValueOfHash
(
daoInstance
.
identifiers
)
,
isEmpty
=
!
Utils
.
firstValueOfHash
(
daoInstance
.
identifiers
)
if
(
association
.
isSingleAssociation
)
{
if
(
association
.
isSingleAssociation
)
{
...
@@ -287,18 +286,16 @@ module.exports = (function() {
...
@@ -287,18 +286,16 @@ module.exports = (function() {
var
self
=
this
var
self
=
this
,
values
=
{}
,
values
=
{}
,
updatedAtAttr
=
Utils
.
_
.
underscoredIf
(
this
.
__options
.
updatedAt
,
this
.
__options
.
underscored
)
,
updatedAtAttr
=
this
.
Model
.
_timestampAttributes
.
updatedAt
,
createdAtAttr
=
Utils
.
_
.
underscoredIf
(
this
.
__options
.
createdAt
,
this
.
__options
.
underscored
)
,
createdAtAttr
=
this
.
Model
.
_timestampAttributes
.
createdAt
if
(
options
.
fields
)
{
if
(
options
.
fields
)
{
if
(
self
.
__options
.
timestamps
)
{
if
(
updatedAtAttr
&&
options
.
fields
.
indexOf
(
updatedAtAttr
)
===
-
1
)
{
if
(
options
.
fields
.
indexOf
(
updatedAtAttr
)
===
-
1
)
{
options
.
fields
.
push
(
updatedAtAttr
)
options
.
fields
.
push
(
updatedAtAttr
)
}
}
if
(
options
.
fields
.
indexOf
(
createdAtAttr
)
===
-
1
&&
this
.
isNewRecord
===
true
)
{
if
(
createdAtAttr
&&
options
.
fields
.
indexOf
(
createdAtAttr
)
===
-
1
&&
this
.
isNewRecord
===
true
)
{
options
.
fields
.
push
(
createdAtAttr
)
options
.
fields
.
push
(
createdAtAttr
)
}
}
}
}
}
...
@@ -340,7 +337,7 @@ module.exports = (function() {
...
@@ -340,7 +337,7 @@ module.exports = (function() {
}
}
}
}
if
(
self
.
__options
.
timestamps
)
{
if
(
updatedAtAttr
)
{
values
[
updatedAtAttr
]
=
(
values
[
updatedAtAttr
]
=
(
(
(
self
.
isNewRecord
self
.
isNewRecord
...
@@ -348,18 +345,18 @@ module.exports = (function() {
...
@@ -348,18 +345,18 @@ module.exports = (function() {
&&
!!
self
.
daoFactory
.
rawAttributes
[
updatedAtAttr
].
defaultValue
&&
!!
self
.
daoFactory
.
rawAttributes
[
updatedAtAttr
].
defaultValue
)
)
?
self
.
daoFactory
.
rawAttributes
[
updatedAtAttr
].
defaultValue
?
self
.
daoFactory
.
rawAttributes
[
updatedAtAttr
].
defaultValue
:
Utils
.
now
(
self
.
sequelize
.
options
.
dialect
))
:
Utils
.
now
(
self
.
sequelize
.
options
.
dialect
))
if
(
self
.
isNewRecord
&&
!
values
[
createdAtAttr
])
{
values
[
createdAtAttr
]
=
(
(
!!
self
.
daoFactory
.
rawAttributes
[
createdAtAttr
]
&&
!!
self
.
daoFactory
.
rawAttributes
[
createdAtAttr
].
defaultValue
)
?
self
.
daoFactory
.
rawAttributes
[
createdAtAttr
].
defaultValue
:
values
[
updatedAtAttr
])
}
}
}
if
(
self
.
isNewRecord
&&
createdAtAttr
&&
!
values
[
createdAtAttr
])
{
values
[
createdAtAttr
]
=
(
(
!!
self
.
daoFactory
.
rawAttributes
[
createdAtAttr
]
&&
!!
self
.
daoFactory
.
rawAttributes
[
createdAtAttr
].
defaultValue
)
?
self
.
daoFactory
.
rawAttributes
[
createdAtAttr
].
defaultValue
:
values
[
updatedAtAttr
])
}
var
query
=
null
var
query
=
null
,
args
=
[]
,
args
=
[]
...
@@ -514,9 +511,8 @@ module.exports = (function() {
...
@@ -514,9 +511,8 @@ module.exports = (function() {
return
emitter
.
emit
(
'error'
,
err
)
return
emitter
.
emit
(
'error'
,
err
)
}
}
if
(
self
.
__options
.
timestamps
&&
self
.
__options
.
paranoid
&&
options
.
force
===
false
)
{
if
(
self
.
Model
.
_timestampAttributes
.
deletedAt
&&
options
.
force
===
false
)
{
var
attr
=
Utils
.
_
.
underscoredIf
(
self
.
__options
.
deletedAt
,
self
.
__options
.
underscored
)
self
.
dataValues
[
self
.
Model
.
_timestampAttributes
.
deletedAt
]
=
new
Date
()
self
.
dataValues
[
attr
]
=
new
Date
()
query
=
self
.
save
(
options
)
query
=
self
.
save
(
options
)
}
else
{
}
else
{
var
identifier
=
self
.
__options
.
hasPrimaryKeys
?
self
.
primaryKeyValues
:
{
id
:
self
.
id
};
var
identifier
=
self
.
__options
.
hasPrimaryKeys
?
self
.
primaryKeyValues
:
{
id
:
self
.
id
};
...
@@ -550,7 +546,7 @@ module.exports = (function() {
...
@@ -550,7 +546,7 @@ module.exports = (function() {
})
})
var
identifier
=
this
.
__options
.
hasPrimaryKeys
?
this
.
primaryKeyValues
:
{
id
:
this
.
id
}
var
identifier
=
this
.
__options
.
hasPrimaryKeys
?
this
.
primaryKeyValues
:
{
id
:
this
.
id
}
,
updatedAtAttr
=
Utils
.
_
.
underscoredIf
(
this
.
__options
.
updatedAt
,
this
.
__options
.
underscored
)
,
updatedAtAttr
=
this
.
Model
.
_timestampAttributes
.
updatedAt
,
values
=
{}
,
values
=
{}
if
(
countOrOptions
===
undefined
)
{
if
(
countOrOptions
===
undefined
)
{
...
@@ -574,10 +570,8 @@ module.exports = (function() {
...
@@ -574,10 +570,8 @@ module.exports = (function() {
values
=
fields
values
=
fields
}
}
if
(
this
.
__options
.
timestamps
)
{
if
(
updatedAtAttr
&&
!
values
[
updatedAtAttr
])
{
if
(
!
values
[
updatedAtAttr
])
{
countOrOptions
.
attributes
[
updatedAtAttr
]
=
Utils
.
now
(
this
.
daoFactory
.
daoFactoryManager
.
sequelize
.
options
.
dialect
)
countOrOptions
.
attributes
[
updatedAtAttr
]
=
Utils
.
now
(
this
.
daoFactory
.
daoFactoryManager
.
sequelize
.
options
.
dialect
)
}
}
}
return
this
.
QueryInterface
.
increment
(
this
,
this
.
QueryInterface
.
QueryGenerator
.
addSchema
(
this
.
__factory
.
tableName
,
this
.
__factory
.
options
.
schema
),
values
,
identifier
,
countOrOptions
)
return
this
.
QueryInterface
.
increment
(
this
,
this
.
QueryInterface
.
QueryGenerator
.
addSchema
(
this
.
__factory
.
tableName
,
this
.
__factory
.
options
.
schema
),
values
,
identifier
,
countOrOptions
)
...
@@ -643,7 +637,6 @@ module.exports = (function() {
...
@@ -643,7 +637,6 @@ module.exports = (function() {
}
}
// private
// private
var
initValues
=
function
(
values
,
options
)
{
var
initValues
=
function
(
values
,
options
)
{
// set id to null if not passed as value, a newly created dao has no id
// set id to null if not passed as value, a newly created dao has no id
var
defaults
=
this
.
hasPrimaryKeys
?
{}
:
{
id
:
null
},
var
defaults
=
this
.
hasPrimaryKeys
?
{}
:
{
id
:
null
},
...
@@ -660,21 +653,19 @@ module.exports = (function() {
...
@@ -660,21 +653,19 @@ module.exports = (function() {
})
})
}
}
if
(
this
.
__options
.
timestamps
)
{
if
(
this
.
Model
.
_timestampAttributes
.
createdAt
&&
defaults
[
this
.
Model
.
_timestampAttributes
.
createdAt
])
{
if
(
defaults
[
this
.
_timestampAttributes
.
createdAt
])
{
this
.
dataValues
[
this
.
Model
.
_timestampAttributes
.
createdAt
]
=
Utils
.
toDefaultValue
(
defaults
[
this
.
Model
.
_timestampAttributes
.
createdAt
]);
this
.
dataValues
[
this
.
_timestampAttributes
.
createdAt
]
=
Utils
.
toDefaultValue
(
defaults
[
this
.
_timestampAttributes
.
createdAt
]);
delete
defaults
[
this
.
Model
.
_timestampAttributes
.
createdAt
];
delete
defaults
[
this
.
_timestampAttributes
.
createdAt
];
}
}
if
(
defaults
[
this
.
_timestampAttributes
.
updatedAt
])
{
if
(
this
.
Model
.
_timestampAttributes
.
updatedAt
&&
defaults
[
this
.
Model
.
_timestampAttributes
.
updatedAt
])
{
this
.
dataValues
[
this
.
_timestampAttributes
.
updatedAt
]
=
Utils
.
toDefaultValue
(
defaults
[
this
.
_timestampAttributes
.
updatedAt
]);
this
.
dataValues
[
this
.
Model
.
_timestampAttributes
.
updatedAt
]
=
Utils
.
toDefaultValue
(
defaults
[
this
.
Model
.
_timestampAttributes
.
updatedAt
]);
delete
defaults
[
this
.
_timestampAttributes
.
updatedAt
];
delete
defaults
[
this
.
Model
.
_timestampAttributes
.
updatedAt
];
}
}
if
(
defaults
[
this
.
_timestampAttributes
.
deletedAt
])
{
if
(
this
.
Model
.
_timestampAttributes
.
createdAt
&&
defaults
[
this
.
Model
.
_timestampAttributes
.
deletedAt
])
{
this
.
dataValues
[
this
.
_timestampAttributes
.
deletedAt
]
=
Utils
.
toDefaultValue
(
defaults
[
this
.
_timestampAttributes
.
deletedAt
]);
this
.
dataValues
[
this
.
Model
.
_timestampAttributes
.
deletedAt
]
=
Utils
.
toDefaultValue
(
defaults
[
this
.
Model
.
_timestampAttributes
.
deletedAt
]);
delete
defaults
[
this
.
_timestampAttributes
.
deletedAt
];
delete
defaults
[
this
.
Model
.
_timestampAttributes
.
deletedAt
];
}
}
}
}
}
if
(
Object
.
keys
(
defaults
).
length
)
{
if
(
Object
.
keys
(
defaults
).
length
)
{
...
...
lib/dialects/abstract/query-generator.js
View file @
775dd7b
...
@@ -1066,12 +1066,12 @@ module.exports = (function() {
...
@@ -1066,12 +1066,12 @@ module.exports = (function() {
return
joins
;
return
joins
;
},
},
arrayValue
:
function
(
value
,
key
,
_key
){
arrayValue
:
function
(
value
,
key
,
_key
,
factory
,
logicResult
){
var
_value
=
null
;
var
_value
=
null
;
if
(
value
.
length
===
0
)
{
value
=
[
null
]
}
if
(
value
.
length
===
0
)
{
value
=
[
null
]
}
_value
=
"("
+
value
.
map
(
function
(
v
)
{
return
this
.
escape
(
v
)
}.
bind
(
this
)).
join
(
','
)
+
")"
_value
=
"("
+
value
.
map
(
function
(
v
)
{
return
this
.
escape
(
v
)
}.
bind
(
this
)).
join
(
','
)
+
")"
return
[
_key
,
_value
].
join
(
"
IN
"
)
return
[
_key
,
_value
].
join
(
"
"
+
logicResult
+
"
"
)
},
},
/*
/*
...
@@ -1104,7 +1104,7 @@ module.exports = (function() {
...
@@ -1104,7 +1104,7 @@ module.exports = (function() {
}
}
if
(
Array
.
isArray
(
value
))
{
if
(
Array
.
isArray
(
value
))
{
result
.
push
(
this
.
arrayValue
(
value
,
key
,
_key
,
dao
))
result
.
push
(
this
.
arrayValue
(
value
,
key
,
_key
,
dao
,
"IN"
))
}
else
if
((
value
)
&&
(
typeof
value
==
'object'
)
&&
!
(
value
instanceof
Date
)
&&
!
Buffer
.
isBuffer
(
value
))
{
}
else
if
((
value
)
&&
(
typeof
value
==
'object'
)
&&
!
(
value
instanceof
Date
)
&&
!
Buffer
.
isBuffer
(
value
))
{
if
(
!!
value
.
join
)
{
if
(
!!
value
.
join
)
{
//using as sentinel for join column => value
//using as sentinel for join column => value
...
@@ -1113,10 +1113,9 @@ module.exports = (function() {
...
@@ -1113,10 +1113,9 @@ module.exports = (function() {
}
else
{
}
else
{
for
(
var
logic
in
value
)
{
for
(
var
logic
in
value
)
{
var
logicResult
=
Utils
.
getWhereLogic
(
logic
,
hash
[
key
][
logic
]);
var
logicResult
=
Utils
.
getWhereLogic
(
logic
,
hash
[
key
][
logic
]);
if
(
logic
===
"IN"
||
logic
===
"NOT IN"
)
{
if
(
logicResult
===
"IN"
||
logicResult
===
"NOT IN"
)
{
var
values
=
Array
.
isArray
(
where
[
i
][
ii
])
?
where
[
i
][
ii
]
:
[
where
[
i
][
ii
]]
var
values
=
Array
.
isArray
(
value
[
logic
])
?
value
[
logic
]
:
[
value
[
logic
]]
_where
[
_where
.
length
]
=
i
+
' '
+
logic
+
' ('
+
values
.
map
(
function
(){
return
'?'
}).
join
(
','
)
+
')'
result
.
push
(
this
.
arrayValue
(
values
,
key
,
_key
,
dao
,
logicResult
))
_whereArgs
=
_whereArgs
.
concat
(
values
)
}
}
else
if
(
logicResult
===
"BETWEEN"
||
logicResult
===
"NOT BETWEEN"
)
{
else
if
(
logicResult
===
"BETWEEN"
||
logicResult
===
"NOT BETWEEN"
)
{
_value
=
this
.
escape
(
value
[
logic
][
0
])
_value
=
this
.
escape
(
value
[
logic
][
0
])
...
...
lib/dialects/mysql/query-generator.js
View file @
775dd7b
...
@@ -182,7 +182,7 @@ module.exports = (function() {
...
@@ -182,7 +182,7 @@ module.exports = (function() {
,
allAttributes
=
[]
,
allAttributes
=
[]
Utils
.
_
.
forEach
(
attrValueHashes
,
function
(
attrValueHash
,
i
)
{
Utils
.
_
.
forEach
(
attrValueHashes
,
function
(
attrValueHash
,
i
)
{
Utils
.
_
.
for
Each
(
attrValueHash
,
function
(
value
,
key
,
hash
)
{
Utils
.
_
.
for
Own
(
attrValueHash
,
function
(
value
,
key
,
hash
)
{
if
(
allAttributes
.
indexOf
(
key
)
===
-
1
)
allAttributes
.
push
(
key
)
if
(
allAttributes
.
indexOf
(
key
)
===
-
1
)
allAttributes
.
push
(
key
)
})
})
})
})
...
...
lib/dialects/postgres/connector-manager.js
View file @
775dd7b
...
@@ -12,7 +12,6 @@ module.exports = (function() {
...
@@ -12,7 +12,6 @@ module.exports = (function() {
this
.
config
.
port
=
this
.
config
.
port
||
5432
this
.
config
.
port
=
this
.
config
.
port
||
5432
this
.
pooling
=
(
!!
this
.
config
.
pool
&&
(
this
.
config
.
pool
.
maxConnections
>
0
))
this
.
pooling
=
(
!!
this
.
config
.
pool
&&
(
this
.
config
.
pool
.
maxConnections
>
0
))
this
.
pg
=
this
.
config
.
native
?
require
(
pgModule
).
native
:
require
(
pgModule
)
this
.
pg
=
this
.
config
.
native
?
require
(
pgModule
).
native
:
require
(
pgModule
)
this
.
poolIdentifier
=
null
// Better support for BigInts
// Better support for BigInts
// https://github.com/brianc/node-postgres/issues/166#issuecomment-9514935
// https://github.com/brianc/node-postgres/issues/166#issuecomment-9514935
this
.
pg
.
types
.
setTypeParser
(
20
,
String
);
this
.
pg
.
types
.
setTypeParser
(
20
,
String
);
...
@@ -181,10 +180,6 @@ module.exports = (function() {
...
@@ -181,10 +180,6 @@ module.exports = (function() {
}
}
ConnectorManager
.
prototype
.
disconnect
=
function
()
{
ConnectorManager
.
prototype
.
disconnect
=
function
()
{
if
(
this
.
poolIdentifier
)
{
this
.
poolIdentifier
.
destroyAllNow
()
}
if
(
this
.
client
)
{
if
(
this
.
client
)
{
if
(
this
.
clientDrained
)
{
if
(
this
.
clientDrained
)
{
this
.
client
.
end
()
this
.
client
.
end
()
...
...
lib/dialects/postgres/query-generator.js
View file @
775dd7b
...
@@ -156,7 +156,7 @@ module.exports = (function() {
...
@@ -156,7 +156,7 @@ module.exports = (function() {
attributes
:
attrString
.
join
(
', '
)
})
attributes
:
attrString
.
join
(
', '
)
})
},
},
arrayValue
:
function
(
value
,
key
,
_key
,
factory
){
arrayValue
:
function
(
value
,
key
,
_key
,
factory
,
logicResult
){
var
col
=
null
var
col
=
null
,
coltype
=
null
,
coltype
=
null
,
_realKey
=
key
.
split
(
'.'
).
pop
()
,
_realKey
=
key
.
split
(
'.'
).
pop
()
...
@@ -177,7 +177,7 @@ module.exports = (function() {
...
@@ -177,7 +177,7 @@ module.exports = (function() {
return
[
_key
,
_value
].
join
(
" && "
)
return
[
_key
,
_value
].
join
(
" && "
)
}
else
{
}
else
{
_value
=
"("
+
value
.
map
(
this
.
escape
).
join
(
','
)
+
")"
_value
=
"("
+
value
.
map
(
this
.
escape
).
join
(
','
)
+
")"
return
[
_key
,
_value
].
join
(
"
IN
"
)
return
[
_key
,
_value
].
join
(
"
"
+
logicResult
+
"
"
)
}
}
},
},
...
@@ -274,7 +274,7 @@ module.exports = (function() {
...
@@ -274,7 +274,7 @@ module.exports = (function() {
,
allAttributes
=
[]
,
allAttributes
=
[]
Utils
.
_
.
forEach
(
attrValueHashes
,
function
(
attrValueHash
,
i
)
{
Utils
.
_
.
forEach
(
attrValueHashes
,
function
(
attrValueHash
,
i
)
{
Utils
.
_
.
for
Each
(
attrValueHash
,
function
(
value
,
key
,
hash
)
{
Utils
.
_
.
for
Own
(
attrValueHash
,
function
(
value
,
key
,
hash
)
{
if
(
allAttributes
.
indexOf
(
key
)
===
-
1
)
allAttributes
.
push
(
key
)
if
(
allAttributes
.
indexOf
(
key
)
===
-
1
)
allAttributes
.
push
(
key
)
if
(
tables
[
tableName
]
&&
tables
[
tableName
][
key
])
{
if
(
tables
[
tableName
]
&&
tables
[
tableName
][
key
])
{
...
...
lib/dialects/sqlite/query-generator.js
View file @
775dd7b
...
@@ -178,7 +178,7 @@ module.exports = (function() {
...
@@ -178,7 +178,7 @@ module.exports = (function() {
,
allAttributes
=
[]
,
allAttributes
=
[]
Utils
.
_
.
forEach
(
attrValueHashes
,
function
(
attrValueHash
,
i
)
{
Utils
.
_
.
forEach
(
attrValueHashes
,
function
(
attrValueHash
,
i
)
{
Utils
.
_
.
for
Each
(
attrValueHash
,
function
(
value
,
key
,
hash
)
{
Utils
.
_
.
for
Own
(
attrValueHash
,
function
(
value
,
key
,
hash
)
{
if
(
allAttributes
.
indexOf
(
key
)
===
-
1
)
allAttributes
.
push
(
key
)
if
(
allAttributes
.
indexOf
(
key
)
===
-
1
)
allAttributes
.
push
(
key
)
})
})
})
})
...
...
lib/query-interface.js
View file @
775dd7b
...
@@ -141,6 +141,7 @@ module.exports = (function() {
...
@@ -141,6 +141,7 @@ module.exports = (function() {
chainer2
.
add
(
self
.
sequelize
.
query
(
self
.
QueryGenerator
.
pgEnumAdd
(
getTableName
,
keys
[
i
],
value
,
options
)))
chainer2
.
add
(
self
.
sequelize
.
query
(
self
.
QueryGenerator
.
pgEnumAdd
(
getTableName
,
keys
[
i
],
value
,
options
)))
}
}
})
})
enumIdx
++
}
}
}
}
}
}
...
...
lib/sequelize.js
View file @
775dd7b
...
@@ -56,7 +56,12 @@ module.exports = (function() {
...
@@ -56,7 +56,12 @@ module.exports = (function() {
if
(
arguments
.
length
===
1
||
(
arguments
.
length
===
2
&&
typeof
username
===
'object'
))
{
if
(
arguments
.
length
===
1
||
(
arguments
.
length
===
2
&&
typeof
username
===
'object'
))
{
options
=
username
||
{}
options
=
username
||
{}
urlParts
=
url
.
parse
(
arguments
[
0
])
urlParts
=
url
.
parse
(
arguments
[
0
])
database
=
urlParts
.
path
.
replace
(
/^
\/
/
,
''
)
// SQLite don't have DB in connection url
if
(
urlParts
.
path
)
{
database
=
urlParts
.
path
.
replace
(
/^
\/
/
,
''
)
}
dialect
=
urlParts
.
protocol
dialect
=
urlParts
.
protocol
options
.
dialect
=
urlParts
.
protocol
.
replace
(
/:$/
,
''
)
options
.
dialect
=
urlParts
.
protocol
.
replace
(
/:$/
,
''
)
options
.
host
=
urlParts
.
hostname
options
.
host
=
urlParts
.
hostname
...
@@ -79,7 +84,7 @@ module.exports = (function() {
...
@@ -79,7 +84,7 @@ module.exports = (function() {
define
:
{},
define
:
{},
query
:
{},
query
:
{},
sync
:
{},
sync
:
{},
logging
:
false
,
logging
:
console
.
log
,
omitNull
:
false
,
omitNull
:
false
,
queue
:
true
,
queue
:
true
,
native
:
false
,
native
:
false
,
...
...
test/assets/migrations/20111117063700-createPerson.cs
0 → 100644
View file @
775dd7b
module
.
exports
=
{
up
:
function
(
migration
,
DataTypes
,
done
)
{
migration
.
createTable
(
'
Person
'
,
{
name
:
DataTypes
.
STRING
,
isBetaMember
:
{
type
:
DataTypes
.
BOOLEAN
,
defaultValue
:
false
,
allowNull
:
false
}
})
.
complete
(
done
)
},
down
:
function
(
migration
,
DataTypes
,
done
)
{
migration
.
dropTable
(
'
Person
'
).
complete
(
done
)
}
}
test/dao-factory.test.js
View file @
775dd7b
...
@@ -205,6 +205,30 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
...
@@ -205,6 +205,30 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
})
})
it
(
'should allow me to disable some of the timestamp fields'
,
function
(
done
)
{
var
UpdatingUser
=
this
.
sequelize
.
define
(
'UpdatingUser'
,
{},
{
timestamps
:
true
,
updatedAt
:
false
,
createdAt
:
false
,
deletedAt
:
'deletedAtThisTime'
,
paranoid
:
true
})
UpdatingUser
.
sync
({
force
:
true
}).
success
(
function
()
{
UpdatingUser
.
create
().
success
(
function
(
user
)
{
expect
(
user
.
createdAt
).
not
.
to
.
exist
expect
(
user
.
false
).
not
.
to
.
exist
// because, you know we might accidentally add a field named 'false'
user
.
save
().
success
(
function
(
user
)
{
expect
(
user
.
updatedAt
).
not
.
to
.
exist
user
.
destroy
().
success
(
function
(
user
)
{
expect
(
user
.
deletedAtThisTime
).
to
.
exist
done
()
})
})
})
})
})
it
(
'should allow me to override updatedAt, createdAt, and deletedAt fields with underscored being true'
,
function
(
done
)
{
it
(
'should allow me to override updatedAt, createdAt, and deletedAt fields with underscored being true'
,
function
(
done
)
{
var
UserTable
=
this
.
sequelize
.
define
(
'UserCol'
,
{
var
UserTable
=
this
.
sequelize
.
define
(
'UserCol'
,
{
aNumber
:
Sequelize
.
INTEGER
aNumber
:
Sequelize
.
INTEGER
...
@@ -1944,4 +1968,42 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
...
@@ -1944,4 +1968,42 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
describe
(
'Unique'
,
function
()
{
it
(
"should set unique when unique is true"
,
function
(
done
)
{
var
self
=
this
var
uniqueTrue
=
self
.
sequelize
.
define
(
'uniqueTrue'
,
{
str
:
{
type
:
Sequelize
.
STRING
,
unique
:
true
}
})
uniqueTrue
.
sync
({
force
:
true
}).
on
(
'sql'
,
function
(
s
)
{
expect
(
s
).
to
.
match
(
/UNIQUE/
)
done
()
})
})
it
(
"should not set unique when unique is false"
,
function
(
done
)
{
var
self
=
this
var
uniqueFalse
=
self
.
sequelize
.
define
(
'uniqueFalse'
,
{
str
:
{
type
:
Sequelize
.
STRING
,
unique
:
false
}
})
uniqueFalse
.
sync
({
force
:
true
}).
on
(
'sql'
,
function
(
s
)
{
expect
(
s
).
not
.
to
.
match
(
/UNIQUE/
)
done
()
})
})
it
(
"should not set unique when unique is unset"
,
function
(
done
)
{
var
self
=
this
var
uniqueUnset
=
self
.
sequelize
.
define
(
'uniqueUnset'
,
{
str
:
{
type
:
Sequelize
.
STRING
}
})
uniqueUnset
.
sync
({
force
:
true
}).
on
(
'sql'
,
function
(
s
)
{
expect
(
s
).
not
.
to
.
match
(
/UNIQUE/
)
done
()
})
})
})
})
})
test/dao-factory/create.test.js
View file @
775dd7b
...
@@ -407,6 +407,31 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
...
@@ -407,6 +407,31 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
})
})
it
(
"raises an error if saving an empty string into a column allowing null or URL"
,
function
(
done
)
{
var
StringIsNullOrUrl
=
this
.
sequelize
.
define
(
'StringIsNullOrUrl'
,
{
str
:
{
type
:
Sequelize
.
STRING
,
allowNull
:
true
,
validate
:
{
isUrl
:
true
}
}
})
this
.
sequelize
.
options
.
omitNull
=
false
StringIsNullOrUrl
.
sync
({
force
:
true
}).
success
(
function
()
{
StringIsNullOrUrl
.
create
({
str
:
null
}).
success
(
function
(
str1
)
{
expect
(
str1
.
str
).
to
.
be
.
null
StringIsNullOrUrl
.
create
({
str
:
'http://sequelizejs.org'
}).
success
(
function
(
str2
)
{
expect
(
str2
.
str
).
to
.
equal
(
'http://sequelizejs.org'
)
StringIsNullOrUrl
.
create
({
str
:
''
}).
error
(
function
(
err
)
{
expect
(
err
).
to
.
exist
expect
(
err
.
str
[
0
]).
to
.
match
(
/Invalid URL: str/
)
done
()
})
})
})
})
})
it
(
'raises an error if you mess up the datatype'
,
function
(
done
)
{
it
(
'raises an error if you mess up the datatype'
,
function
(
done
)
{
var
self
=
this
var
self
=
this
expect
(
function
()
{
expect
(
function
()
{
...
@@ -886,6 +911,18 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
...
@@ -886,6 +911,18 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
})
})
it
(
'properly handles a model with a length column'
,
function
(
done
)
{
var
UserWithLength
=
this
.
sequelize
.
define
(
'UserWithLength'
,
{
length
:
Sequelize
.
INTEGER
})
UserWithLength
.
sync
({
force
:
true
}).
success
(
function
()
{
UserWithLength
.
bulkCreate
([{
length
:
42
},
{
length
:
11
}]).
success
(
function
()
{
done
()
})
})
})
it
(
'stores the current date in createdAt'
,
function
(
done
)
{
it
(
'stores the current date in createdAt'
,
function
(
done
)
{
var
self
=
this
var
self
=
this
,
data
=
[{
username
:
'Peter'
},
,
data
=
[{
username
:
'Peter'
},
...
...
test/migrator.test.js
View file @
775dd7b
...
@@ -28,6 +28,19 @@ describe(Support.getTestDialectTeaser("Migrator"), function() {
...
@@ -28,6 +28,19 @@ describe(Support.getTestDialectTeaser("Migrator"), function() {
})
})
describe
(
'getUndoneMigrations'
,
function
()
{
describe
(
'getUndoneMigrations'
,
function
()
{
it
(
"supports coffee files"
,
function
(
done
)
{
this
.
init
({
filesFilter
:
/
\.
cs$/
,
to
:
20111130161100
},
function
(
migrator
)
{
migrator
.
getUndoneMigrations
(
function
(
err
,
migrations
)
{
expect
(
err
).
to
.
be
.
null
expect
(
migrations
).
to
.
have
.
length
(
1
)
done
()
})
})
})
it
(
"returns no files if timestamps are after the files timestamp"
,
function
(
done
)
{
it
(
"returns no files if timestamps are after the files timestamp"
,
function
(
done
)
{
this
.
init
({
from
:
20140101010101
},
function
(
migrator
)
{
this
.
init
({
from
:
20140101010101
},
function
(
migrator
)
{
migrator
.
getUndoneMigrations
(
function
(
err
,
migrations
)
{
migrator
.
getUndoneMigrations
(
function
(
err
,
migrations
)
{
...
@@ -309,7 +322,7 @@ describe(Support.getTestDialectTeaser("Migrator"), function() {
...
@@ -309,7 +322,7 @@ describe(Support.getTestDialectTeaser("Migrator"), function() {
})
})
})
})
})
})
if
(
dialect
.
match
(
/^postgres/
))
{
if
(
dialect
.
match
(
/^postgres/
))
{
describe
(
'function migrations'
,
function
()
{
describe
(
'function migrations'
,
function
()
{
...
...
test/postgres/dao.test.js
View file @
775dd7b
...
@@ -106,7 +106,11 @@ if (dialect.match(/^postgres/)) {
...
@@ -106,7 +106,11 @@ if (dialect.match(/^postgres/)) {
// now sync one more time:
// now sync one more time:
DummyModel
.
sync
({
force
:
true
}).
done
(
function
(
err
)
{
DummyModel
.
sync
({
force
:
true
}).
done
(
function
(
err
)
{
expect
(
err
).
not
.
to
.
be
.
ok
expect
(
err
).
not
.
to
.
be
.
ok
done
();
// sync without dropping
DummyModel
.
sync
().
done
(
function
(
err
)
{
expect
(
err
).
not
.
to
.
be
.
ok
done
();
})
})
})
})
})
})
})
...
...
test/postgres/query-generator.test.js
View file @
775dd7b
...
@@ -906,6 +906,14 @@ if (dialect.match(/^postgres/)) {
...
@@ -906,6 +906,14 @@ if (dialect.match(/^postgres/)) {
arguments
:
[{
id
:
[]
}],
arguments
:
[{
id
:
[]
}],
expectation
:
"\"id\" IN (NULL)"
expectation
:
"\"id\" IN (NULL)"
},
},
{
arguments
:
[{
id
:
{
not
:
[
1
,
2
,
3
]
}}],
expectation
:
"\"id\" NOT IN (1,2,3)"
},
{
arguments
:
[{
id
:
{
not
:
[]
}}],
expectation
:
"\"id\" NOT IN (NULL)"
},
// Variants when quoteIdentifiers is false
// Variants when quoteIdentifiers is false
{
{
...
@@ -918,6 +926,16 @@ if (dialect.match(/^postgres/)) {
...
@@ -918,6 +926,16 @@ if (dialect.match(/^postgres/)) {
expectation
:
"id IN (NULL)"
,
expectation
:
"id IN (NULL)"
,
context
:
{
options
:
{
quoteIdentifiers
:
false
}}
context
:
{
options
:
{
quoteIdentifiers
:
false
}}
},
},
{
arguments
:
[{
id
:
{
not
:
[
1
,
2
,
3
]
}}],
expectation
:
"id NOT IN (1,2,3)"
,
context
:
{
options
:
{
quoteIdentifiers
:
false
}}
},
{
arguments
:
[{
id
:
{
not
:
[]
}}],
expectation
:
"id NOT IN (NULL)"
,
context
:
{
options
:
{
quoteIdentifiers
:
false
}}
}
]
]
}
}
...
...
test/sequelize.executable.test.js
View file @
775dd7b
...
@@ -6,6 +6,7 @@ var chai = require('chai')
...
@@ -6,6 +6,7 @@ var chai = require('chai')
,
_
=
require
(
'lodash'
)
,
_
=
require
(
'lodash'
)
,
exec
=
require
(
'child_process'
).
exec
,
exec
=
require
(
'child_process'
).
exec
,
version
=
(
require
(
__dirname
+
'/../package.json'
)).
version
,
version
=
(
require
(
__dirname
+
'/../package.json'
)).
version
,
path
=
require
(
'path'
)
chai
.
Assertion
.
includeStack
=
true
chai
.
Assertion
.
includeStack
=
true
...
@@ -205,7 +206,14 @@ describe(Support.getTestDialectTeaser("Executable"), function() {
...
@@ -205,7 +206,14 @@ describe(Support.getTestDialectTeaser("Executable"), function() {
})
})
})
})
})
})
})([
'--migrate'
,
'-m'
])
})([
'--migrate'
,
'--migrate --config ../tmp/config/config.json'
,
'--migrate --config '
+
path
.
join
(
__dirname
,
'tmp'
,
'config'
,
'config.json'
),
'-m'
,
'-m --config ../tmp/config/config.json'
,
'-m --config '
+
path
.
join
(
__dirname
,
'tmp'
,
'config'
,
'config.json'
)
])
;(
function
(
flags
)
{
;(
function
(
flags
)
{
flags
.
forEach
(
function
(
flag
)
{
flags
.
forEach
(
function
(
flag
)
{
...
...
test/sequelize.test.js
View file @
775dd7b
...
@@ -40,6 +40,15 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
...
@@ -40,6 +40,15 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
expect
(
sequelize
.
config
.
host
).
to
.
equal
(
'127.0.0.1'
)
expect
(
sequelize
.
config
.
host
).
to
.
equal
(
'127.0.0.1'
)
done
()
done
()
})
})
if
(
dialect
===
'sqlite'
)
{
it
(
'should work with connection strings (1)'
,
function
()
{
var
sequelize
=
new
Sequelize
(
'sqlite://test.sqlite'
)
})
it
(
'should work with connection strings (2)'
,
function
()
{
var
sequelize
=
new
Sequelize
(
'sqlite://test.sqlite/'
)
})
}
})
})
if
(
dialect
!==
'sqlite'
)
{
if
(
dialect
!==
'sqlite'
)
{
...
...
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