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 d6b272bf
authored
Mar 30, 2011
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added possibility to suppress sql logging by passing {logging: false} to sequelize
1 parent
776c6abe
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
6 deletions
lib/sequelize/model-definition.js
lib/sequelize/query.js
lib/sequelize/sequelize.js
test/Model/find-findAll-all.js
test/Model/sync-drop.js
lib/sequelize/model-definition.js
View file @
d6b272b
...
...
@@ -73,7 +73,7 @@ ModelDefinition.prototype.build = function(values) {
}
ModelDefinition
.
prototype
.
create
=
function
(
values
)
{
return
this
.
build
(
values
).
save
return
this
.
build
(
values
).
save
()
}
Utils
.
_
.
map
(
require
(
"./association-mixin"
).
classMethods
,
function
(
fct
,
name
)
{
ModelDefinition
.
prototype
[
name
]
=
fct
})
\ No newline at end of file
lib/sequelize/query.js
View file @
d6b272b
...
...
@@ -16,7 +16,8 @@ Query.prototype.run = function(query) {
database
:
this
.
config
.
database
})
console
.
log
(
'Executing: '
+
query
)
if
(
this
.
options
.
logging
)
console
.
log
(
'Executing: '
+
query
)
client
.
connect
()
client
.
query
(
query
,
function
(
err
,
results
,
fields
)
{
...
...
@@ -41,7 +42,6 @@ Query.prototype.onSuccess = function(query, results, fields) {
if
(
query
.
indexOf
(
'SELECT'
)
==
0
)
{
result
=
results
.
map
(
function
(
result
)
{
return
self
.
callee
.
build
(
result
)
})
console
.
log
(
this
.
options
)
if
(
this
.
options
.
plain
)
result
=
(
result
.
length
==
0
)
?
null
:
result
[
0
]
}
...
...
lib/sequelize/sequelize.js
View file @
d6b272b
...
...
@@ -7,7 +7,10 @@ var Sequelize = module.exports = function(database, username, password, options)
var
ModelManager
=
require
(
"./model-manager"
)
this
.
modelManager
=
new
ModelManager
(
this
)
this
.
options
=
Utils
.
_
.
reject
(
options
,
function
(
value
,
key
)
{
return
[
"host"
,
"port"
,
"disableTableNameModification"
].
indexOf
(
key
)
>
-
1
})
Utils
.
_
.
reject
(
options
,
function
(
_
,
key
)
{
return
[
"host"
,
"port"
,
"disableTableNameModification"
].
indexOf
(
key
)
>
-
1
})
this
.
options
=
options
this
.
config
=
{
database
:
database
,
username
:
username
,
...
...
@@ -27,6 +30,8 @@ var instanceMethods = {
},
query
:
function
(
sql
,
callee
,
options
)
{
options
=
options
||
{}
options
.
logging
=
this
.
options
.
hasOwnProperty
(
'logging'
)
?
this
.
options
.
logging
:
true
return
new
Query
(
this
.
config
,
callee
,
options
).
run
(
sql
)
}
}
...
...
test/Model/find-findAll-all.js
View file @
d6b272b
var
assert
=
require
(
"assert"
)
,
config
=
require
(
"./../config"
)
,
Sequelize
=
require
(
"./../../index"
)
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
})
module
.
exports
=
{
'all should return all created models'
:
function
(
beforeExit
)
{
var
User
=
sequelize
.
define
(
'User'
,
{
name
:
Sequelize
.
STRING
,
bio
:
Sequelize
.
TEXT
})
User
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
User
.
create
({
name
:
'foo'
,
bio
:
'foobar'
}).
on
(
'success'
,
function
()
{
User
.
create
({
name
:
'bar'
,
bio
:
'foobar'
}).
on
(
'success'
,
function
()
{
User
.
all
.
on
(
'success'
,
function
(
users
)
{
assert
.
eql
(
users
.
length
,
2
)
beforeExit
()
})
})
})
})
}
}
\ No newline at end of file
test/Model/sync-drop.js
View file @
d6b272b
var
assert
=
require
(
"assert"
)
,
config
=
require
(
"./../config"
)
,
Sequelize
=
require
(
"./../../index"
)
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
)
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
}
)
module
.
exports
=
{
'sync should work with correct database config'
:
function
(
beforeExit
)
{
...
...
@@ -12,7 +12,7 @@ module.exports = {
User
.
sync
().
on
(
'success'
,
beforeExit
)
},
'sync should fail with incorrect database config'
:
function
(
beforeExit
)
{
var
s
=
new
Sequelize
(
'foo'
,
'bar'
,
null
)
var
s
=
new
Sequelize
(
'foo'
,
'bar'
,
null
,
{
logging
:
false
}
)
var
User
=
s
.
define
(
'User'
,
{
name
:
Sequelize
.
STRING
,
bio
:
Sequelize
.
TEXT
...
...
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