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
0866f6e2
Commit
0866f6e2
authored
Aug 25, 2023
by
chenjinjing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no message
parent
15b097ce
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
35 deletions
+35
-35
selectData.ts
src/biz/mongo/selectData.ts
+7
-17
findData.ts
src/biz/mysql/findData.ts
+28
-6
modelBind.ts
src/model/modelBind.ts
+0
-12
No files found.
src/biz/mongo/selectData.ts
View file @
0866f6e2
...
@@ -9,28 +9,28 @@ import { BizError } from "../../util/bizError";
...
@@ -9,28 +9,28 @@ import { BizError } from "../../util/bizError";
* @param param
* @param param
* @returns
* @returns
*/
*/
export
async
function
selectOneDataByParam
(
tableName
:
string
,
column
:
any
,
param
:
any
)
{
export
async
function
selectOneDataByParam
(
tableName
:
string
,
param
:
any
)
{
let
model
=
modelMap
[
tableName
];
let
model
=
modelMap
[
tableName
];
if
(
!
model
)
throw
new
BizError
(
ERRORENUM
.
不存在表
);
if
(
!
model
)
throw
new
BizError
(
ERRORENUM
.
不存在表
);
let
data
=
model
.
findOnceData
(
column
,
param
);
let
data
=
model
.
findOnceData
(
param
);
return
{
data
};
return
{
data
};
}
}
export
async
function
selectDataListByParam
(
tableName
:
string
,
column
:
any
,
param
:
any
)
{
export
async
function
selectDataListByParam
(
tableName
:
string
,
param
:
any
)
{
let
model
=
modelMap
[
tableName
];
let
model
=
modelMap
[
tableName
];
if
(
!
model
)
throw
new
BizError
(
ERRORENUM
.
不存在表
);
if
(
!
model
)
throw
new
BizError
(
ERRORENUM
.
不存在表
);
let
data
=
model
.
findManyData
(
column
,
param
);
let
data
=
model
.
findManyData
(
param
);
return
{
data
};
return
{
data
};
}
}
export
async
function
selectDataListToPageByParam
(
tableName
:
string
,
column
:
any
,
param
:
any
,
pageNumber
:
number
,
pageSize
:
number
)
{
export
async
function
selectDataListToPageByParam
(
tableName
:
string
,
param
:
any
,
pageNumber
:
number
,
pageSize
:
number
)
{
pageSize
=
pageSize
||
10
;
pageSize
=
pageSize
||
10
;
let
model
=
modelMap
[
tableName
];
let
model
=
modelMap
[
tableName
];
if
(
!
model
)
throw
new
BizError
(
ERRORENUM
.
不存在表
);
if
(
!
model
)
throw
new
BizError
(
ERRORENUM
.
不存在表
);
let
data
=
model
.
findDataToPage
(
column
,
param
,
(
pageNumber
-
1
)
*
10
,
pageSize
);
let
data
=
model
.
findDataToPage
(
param
,
(
pageNumber
-
1
)
*
10
,
pageSize
);
return
{
data
};
return
{
data
};
}
}
...
@@ -51,13 +51,3 @@ export async function aggragateParam(tableName:string, param:any) {
...
@@ -51,13 +51,3 @@ export async function aggragateParam(tableName:string, param:any) {
return
{
data
};
return
{
data
};
}
}
\ No newline at end of file
export
async
function
selectDataToTableAssociation
(
tableName
:
string
,
associatedTable
:
string
,
column
:
any
,
param
:
any
)
{
let
model
=
modelMap
[
tableName
];
if
(
!
model
)
throw
new
BizError
(
ERRORENUM
.
不存在表
);
let
data
=
await
model
.
findDataToTableAssociation
(
associatedTable
,
column
,
param
);
return
{
data
};
}
\ No newline at end of file
src/biz/mysql/findData.ts
View file @
0866f6e2
...
@@ -21,9 +21,9 @@ function analysisParamToWhere(param) {
...
@@ -21,9 +21,9 @@ function analysisParamToWhere(param) {
* @param param
* @param param
* @returns
* @returns
*/
*/
export
async
function
selectOneDataByParam
(
tableModel
,
param
)
{
export
async
function
selectOneDataByParam
(
tableModel
,
column
:
any
,
param
)
{
let
where
=
analysisParamToWhere
(
param
);
let
where
=
analysisParamToWhere
(
param
);
let
data
=
tableModel
.
findOne
({
where
});
let
data
=
tableModel
.
findOne
({
attributes
:
column
,
where
});
return
{
data
};
return
{
data
};
}
}
...
@@ -34,9 +34,9 @@ export async function selectOneDataByParam(tableModel, param) {
...
@@ -34,9 +34,9 @@ export async function selectOneDataByParam(tableModel, param) {
* @param param
* @param param
* @returns
* @returns
*/
*/
export
async
function
selectDataListByParam
(
tableModel
,
param
:
any
)
{
export
async
function
selectDataListByParam
(
tableModel
,
column
:
any
,
param
:
any
)
{
let
where
=
analysisParamToWhere
(
param
);
let
where
=
analysisParamToWhere
(
param
);
let
data
=
tableModel
.
findAll
({
where
});
let
data
=
tableModel
.
findAll
({
attributes
:
column
,
where
});
return
{
data
};
return
{
data
};
}
}
...
@@ -49,10 +49,10 @@ export async function selectDataListByParam(tableModel, param:any) {
...
@@ -49,10 +49,10 @@ export async function selectDataListByParam(tableModel, param:any) {
* @param pageSize
* @param pageSize
* @returns
* @returns
*/
*/
export
async
function
selectDataListToPageByParam
(
tableModel
,
param
:
any
,
pageNumber
:
number
,
pageSize
:
number
)
{
export
async
function
selectDataListToPageByParam
(
tableModel
,
column
:
any
,
param
:
any
,
pageNumber
:
number
,
pageSize
:
number
)
{
pageSize
=
pageSize
||
10
;
pageSize
=
pageSize
||
10
;
let
where
=
analysisParamToWhere
(
param
);
let
where
=
analysisParamToWhere
(
param
);
let
data
=
tableModel
.
findAll
({
where
,
offset
:(
pageNumber
-
1
)
*
10
,
limit
:
pageSize
});
let
data
=
tableModel
.
findAll
({
attributes
:
column
,
where
,
offset
:(
pageNumber
-
1
)
*
10
,
limit
:
pageSize
});
return
{
data
};
return
{
data
};
}
}
...
@@ -71,3 +71,24 @@ export async function associationSelect(tableName:string, param:any) {
...
@@ -71,3 +71,24 @@ export async function associationSelect(tableName:string, param:any) {
return
{
data
};
return
{
data
};
}
}
/**
* 多表联查
* @param tableName
* @param associatedTable
* @param column
* @param param
* @returns
*/
export
async
function
selectDataToTableAssociation
(
tableModel
,
associatedTable
:
string
,
column
:
any
,
param
:
any
)
{
let
where
=
analysisParamToWhere
(
param
);
let
data
=
tableModel
.
findAll
({
include
:
[{
model
:
associatedTable
,
attributes
:
column
,
//指定关联表查询的字段
}],
where
});
return
{
data
};
}
\ No newline at end of file
src/model/modelBind.ts
View file @
0866f6e2
...
@@ -24,7 +24,6 @@ export async function initModel() {
...
@@ -24,7 +24,6 @@ export async function initModel() {
modelMap
[
tableName
].
findDataCount
=
findDataCountBind
;
modelMap
[
tableName
].
findDataCount
=
findDataCountBind
;
modelMap
[
tableName
].
findDataToPage
=
findDataToPageBind
;
modelMap
[
tableName
].
findDataToPage
=
findDataToPageBind
;
modelMap
[
tableName
].
aggragateData
=
aggragateDataBind
;
modelMap
[
tableName
].
aggragateData
=
aggragateDataBind
;
modelMap
[
tableName
].
findDataToTableAssociation
=
findDataToTableAssociationBind
;
}
}
}
}
...
@@ -75,14 +74,4 @@ async function aggragateDataBind(param) {
...
@@ -75,14 +74,4 @@ async function aggragateDataBind(param) {
}
}
async
function
findDataToTableAssociationBind
(
associatedTable
:
string
,
column
:
any
,
param
:
any
)
{
return
await
this
.
find
({
include
:
[{
model
:
associatedTable
,
attributes
:
column
,
//指定关联表查询的字段
}],
where
:
param
})
}
export
{
modelMap
};
export
{
modelMap
};
\ 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