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 e67e43c0
authored
Aug 24, 2010
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added error handling for invalid database credentials
1 parent
7a9200da
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
12 deletions
src/Sequelize.js
src/SequelizeTable.js
test/SequelizeTableTest.js
test/SequelizeTest.js
src/Sequelize.js
View file @
e67e43c
...
@@ -111,8 +111,9 @@ Sequelize.prototype = {
...
@@ -111,8 +111,9 @@ Sequelize.prototype = {
},
},
sync
:
function
(
callback
)
{
sync
:
function
(
callback
)
{
var
finished
=
[]
var
finished
=
[],
var
tables
=
this
.
tables
tables
=
this
.
tables
,
errors
=
[]
Sequelize
.
Helper
.
Hash
.
forEach
(
tables
,
function
(
table
)
{
Sequelize
.
Helper
.
Hash
.
forEach
(
tables
,
function
(
table
)
{
table
.
klass
.
prepareAssociations
()
table
.
klass
.
prepareAssociations
()
...
@@ -122,25 +123,29 @@ Sequelize.prototype = {
...
@@ -122,25 +123,29 @@ Sequelize.prototype = {
callback
()
callback
()
else
else
Sequelize
.
Helper
.
Hash
.
forEach
(
tables
,
function
(
table
)
{
Sequelize
.
Helper
.
Hash
.
forEach
(
tables
,
function
(
table
)
{
table
.
klass
.
sync
(
function
()
{
table
.
klass
.
sync
(
function
(
_
,
err
)
{
finished
.
push
(
true
)
finished
.
push
(
true
)
if
(
err
)
errors
.
push
(
err
)
if
((
finished
.
length
==
Sequelize
.
Helper
.
Hash
.
keys
(
tables
).
length
)
&&
callback
)
if
((
finished
.
length
==
Sequelize
.
Helper
.
Hash
.
keys
(
tables
).
length
)
&&
callback
)
callback
()
callback
(
errors
)
})
})
})
})
},
},
drop
:
function
(
callback
)
{
drop
:
function
(
callback
)
{
var
finished
=
[]
var
finished
=
[],
var
tables
=
this
.
tables
tables
=
this
.
tables
,
errors
=
[]
if
((
Sequelize
.
Helper
.
Hash
.
keys
(
tables
).
length
==
0
)
&&
callback
)
callback
()
if
((
Sequelize
.
Helper
.
Hash
.
keys
(
tables
).
length
==
0
)
&&
callback
)
callback
()
else
else
Sequelize
.
Helper
.
Hash
.
forEach
(
tables
,
function
(
table
,
tableName
)
{
Sequelize
.
Helper
.
Hash
.
forEach
(
tables
,
function
(
table
,
tableName
)
{
table
.
klass
.
drop
(
function
()
{
table
.
klass
.
drop
(
function
(
_
,
err
)
{
finished
.
push
(
true
)
finished
.
push
(
true
)
if
(
finished
.
length
==
Sequelize
.
Helper
.
Hash
.
keys
(
tables
).
length
)
if
(
err
)
errors
.
push
(
err
)
if
(
callback
)
callback
()
if
((
finished
.
length
==
Sequelize
.
Helper
.
Hash
.
keys
(
tables
).
length
)
&&
callback
)
callback
(
errors
)
})
})
})
})
},
},
...
@@ -154,6 +159,7 @@ Sequelize.prototype = {
...
@@ -154,6 +159,7 @@ Sequelize.prototype = {
connection
.
auto_prepare
=
true
connection
.
auto_prepare
=
true
connection
connection
.
auth
(
this
.
config
.
database
,
this
.
config
.
username
,
this
.
config
.
password
)
.
auth
(
this
.
config
.
database
,
this
.
config
.
username
,
this
.
config
.
password
)
.
addListener
(
"error"
,
function
(
err
)
{
callback
(
err
)
})
.
addListener
(
'authorized'
,
function
()
{
.
addListener
(
'authorized'
,
function
()
{
if
(
!
self
.
options
.
disableLogging
)
if
(
!
self
.
options
.
disableLogging
)
Sequelize
.
Helper
.
log
(
"Executing the query: "
+
queryString
)
Sequelize
.
Helper
.
log
(
"Executing the query: "
+
queryString
)
...
...
src/SequelizeTable.js
View file @
e67e43c
...
@@ -79,6 +79,7 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
...
@@ -79,6 +79,7 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
if
(
callback
)
callback
()
if
(
callback
)
callback
()
},
},
/* returns: table, error */
sync
:
function
(
callback
)
{
sync
:
function
(
callback
)
{
var
fields
=
[
"id INT NOT NULL auto_increment PRIMARY KEY"
]
var
fields
=
[
"id INT NOT NULL auto_increment PRIMARY KEY"
]
Sequelize
.
Helper
.
Hash
.
forEach
(
table
.
attributes
,
function
(
type
,
name
)
{
Sequelize
.
Helper
.
Hash
.
forEach
(
table
.
attributes
,
function
(
type
,
name
)
{
...
@@ -87,14 +88,14 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
...
@@ -87,14 +88,14 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
sequelize
.
query
(
sequelize
.
query
(
Sequelize
.
sqlQueryFor
(
'create'
,
{
table
:
table
.
tableName
,
fields
:
fields
.
join
(
', '
)
}
),
Sequelize
.
sqlQueryFor
(
'create'
,
{
table
:
table
.
tableName
,
fields
:
fields
.
join
(
', '
)
}
),
function
(
)
{
if
(
callback
)
callback
(
table
)
}
function
(
err
)
{
if
(
callback
)
callback
(
table
,
err
)
}
)
)
},
},
drop
:
function
(
callback
)
{
drop
:
function
(
callback
)
{
sequelize
.
query
(
sequelize
.
query
(
Sequelize
.
sqlQueryFor
(
'drop'
,
{
table
:
table
.
tableName
}),
Sequelize
.
sqlQueryFor
(
'drop'
,
{
table
:
table
.
tableName
}),
function
(
)
{
if
(
callback
)
callback
(
table
)
}
function
(
err
)
{
if
(
callback
)
callback
(
table
,
err
)
}
)
)
},
},
...
...
test/SequelizeTableTest.js
View file @
e67e43c
...
@@ -314,5 +314,29 @@ module.exports = {
...
@@ -314,5 +314,29 @@ module.exports = {
})
})
})
})
beforeExit
(
function
()
{
assert
.
equal
(
true
,
testIsFinished
)
})
beforeExit
(
function
()
{
assert
.
equal
(
true
,
testIsFinished
)
})
},
'sync ==> failure'
:
function
(
assert
,
beforeExit
)
{
var
testIsFinished
=
false
,
sequelizeWithInvalidCredentials
=
new
Sequelize
(
'foo'
,
'bar'
,
'barfoos'
),
Fail
=
sequelizeWithInvalidCredentials
.
define
(
'Fail'
,
{})
Fail
.
sync
(
function
(
table
,
err
)
{
assert
.
isDefined
(
err
)
assert
.
isDefined
(
err
.
message
)
testIsFinished
=
true
})
beforeExit
(
function
()
{
assert
.
equal
(
testIsFinished
,
true
)
})
},
'drop ==> failure'
:
function
(
assert
,
beforeExit
)
{
var
testIsFinished
=
false
,
sequelizeWithInvalidCredentials
=
new
Sequelize
(
'foo'
,
'bar'
,
'barfoos'
),
Fail
=
sequelizeWithInvalidCredentials
.
define
(
'Fail'
,
{})
Fail
.
drop
(
function
(
table
,
err
)
{
assert
.
isDefined
(
err
)
assert
.
isDefined
(
err
.
message
)
testIsFinished
=
true
})
beforeExit
(
function
()
{
assert
.
equal
(
testIsFinished
,
true
)
})
}
}
}
}
\ No newline at end of file
test/SequelizeTest.js
View file @
e67e43c
...
@@ -75,5 +75,29 @@ module.exports = {
...
@@ -75,5 +75,29 @@ module.exports = {
'sqlQueryFor: delete wihtout limit'
:
function
(
assert
)
{
'sqlQueryFor: delete wihtout limit'
:
function
(
assert
)
{
var
query
=
Sequelize
.
sqlQueryFor
(
'delete'
,
{
table
:
'Foo'
,
where
:
"id=2"
,
limit
:
null
})
var
query
=
Sequelize
.
sqlQueryFor
(
'delete'
,
{
table
:
'Foo'
,
where
:
"id=2"
,
limit
:
null
})
assert
.
equal
(
query
,
"DELETE FROM Foo WHERE id=2"
)
assert
.
equal
(
query
,
"DELETE FROM Foo WHERE id=2"
)
},
'sync: errors'
:
function
(
assert
,
beforeExit
)
{
var
testIsFinished
=
false
,
sequelizeWithInvalidCredentials
=
new
Sequelize
(
'foo'
,
'bar'
,
'barfoos'
),
Fail
=
sequelizeWithInvalidCredentials
.
define
(
'Fail'
,
{})
sequelizeWithInvalidCredentials
.
sync
(
function
(
errors
)
{
assert
.
isDefined
(
errors
)
assert
.
equal
(
errors
.
length
,
1
)
testIsFinished
=
true
})
beforeExit
(
function
()
{
assert
.
equal
(
testIsFinished
,
true
)
})
},
'drop: errors'
:
function
(
assert
,
beforeExit
)
{
var
testIsFinished
=
false
,
sequelizeWithInvalidCredentials
=
new
Sequelize
(
'foo'
,
'bar'
,
'barfoos'
),
Fail
=
sequelizeWithInvalidCredentials
.
define
(
'Fail'
,
{})
sequelizeWithInvalidCredentials
.
drop
(
function
(
errors
)
{
assert
.
isDefined
(
errors
)
assert
.
equal
(
errors
.
length
,
1
)
testIsFinished
=
true
})
beforeExit
(
function
()
{
assert
.
equal
(
testIsFinished
,
true
)
})
}
}
}
}
\ No newline at end of file
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