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 edef6294
authored
Apr 10, 2013
by
Jochem Maas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP
1 parent
f54644e6
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
23 deletions
lib/dao.js
lib/dao.js
View file @
edef629
...
...
@@ -7,6 +7,7 @@ module.exports = (function() {
var
DAO
=
function
(
values
,
options
,
isNewRecord
)
{
var
self
=
this
this
.
dataValues
=
[]
this
.
__options
=
options
this
.
hasPrimaryKeys
=
options
.
hasPrimaryKeys
this
.
selectedValues
=
values
...
...
@@ -16,18 +17,9 @@ module.exports = (function() {
if
(
this
.
hasDefaultValues
)
{
Utils
.
_
.
each
(
this
.
defaultValues
,
function
(
value
,
name
)
{
if
(
typeof
self
[
name
]
===
'undefined'
)
{
self
.
addAttribute
(
name
,
value
());
}
})
}
if
(
this
.
booleanValues
.
length
)
{
this
.
booleanValues
.
forEach
(
function
(
name
)
{
//transform integer 0,1 into boolean
self
[
name
]
=
!!
self
[
name
];
});
}
}
Utils
.
_
.
extend
(
DAO
.
prototype
,
Mixin
.
prototype
)
...
...
@@ -42,7 +34,7 @@ module.exports = (function() {
Object
.
defineProperty
(
DAO
.
prototype
,
'isDeleted'
,
{
get
:
function
()
{
var
result
=
this
.
__options
.
timestamps
&&
this
.
__options
.
paranoid
result
=
result
&&
this
[
this
.
__options
.
underscored
?
'deleted_at'
:
'deletedAt'
]
!==
null
result
=
result
&&
this
.
dataValues
[
this
.
__options
.
underscored
?
'deleted_at'
:
'deletedAt'
]
!==
null
return
result
}
...
...
@@ -54,7 +46,7 @@ module.exports = (function() {
,
self
=
this
this
.
attributes
.
concat
(
this
.
__eagerlyLoadedAssociations
).
forEach
(
function
(
attr
)
{
result
[
attr
]
=
self
[
attr
]
result
[
attr
]
=
self
.
dataValues
[
attr
]
})
return
result
...
...
@@ -67,7 +59,7 @@ module.exports = (function() {
,
self
=
this
Utils
.
_
.
each
(
this
.
__factory
.
primaryKeys
,
function
(
_
,
attr
)
{
result
[
attr
]
=
self
[
attr
]
result
[
attr
]
=
self
.
dataValues
[
attr
]
})
return
result
...
...
@@ -85,7 +77,7 @@ module.exports = (function() {
}
primaryKeys
.
forEach
(
function
(
identifier
)
{
result
[
identifier
]
=
self
[
identifier
]
result
[
identifier
]
=
self
.
dataValues
[
identifier
]
})
return
result
...
...
@@ -111,9 +103,11 @@ module.exports = (function() {
}
}
var
tmpVals
=
self
.
values
fields
.
forEach
(
function
(
field
)
{
if
(
self
.
value
s
[
field
]
!==
undefined
)
{
values
[
field
]
=
self
.
value
s
[
field
]
if
(
tmpVal
s
[
field
]
!==
undefined
)
{
values
[
field
]
=
tmpVal
s
[
field
]
}
})
}
...
...
@@ -132,7 +126,7 @@ module.exports = (function() {
}
if
(
this
.
__options
.
timestamps
&&
this
.
hasOwnProperty
(
updatedAtAttr
))
{
this
[
updatedAtAttr
]
=
values
[
updatedAtAttr
]
=
Utils
.
now
()
this
.
dataValues
[
updatedAtAttr
]
=
values
[
updatedAtAttr
]
=
Utils
.
now
()
}
if
(
this
.
isNewRecord
)
{
...
...
@@ -277,7 +271,7 @@ module.exports = (function() {
DAO
.
prototype
.
destroy
=
function
()
{
if
(
this
.
__options
.
timestamps
&&
this
.
__options
.
paranoid
)
{
var
attr
=
this
.
__options
.
underscored
?
'deleted_at'
:
'deletedAt'
this
[
attr
]
=
new
Date
()
this
.
dataValues
[
attr
]
=
new
Date
()
return
this
.
save
()
}
else
{
var
identifier
=
this
.
__options
.
hasPrimaryKeys
?
this
.
primaryKeyValues
:
this
.
id
...
...
@@ -338,7 +332,27 @@ module.exports = (function() {
}
DAO
.
prototype
.
addAttribute
=
function
(
attribute
,
value
)
{
this
[
attribute
]
=
value
if
(
typeof
this
.
dataValues
[
attribute
]
!==
'undefined'
)
return
;
var
def
=
{},
predef
=
Object
.
getOwnPropertyDescriptor
(
this
,
attribute
),
isBool
=
this
.
booleanValues
.
length
&&
this
.
booleanValues
.
indexOf
(
attribute
)
!==
-
1
;
if
(
isBool
)
// transform integer 0,1 into boolean
value
=
!!
value
;
var
hasnot
=
function
(
which
)
{
return
!
predef
||
(
!
predef
.
hasOwnProperty
(
'value'
)
&&
!
predef
.
hasOwnProperty
(
which
));
};
if
(
hasnot
(
'get'
))
def
.
get
=
function
()
{
return
this
.
dataValues
[
attribute
];
};
if
(
hasnot
(
'set'
))
def
.
set
=
function
(
v
)
{
this
.
dataValues
[
attribute
]
=
v
;
};
if
(
Utils
.
_
.
size
(
def
))
Object
.
defineProperty
(
this
,
attribute
,
def
);
this
.
dataValues
[
attribute
]
=
value
;
}
DAO
.
prototype
.
setValidators
=
function
(
attribute
,
validators
)
{
...
...
@@ -374,11 +388,7 @@ module.exports = (function() {
if
(
Utils
.
_
.
size
(
defaults
))
{
for
(
var
attr
in
defaults
)
{
var
value
=
defaults
[
attr
]
if
(
!
this
.
hasOwnProperty
(
attr
))
{
this
.
addAttribute
(
attr
,
Utils
.
toDefaultValue
(
value
))
}
this
.
addAttribute
(
attr
,
Utils
.
toDefaultValue
(
defaults
[
attr
]))
}
}
}
...
...
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