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 d57a18f2
authored
Jul 23, 2010
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
minor refactoring + logic for valuesForUpdate
1 parent
f22e5e65
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
11 deletions
sequelize.js
specs.js
sequelize.js
View file @
d57a18f
...
@@ -124,18 +124,10 @@ var Helper = {
...
@@ -124,18 +124,10 @@ var Helper = {
result
=
[]
result
=
[]
Helper
.
Hash
.
keys
(
actualValues
).
forEach
(
function
(
key
)
{
Helper
.
Hash
.
keys
(
actualValues
).
forEach
(
function
(
key
)
{
var
value
=
null
,
var
value
=
actualValues
[
key
]
,
dataType
=
object
.
attributes
[
key
]
dataType
=
object
.
attributes
[
key
]
switch
(
dataType
)
{
result
.
push
(
Helper
.
transformValueByDataType
(
value
,
dataType
))
case
exports
.
Sequelize
.
INTEGER
:
value
=
actualValues
[
key
];
break
;
default
:
value
=
"'"
+
actualValues
[
key
]
+
"'"
}
result
.
push
(
value
)
})
})
return
result
return
result
...
@@ -145,8 +137,29 @@ var Helper = {
...
@@ -145,8 +137,29 @@ var Helper = {
return
Helper
.
Hash
.
keys
(
Helper
.
values
(
object
)).
join
(
", "
)
return
Helper
.
Hash
.
keys
(
Helper
.
values
(
object
)).
join
(
", "
)
},
},
get
valuesForUpdate
()
{
transformValueByDataType
:
function
(
value
,
dataType
)
{
var
result
=
null
switch
(
dataType
)
{
case
exports
.
Sequelize
.
INTEGER
:
result
=
value
;
break
;
default
:
result
=
"'"
+
value
+
"'"
}
return
result
},
valuesForUpdate
:
function
(
object
)
{
var
actualValues
=
Helper
.
values
(
object
),
result
=
[]
Helper
.
Hash
.
keys
(
actualValues
).
forEach
(
function
(
key
)
{
var
value
=
actualValues
[
key
],
dataType
=
object
.
attributes
[
key
]
result
.
push
([
key
,
Helper
.
transformValueByDataType
(
value
,
dataType
)].
join
(
" = "
))
})
return
result
.
join
(
", "
)
},
},
evaluateTemplate
:
function
(
template
,
replacements
)
{
evaluateTemplate
:
function
(
template
,
replacements
)
{
...
...
specs.js
View file @
d57a18f
...
@@ -160,5 +160,18 @@ vows.describe('SequelizeHelper').addBatch({
...
@@ -160,5 +160,18 @@ vows.describe('SequelizeHelper').addBatch({
'should be a comma seperated string'
:
function
(
day
)
{
'should be a comma seperated string'
:
function
(
day
)
{
assert
.
equal
(
SequelizeHelper
.
fieldsForInsertQuery
(
day
),
"name, foo"
)
assert
.
equal
(
SequelizeHelper
.
fieldsForInsertQuery
(
day
),
"name, foo"
)
}
}
},
'valuesForUpdate'
:
{
topic
:
function
()
{
var
s
=
new
Sequelize
(
'sequelize_test'
,
'test'
,
'test'
)
var
Day
=
s
.
define
(
'Day'
,
{
name
:
Sequelize
.
STRING
,
foo
:
Sequelize
.
INTEGER
})
return
new
Day
({
name
:
'Monday'
,
foo
:
2
})
},
'should return a string'
:
function
(
day
)
{
assert
.
isString
(
SequelizeHelper
.
valuesForUpdate
(
day
))
},
'should correctly render data'
:
function
(
day
)
{
assert
.
equal
(
SequelizeHelper
.
valuesForUpdate
(
day
),
"name = 'Monday', foo = 2"
)
}
}
}
}).
export
(
module
)
}).
export
(
module
)
\ 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