Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yafangsuo_dataServer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
node_server
yafangsuo_dataServer
Commits
23c2404c
Commit
23c2404c
authored
Sep 19, 2023
by
lixinming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no message
parent
b95faa3d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
92 additions
and
17 deletions
+92
-17
findData.ts
src/biz/mysql/findData.ts
+14
-13
updateData.ts
src/biz/mysql/updateData.ts
+78
-4
No files found.
src/biz/mysql/findData.ts
View file @
23c2404c
...
@@ -89,6 +89,7 @@ function analysisParamToWhere(param, column) {
...
@@ -89,6 +89,7 @@ function analysisParamToWhere(param, column) {
export
async
function
selectOneDataByParam
(
tableModel
,
param
,
column
)
{
export
async
function
selectOneDataByParam
(
tableModel
,
param
,
column
)
{
let
selectParam
=
analysisParamToWhere
(
param
,
column
);
let
selectParam
=
analysisParamToWhere
(
param
,
column
);
let
data
=
await
tableModel
.
findOne
(
selectParam
);
let
data
=
await
tableModel
.
findOne
(
selectParam
);
data
=
data
||
{};
return
{
data
};
return
{
data
};
}
}
...
@@ -151,10 +152,10 @@ export async function selectDataToTableAssociation(tableModel, includeConf, para
...
@@ -151,10 +152,10 @@ export async function selectDataToTableAssociation(tableModel, includeConf, para
let
include
=
[];
let
include
=
[];
for
(
let
tableName
in
includeConf
)
{
for
(
let
tableName
in
includeConf
)
{
if
(
!
mysqlModelMap
[
tableName
])
throw
new
BizError
(
ERRORENUM
.
不存在表
,
`尝试进行多表联查,但是不存在
${
tableName
}
`
);
if
(
!
mysqlModelMap
[
tableName
])
throw
new
BizError
(
ERRORENUM
.
不存在表
,
`尝试进行多表联查,但是不存在
${
tableName
}
`
);
include
.
push
({
let
{
where
,
column
}
=
includeConf
[
tableName
];
attributes
:
includeConf
[
tableName
],
let
includeInfomation
=
analysisParamToWhere
(
where
,
column
);
model
:
mysqlModelMap
[
tableName
]
includeInfomation
.
model
=
mysqlModelMap
[
tableName
];
}
);
include
.
push
(
includeInfomation
);
}
}
let
selectParam
:
any
=
analysisParamToWhere
(
param
,
column
);
let
selectParam
:
any
=
analysisParamToWhere
(
param
,
column
);
...
@@ -178,11 +179,10 @@ export async function selectDataToTableAssociationToPage(tableModel, includeConf
...
@@ -178,11 +179,10 @@ export async function selectDataToTableAssociationToPage(tableModel, includeConf
let
include
=
[];
let
include
=
[];
for
(
let
tableName
in
includeConf
)
{
for
(
let
tableName
in
includeConf
)
{
if
(
!
mysqlModelMap
[
tableName
])
throw
new
BizError
(
ERRORENUM
.
不存在表
,
`尝试进行多表联查,但是不存在
${
tableName
}
`
);
if
(
!
mysqlModelMap
[
tableName
])
throw
new
BizError
(
ERRORENUM
.
不存在表
,
`尝试进行多表联查,但是不存在
${
tableName
}
`
);
include
.
push
({
let
{
where
,
column
}
=
includeConf
[
tableName
];
attributes
:
includeConf
[
tableName
],
let
includeInfomation
=
analysisParamToWhere
(
where
,
column
);
model
:
mysqlModelMap
[
tableName
]
includeInfomation
.
model
=
mysqlModelMap
[
tableName
];
});
include
.
push
(
includeInfomation
);
// include.push({model:mysqlModelMap[tableName]});
}
}
let
selectParam
:
any
=
analysisParamToWhere
(
param
,
column
);
let
selectParam
:
any
=
analysisParamToWhere
(
param
,
column
);
...
@@ -207,15 +207,16 @@ export async function selectOneDataToTableAssociation(tableModel, includeConf, p
...
@@ -207,15 +207,16 @@ export async function selectOneDataToTableAssociation(tableModel, includeConf, p
let
include
=
[];
let
include
=
[];
for
(
let
tableName
in
includeConf
)
{
for
(
let
tableName
in
includeConf
)
{
if
(
!
mysqlModelMap
[
tableName
])
throw
new
BizError
(
ERRORENUM
.
不存在表
,
`尝试进行多表联查,但是不存在
${
tableName
}
`
);
if
(
!
mysqlModelMap
[
tableName
])
throw
new
BizError
(
ERRORENUM
.
不存在表
,
`尝试进行多表联查,但是不存在
${
tableName
}
`
);
include
.
push
({
let
{
where
,
column
}
=
includeConf
[
tableName
];
attributes
:
includeConf
[
tableName
],
let
includeInfomation
=
analysisParamToWhere
(
where
,
column
);
model
:
mysqlModelMap
[
tableName
]
includeInfomation
.
model
=
mysqlModelMap
[
tableName
];
}
);
include
.
push
(
includeInfomation
);
}
}
let
selectParam
:
any
=
analysisParamToWhere
(
param
,
column
);
let
selectParam
:
any
=
analysisParamToWhere
(
param
,
column
);
selectParam
.
include
=
include
;
selectParam
.
include
=
include
;
let
data
=
await
tableModel
.
findOne
(
selectParam
);
let
data
=
await
tableModel
.
findOne
(
selectParam
);
data
=
data
||
{};
return
{
data
};
return
{
data
};
}
}
src/biz/mysql/updateData.ts
View file @
23c2404c
import
{
Op
,
Sequelize
}
from
"sequelize"
;
/**
/**
* 批量修改数据
* where条件查询参数
* @param tableName 表名
* @param param
* @param data
* %like%:模糊查询 {列名: {"%like%": }}
* %gt%:大于 {列名: {"%gt%": }}
* %gte%:大于等于 {列名: {"%gte%": }}
* %lt%:小于 {列名: {"%lt%": }}
* %lte%:小于等于 {列名: {"%lte%": }}
* %between%:查询范围内数据 {列名: {"%between%": ["开始参数", "结束参数"]}} ---BETWEEN 开始参数 AND 结束参数
* %notBetween%:查询不在范围内数据 {列名: {"%notBetween%": ["开始参数", "结束参数"]}} ---NOT BETWEEN 开始参数 AND 结束参数
* %orderDesc%: order by DESC {"%orderDesc%": "列名"}
* %limit%: {"%limit%": 数量}
* @returns
* @returns
*/
*/
function
analysisParamToWhere
(
param
)
{
let
where
=
{};
let
order
=
[];
let
limit
=
0
;
for
(
let
key
in
param
)
{
if
(
typeof
param
[
key
]
==
"object"
)
{
where
[
key
]
=
{};
for
(
let
whereKey
in
param
[
key
]){
switch
(
whereKey
)
{
case
"%like%"
:
where
[
key
][
Op
.
like
]
=
`%
${
param
[
key
][
"%like%"
]}
%`
;
break
;
case
"%gt%"
:
where
[
key
][
Op
.
gt
]
=
param
[
key
][
"%gt%"
];
break
;
case
"%gte%"
:
where
[
key
][
Op
.
gte
]
=
param
[
key
][
"%gte%"
];
break
;
case
"%lt%"
:
where
[
key
][
Op
.
lt
]
=
param
[
key
][
"%lt%"
];
break
;
case
"%lte%"
:
where
[
key
][
Op
.
lte
]
=
param
[
key
][
"%lte%"
];
break
;
case
"%between%"
:
where
[
key
][
Op
.
between
]
=
param
[
key
][
"%between%"
];
break
;
case
"%notBetween%"
:
where
[
key
][
Op
.
notBetween
]
=
param
[
key
][
"%notBetween%"
];
break
;
case
"%in%"
:
where
[
key
][
Op
.
in
]
=
param
[
key
][
"%in%"
];
break
;
case
"%notIn%"
:
where
[
key
][
Op
.
notIn
]
=
param
[
key
][
"%notIn%"
];
break
;
}
}
}
else
{
switch
(
key
)
{
case
"%orderDesc%"
:
order
=
[[
Sequelize
.
col
(
param
[
key
]),
"DESC"
]];
break
;
case
"%orderAsc%"
:
order
=
[[
Sequelize
.
col
(
param
[
key
]),
"ASC"
]];
break
;
case
"%limit%"
:
limit
=
param
[
key
];
break
;
default
:
where
[
key
]
=
param
[
key
];
}
}
}
let
selectParam
:
any
=
{
where
};
if
(
order
&&
order
.
length
)
selectParam
.
order
=
order
;
if
(
limit
)
selectParam
.
limit
=
limit
;
return
selectParam
;
}
export
async
function
updateManyData
(
tableModel
,
param
:
object
,
data
:
object
)
{
export
async
function
updateManyData
(
tableModel
,
param
:
object
,
data
:
object
)
{
let
where
=
analysisParamToWhere
(
param
);
await
tableModel
.
update
(
data
,
{
where
:
param
}
);
await
tableModel
.
update
(
data
,
where
);
return
{
isSuccess
:
true
};
return
{
isSuccess
:
true
};
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment