Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ncov
/
back
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
lintry
2020-01-29 21:12:35 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
3526e0f2d9d561e6af5a8d7b7fcf1358a5a35d57
3526e0f2
1 parent
54dbbf26
更新sequelize的初始化设置
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
8 deletions
server/init/sequelize-init.js
server/init/sequelize-init.js
View file @
3526e0f
...
...
@@ -9,6 +9,10 @@ global.sequelize = global.sequelize = function () {
const
config
=
require
(
'./config'
),
config_sequelize
=
config
.
sequelize
;
// 处理浮点数及大整型数据返回时不转换成String
Sequelize
.
postgres
.
DECIMAL
.
parse
=
function
(
value
)
{
return
parseFloat
(
value
);
};
Sequelize
.
postgres
.
BIGINT
.
parse
=
function
(
value
)
{
return
parseInt
(
value
);
};
//custom method defined here
config_sequelize
.
options
.
define
=
{
classMethods
:
{
...
...
@@ -24,7 +28,7 @@ global.sequelize = global.sequelize = function () {
//根据主键查找是否存在
let
primaryKey
=
Entity
.
primaryKeyAttribute
;
return
Entity
.
findBy
Id
(
entityRequest
[
primaryKey
]
)
return
Entity
.
findBy
Pk
(
entityRequest
[
primaryKey
],
options
)
.
then
(
function
(
entity
)
{
if
(
entity
)
{
//to update
return
entity
.
update
(
entityRequest
,
options
);
...
...
@@ -52,7 +56,7 @@ global.sequelize = global.sequelize = function () {
}
//根据主键查找是否存在
let
primaryKey
=
Entity
.
primaryKeyAttribute
;
return
Entity
.
findBy
Id
(
entityRequest
[
primaryKey
]
)
return
Entity
.
findBy
Pk
(
entityRequest
[
primaryKey
],
options
)
.
then
(
function
(
entity
)
{
if
(
entity
)
{
//to update
return
entity
.
update
(
entityRequest
,
options
);
...
...
@@ -83,12 +87,6 @@ global.sequelize = global.sequelize = function () {
logger
.
info
(
'db init finished!'
);
}
// 兼容4.0模式,添加属性
sequelize
.
Op
=
Sequelize
.
Op
;
sequelize
.
Transaction
=
Sequelize
.
Transaction
;
sequelize
.
Model
=
Sequelize
.
Model
;
sequelize
.
Utils
=
Sequelize
.
Utils
;
return
sequelize
;
}();
...
...
Please
register
or
login
to post a comment