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 67dc76e6
authored
Sep 20, 2014
by
Sveinn Fannar Kristjansson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support PostgreSQL JSON datatype in models
1 parent
572adf67
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
0 deletions
lib/data-types.js
lib/model.js
lib/data-types.js
View file @
67dc76e
...
@@ -404,6 +404,11 @@ module.exports = {
...
@@ -404,6 +404,11 @@ module.exports = {
HSTORE
:
'HSTORE'
,
HSTORE
:
'HSTORE'
,
/**
/**
* A JSON string column. Only available in postgres.
*/
JSON
:
'JSON'
,
/**
* A virtual value that is not stored in the DB. This could for example be useful if you want to provide a default value in your model
* A virtual value that is not stored in the DB. This could for example be useful if you want to provide a default value in your model
* that is returned to the user but not stored in the DB.
* that is returned to the user but not stored in the DB.
*
*
...
...
lib/model.js
View file @
67dc76e
...
@@ -248,6 +248,7 @@ module.exports = (function() {
...
@@ -248,6 +248,7 @@ module.exports = (function() {
this
.
_booleanAttributes
=
[];
this
.
_booleanAttributes
=
[];
this
.
_dateAttributes
=
[];
this
.
_dateAttributes
=
[];
this
.
_hstoreAttributes
=
[];
this
.
_hstoreAttributes
=
[];
this
.
_jsonAttributes
=
[];
this
.
_virtualAttributes
=
[];
this
.
_virtualAttributes
=
[];
this
.
_defaultValues
=
{};
this
.
_defaultValues
=
{};
this
.
Instance
.
prototype
.
validators
=
{};
this
.
Instance
.
prototype
.
validators
=
{};
...
@@ -261,6 +262,8 @@ module.exports = (function() {
...
@@ -261,6 +262,8 @@ module.exports = (function() {
self
.
_dateAttributes
.
push
(
name
);
self
.
_dateAttributes
.
push
(
name
);
}
else
if
(
type
===
DataTypes
.
HSTORE
)
{
}
else
if
(
type
===
DataTypes
.
HSTORE
)
{
self
.
_hstoreAttributes
.
push
(
name
);
self
.
_hstoreAttributes
.
push
(
name
);
}
else
if
(
type
===
DataTypes
.
JSON
)
{
self
.
_jsonAttributes
.
push
(
name
);
}
else
if
(
type
===
DataTypes
.
VIRTUAL
)
{
}
else
if
(
type
===
DataTypes
.
VIRTUAL
)
{
self
.
_virtualAttributes
.
push
(
name
);
self
.
_virtualAttributes
.
push
(
name
);
}
}
...
@@ -290,6 +293,11 @@ module.exports = (function() {
...
@@ -290,6 +293,11 @@ module.exports = (function() {
return
self
.
_hstoreAttributes
.
indexOf
(
key
)
!==
-
1
;
return
self
.
_hstoreAttributes
.
indexOf
(
key
)
!==
-
1
;
});
});
this
.
_hasJsonAttributes
=
!!
this
.
_jsonAttributes
.
length
;
this
.
_isJsonAttribute
=
Utils
.
_
.
memoize
(
function
(
key
)
{
return
self
.
_jsonAttributes
.
indexOf
(
key
)
!==
-
1
;
});
this
.
_hasVirtualAttributes
=
!!
this
.
_virtualAttributes
.
length
;
this
.
_hasVirtualAttributes
=
!!
this
.
_virtualAttributes
.
length
;
this
.
_isVirtualAttribute
=
Utils
.
_
.
memoize
(
function
(
key
)
{
this
.
_isVirtualAttribute
=
Utils
.
_
.
memoize
(
function
(
key
)
{
return
self
.
_virtualAttributes
.
indexOf
(
key
)
!==
-
1
;
return
self
.
_virtualAttributes
.
indexOf
(
key
)
!==
-
1
;
...
...
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