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
15b097ce
Commit
15b097ce
authored
Aug 25, 2023
by
chenjinjing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no message
parent
90b13405
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
127 additions
and
43 deletions
+127
-43
selectData.ts
src/biz/mongo/selectData.ts
+17
-6
mysqlTableConfig.ts
src/config/mysqlTableConfig.ts
+74
-29
modelBind.ts
src/model/modelBind.ts
+19
-7
sqlModelBind.ts
src/model/sqlModelBind.ts
+17
-1
No files found.
src/biz/mongo/selectData.ts
View file @
15b097ce
...
@@ -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
,
param
:
any
)
{
export
async
function
selectOneDataByParam
(
tableName
:
string
,
column
:
any
,
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
(
param
);
let
data
=
model
.
findOnceData
(
column
,
param
);
return
{
data
};
return
{
data
};
}
}
export
async
function
selectDataListByParam
(
tableName
:
string
,
param
:
any
)
{
export
async
function
selectDataListByParam
(
tableName
:
string
,
column
:
any
,
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
(
param
);
let
data
=
model
.
findManyData
(
column
,
param
);
return
{
data
};
return
{
data
};
}
}
export
async
function
selectDataListToPageByParam
(
tableName
:
string
,
param
:
any
,
pageNumber
:
number
,
pageSize
:
number
)
{
export
async
function
selectDataListToPageByParam
(
tableName
:
string
,
column
:
any
,
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
(
param
,
(
pageNumber
-
1
)
*
10
,
pageSize
);
let
data
=
model
.
findDataToPage
(
column
,
param
,
(
pageNumber
-
1
)
*
10
,
pageSize
);
return
{
data
};
return
{
data
};
}
}
...
@@ -50,4 +50,14 @@ export async function aggragateParam(tableName:string, param:any) {
...
@@ -50,4 +50,14 @@ export async function aggragateParam(tableName:string, param:any) {
let
data
=
await
model
.
aggragateData
(
param
);
let
data
=
await
model
.
aggragateData
(
param
);
return
{
data
};
return
{
data
};
}
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/config/mysqlTableConfig.ts
View file @
15b097ce
...
@@ -13,7 +13,8 @@ export const TablesConfig = {
...
@@ -13,7 +13,8 @@ export const TablesConfig = {
unique
:
true
//表示该列的值必须唯一
unique
:
true
//表示该列的值必须唯一
},
},
branchName
:
{
type
:
Sequelize
.
STRING
(
100
),
allowNull
:
false
},
//支部名称
branchName
:
{
type
:
Sequelize
.
STRING
(
100
),
allowNull
:
false
},
//支部名称
}
},
association
:
[{}]
},
},
"后台用户表"
:{
"后台用户表"
:{
tableName
:
'adminUser'
,
tableName
:
'adminUser'
,
...
@@ -28,7 +29,8 @@ export const TablesConfig = {
...
@@ -28,7 +29,8 @@ export const TablesConfig = {
pwd
:{
type
:
Sequelize
.
STRING
(
100
),
allowNull
:
false
},
//密码
pwd
:{
type
:
Sequelize
.
STRING
(
100
),
allowNull
:
false
},
//密码
token
:{
type
:
Sequelize
.
STRING
(
100
),
allowNull
:
false
},
token
:{
type
:
Sequelize
.
STRING
(
100
),
allowNull
:
false
},
tokenMs
:{
type
:
Sequelize
.
DATE
,
allowNull
:
false
}
tokenMs
:{
type
:
Sequelize
.
DATE
,
allowNull
:
false
}
}
},
association
:
[{}]
},
},
"党员基础信息表"
:{
"党员基础信息表"
:{
tableName
:
'partyMember'
,
tableName
:
'partyMember'
,
...
@@ -63,7 +65,13 @@ export const TablesConfig = {
...
@@ -63,7 +65,13 @@ export const TablesConfig = {
tokenMs
:{
type
:
Sequelize
.
DATE
,
allowNull
:
false
},
tokenMs
:{
type
:
Sequelize
.
DATE
,
allowNull
:
false
},
adminToken
:{
type
:
Sequelize
.
STRING
(
100
),
allowNull
:
false
},
adminToken
:{
type
:
Sequelize
.
STRING
(
100
),
allowNull
:
false
},
adminTokenMs
:{
type
:
Sequelize
.
DATE
,
allowNull
:
false
},
adminTokenMs
:{
type
:
Sequelize
.
DATE
,
allowNull
:
false
},
}
},
association
:
[
{
type
:
"hasOne"
,
table1
:
"branch"
,
table2
:
"partyMember"
},
{
type
:
"hasOne"
,
table1
:
"administrativePosition"
,
table2
:
"partyMember"
},
{
type
:
"hasMany"
,
table1
:
"partyPositions"
,
table2
:
"partyMember"
},
{
type
:
"hasMany"
,
table1
:
"department"
,
table2
:
"partyMember"
},
]
},
},
"行政职务表"
:{
"行政职务表"
:{
tableName
:
'administrativePosition'
,
tableName
:
'administrativePosition'
,
...
@@ -76,7 +84,8 @@ export const TablesConfig = {
...
@@ -76,7 +84,8 @@ export const TablesConfig = {
unique
:
true
//表示该列的值必须唯一
unique
:
true
//表示该列的值必须唯一
},
},
administrativePositionName
:
{
type
:
Sequelize
.
STRING
(
100
),
allowNull
:
false
}
administrativePositionName
:
{
type
:
Sequelize
.
STRING
(
100
),
allowNull
:
false
}
}
},
association
:
[{}]
},
},
"党内职务表"
:{
"党内职务表"
:{
tableName
:
'partyPositions'
,
tableName
:
'partyPositions'
,
...
@@ -89,7 +98,8 @@ export const TablesConfig = {
...
@@ -89,7 +98,8 @@ export const TablesConfig = {
unique
:
true
//表示该列的值必须唯一
unique
:
true
//表示该列的值必须唯一
},
},
partyPositionsName
:
{
type
:
Sequelize
.
STRING
(
100
),
allowNull
:
false
}
partyPositionsName
:
{
type
:
Sequelize
.
STRING
(
100
),
allowNull
:
false
}
}
},
association
:
[{}]
},
},
"所属科室表"
:{
"所属科室表"
:{
tableName
:
'department'
,
tableName
:
'department'
,
...
@@ -102,7 +112,8 @@ export const TablesConfig = {
...
@@ -102,7 +112,8 @@ export const TablesConfig = {
unique
:
true
//表示该列的值必须唯一
unique
:
true
//表示该列的值必须唯一
},
},
departmentName
:
{
type
:
Sequelize
.
STRING
(
100
),
allowNull
:
false
}
departmentName
:
{
type
:
Sequelize
.
STRING
(
100
),
allowNull
:
false
}
}
},
association
:
[{}]
},
},
"支部制度表"
:{
"支部制度表"
:{
tableName
:
'branchSystem'
,
tableName
:
'branchSystem'
,
...
@@ -122,7 +133,10 @@ export const TablesConfig = {
...
@@ -122,7 +133,10 @@ export const TablesConfig = {
fileName
:
{
type
:
Sequelize
.
STRING
(
100
),
allowNull
:
false
,
defaultValue
:
'[]'
},
//文件名称 ["",""] --多选
fileName
:
{
type
:
Sequelize
.
STRING
(
100
),
allowNull
:
false
,
defaultValue
:
'[]'
},
//文件名称 ["",""] --多选
fileType
:
{
type
:
Sequelize
.
INTEGER
,
allowNull
:
false
},
//文件类型
fileType
:
{
type
:
Sequelize
.
INTEGER
,
allowNull
:
false
},
//文件类型
uploadTime
:
{
type
:
Sequelize
.
DATE
,
allowNull
:
false
,
defaultValue
:
Sequelize
.
NOW
},
//上传时间
uploadTime
:
{
type
:
Sequelize
.
DATE
,
allowNull
:
false
,
defaultValue
:
Sequelize
.
NOW
},
//上传时间
}
},
association
:
[
{
type
:
"hasMany"
,
table1
:
"branch"
,
table2
:
"branchSystem"
}
]
},
},
"组织生活表"
:{
"组织生活表"
:{
tableName
:
'organizationalLife'
,
tableName
:
'organizationalLife'
,
...
@@ -141,7 +155,10 @@ export const TablesConfig = {
...
@@ -141,7 +155,10 @@ export const TablesConfig = {
fileName
:
{
type
:
Sequelize
.
STRING
(
100
),
allowNull
:
false
,
defaultValue
:
'[]'
},
//文件名称 ["",""] --多选
fileName
:
{
type
:
Sequelize
.
STRING
(
100
),
allowNull
:
false
,
defaultValue
:
'[]'
},
//文件名称 ["",""] --多选
fileType
:
{
type
:
Sequelize
.
INTEGER
,
allowNull
:
false
},
//文件类型
fileType
:
{
type
:
Sequelize
.
INTEGER
,
allowNull
:
false
},
//文件类型
uploadTime
:
{
type
:
Sequelize
.
DATE
,
allowNull
:
false
,
defaultValue
:
Sequelize
.
NOW
},
//上传时间
uploadTime
:
{
type
:
Sequelize
.
DATE
,
allowNull
:
false
,
defaultValue
:
Sequelize
.
NOW
},
//上传时间
}
},
association
:
[
{
type
:
"hasMany"
,
table1
:
"branch"
,
table2
:
"organizationalLife"
}
]
},
},
"专题活动表"
:{
"专题活动表"
:{
tableName
:
'thematicActivities'
,
tableName
:
'thematicActivities'
,
...
@@ -159,7 +176,10 @@ export const TablesConfig = {
...
@@ -159,7 +176,10 @@ export const TablesConfig = {
fileName
:
{
type
:
Sequelize
.
STRING
(
100
),
allowNull
:
false
,
defaultValue
:
'[]'
},
//文件名称 ["",""] --多选
fileName
:
{
type
:
Sequelize
.
STRING
(
100
),
allowNull
:
false
,
defaultValue
:
'[]'
},
//文件名称 ["",""] --多选
fileType
:
{
type
:
Sequelize
.
INTEGER
,
allowNull
:
false
},
//文件类型
fileType
:
{
type
:
Sequelize
.
INTEGER
,
allowNull
:
false
},
//文件类型
uploadTime
:
{
type
:
Sequelize
.
DATE
,
allowNull
:
false
,
defaultValue
:
Sequelize
.
NOW
},
//上传时间
uploadTime
:
{
type
:
Sequelize
.
DATE
,
allowNull
:
false
,
defaultValue
:
Sequelize
.
NOW
},
//上传时间
}
},
association
:
[
{
type
:
"hasMany"
,
table1
:
"branch"
,
table2
:
"thematicActivities"
}
]
},
},
"党建动态表"
:{
"党建动态表"
:{
tableName
:
'partyBuildingDynamic'
,
tableName
:
'partyBuildingDynamic'
,
...
@@ -177,7 +197,10 @@ export const TablesConfig = {
...
@@ -177,7 +197,10 @@ export const TablesConfig = {
fileName
:
{
type
:
Sequelize
.
STRING
(
100
),
allowNull
:
false
,
defaultValue
:
'[]'
},
//文件名称 ["",""] --多选
fileName
:
{
type
:
Sequelize
.
STRING
(
100
),
allowNull
:
false
,
defaultValue
:
'[]'
},
//文件名称 ["",""] --多选
fileType
:
{
type
:
Sequelize
.
INTEGER
,
allowNull
:
false
},
//文件类型
fileType
:
{
type
:
Sequelize
.
INTEGER
,
allowNull
:
false
},
//文件类型
uploadTime
:
{
type
:
Sequelize
.
DATE
,
allowNull
:
false
,
defaultValue
:
Sequelize
.
NOW
},
//上传时间
uploadTime
:
{
type
:
Sequelize
.
DATE
,
allowNull
:
false
,
defaultValue
:
Sequelize
.
NOW
},
//上传时间
}
},
association
:
[
{
type
:
"hasMany"
,
table1
:
"branch"
,
table2
:
"partyBuildingDynamic"
}
]
},
},
"党费管理表"
:{
"党费管理表"
:{
tableName
:
'partyExpenses'
,
tableName
:
'partyExpenses'
,
...
@@ -195,7 +218,11 @@ export const TablesConfig = {
...
@@ -195,7 +218,11 @@ export const TablesConfig = {
bId
:
{
type
:
Sequelize
.
STRING
(
100
),
allowNull
:
false
,
defaultValue
:
'[]'
},
//支部表id 外键 [1,2] --多选
bId
:
{
type
:
Sequelize
.
STRING
(
100
),
allowNull
:
false
,
defaultValue
:
'[]'
},
//支部表id 外键 [1,2] --多选
payTime
:
{
type
:
Sequelize
.
DATE
,
allowNull
:
true
},
//缴费时间
payTime
:
{
type
:
Sequelize
.
DATE
,
allowNull
:
true
},
//缴费时间
payAmount
:
{
type
:
Sequelize
.
INTEGER
,
allowNull
:
false
},
//缴费金额(元)
payAmount
:
{
type
:
Sequelize
.
INTEGER
,
allowNull
:
false
},
//缴费金额(元)
}
},
association
:
[
{
type
:
"hasMany"
,
table1
:
"partyMember"
,
table2
:
"partyExpenses"
},
{
type
:
"hasMany"
,
table1
:
"branch"
,
table2
:
"partyExpenses"
}
]
},
},
"党建先锋表"
:{
"党建先锋表"
:{
tableName
:
'partyVanguard'
,
tableName
:
'partyVanguard'
,
...
@@ -214,7 +241,24 @@ export const TablesConfig = {
...
@@ -214,7 +241,24 @@ export const TablesConfig = {
grantTime
:
{
type
:
Sequelize
.
DATE
,
allowNull
:
false
},
//授予时间
grantTime
:
{
type
:
Sequelize
.
DATE
,
allowNull
:
false
},
//授予时间
bId
:
{
type
:
Sequelize
.
STRING
(
100
),
allowNull
:
false
,
defaultValue
:
'[]'
},
//支部表id 外键 [1,2] --多选
bId
:
{
type
:
Sequelize
.
STRING
(
100
),
allowNull
:
false
,
defaultValue
:
'[]'
},
//支部表id 外键 [1,2] --多选
isUse
:
{
type
:
Sequelize
.
BOOLEAN
,
allowNull
:
false
,
defaultValue
:
true
},
//是否使用
isUse
:
{
type
:
Sequelize
.
BOOLEAN
,
allowNull
:
false
,
defaultValue
:
true
},
//是否使用
}
},
association
:
[
{
type
:
"hasMany"
,
table1
:
"branch"
,
table2
:
"partyVanguard"
}
]
},
"课程类型"
:{
tableName
:
'courseType'
,
schema
:{
ctId
:
{
type
:
Sequelize
.
INTEGER
(
20
),
//表示属性的数据类型
allowNull
:
false
,
//表示当前列是否允许为空, false表示该列不能为空
primaryKey
:
true
,
//表示主键
autoIncrement
:
true
,
//允许自增
unique
:
true
//表示该列的值必须唯一
},
courseTypeName
:
{
type
:
Sequelize
.
STRING
(
100
),
allowNull
:
false
}
},
association
:
[{}]
},
},
"党员学习表"
:{
"党员学习表"
:{
tableName
:
'memberLearning'
,
tableName
:
'memberLearning'
,
...
@@ -234,7 +278,10 @@ export const TablesConfig = {
...
@@ -234,7 +278,10 @@ export const TablesConfig = {
fileName
:
{
type
:
Sequelize
.
STRING
(
100
),
allowNull
:
false
,
defaultValue
:
'[]'
},
//文件名称 ["",""] --多选
fileName
:
{
type
:
Sequelize
.
STRING
(
100
),
allowNull
:
false
,
defaultValue
:
'[]'
},
//文件名称 ["",""] --多选
fileType
:
{
type
:
Sequelize
.
INTEGER
,
allowNull
:
false
},
//文件类型
fileType
:
{
type
:
Sequelize
.
INTEGER
,
allowNull
:
false
},
//文件类型
uploadTime
:
{
type
:
Sequelize
.
DATE
,
allowNull
:
false
,
defaultValue
:
Sequelize
.
NOW
},
//上传时间
uploadTime
:
{
type
:
Sequelize
.
DATE
,
allowNull
:
false
,
defaultValue
:
Sequelize
.
NOW
},
//上传时间
}
},
association
:
[
{
type
:
"hasOne"
,
table1
:
"courseType"
,
table2
:
"memberLearning"
}
]
},
},
"学习进度表"
:{
"学习进度表"
:{
tableName
:
'rateLearning'
,
tableName
:
'rateLearning'
,
...
@@ -250,20 +297,11 @@ export const TablesConfig = {
...
@@ -250,20 +297,11 @@ export const TablesConfig = {
mlId
:
{
type
:
Sequelize
.
INTEGER
,
allowNull
:
false
},
//党员学习id 外键
mlId
:
{
type
:
Sequelize
.
INTEGER
,
allowNull
:
false
},
//党员学习id 外键
rateOfLearning
:
{
type
:
Sequelize
.
INTEGER
,
allowNull
:
false
,
defaultValue
:
0
},
//学习进度
rateOfLearning
:
{
type
:
Sequelize
.
INTEGER
,
allowNull
:
false
,
defaultValue
:
0
},
//学习进度
learningCompleted
:
{
type
:
Sequelize
.
INTEGER
,
allowNull
:
false
,
defaultValue
:
1
}
//是否已完成 1:正在进行、2:阅读完成
learningCompleted
:
{
type
:
Sequelize
.
INTEGER
,
allowNull
:
false
,
defaultValue
:
1
}
//是否已完成 1:正在进行、2:阅读完成
}
},
},
association
:
[
"课程类型"
:{
{
type
:
"hasOne"
,
table1
:
"partyMember"
,
table2
:
"rateLearning"
},
tableName
:
'courseType'
,
{
type
:
"hasOne"
,
table1
:
"memberLearning"
,
table2
:
"rateLearning"
}
schema
:{
]
ctId
:
{
type
:
Sequelize
.
INTEGER
(
20
),
//表示属性的数据类型
allowNull
:
false
,
//表示当前列是否允许为空, false表示该列不能为空
primaryKey
:
true
,
//表示主键
autoIncrement
:
true
,
//允许自增
unique
:
true
//表示该列的值必须唯一
},
courseTypeName
:
{
type
:
Sequelize
.
STRING
(
100
),
allowNull
:
false
}
}
},
},
"学习强国"
:{
"学习强国"
:{
tableName
:
'learningPower'
,
tableName
:
'learningPower'
,
...
@@ -282,7 +320,10 @@ export const TablesConfig = {
...
@@ -282,7 +320,10 @@ export const TablesConfig = {
fileName
:
{
type
:
Sequelize
.
STRING
(
100
),
allowNull
:
false
,
defaultValue
:
'[]'
},
//文件名称 ["",""] --多选
fileName
:
{
type
:
Sequelize
.
STRING
(
100
),
allowNull
:
false
,
defaultValue
:
'[]'
},
//文件名称 ["",""] --多选
fileType
:
{
type
:
Sequelize
.
INTEGER
,
allowNull
:
false
},
//文件类型
fileType
:
{
type
:
Sequelize
.
INTEGER
,
allowNull
:
false
},
//文件类型
uploadTime
:
{
type
:
Sequelize
.
DATE
,
allowNull
:
false
,
defaultValue
:
Sequelize
.
NOW
},
//上传时间
uploadTime
:
{
type
:
Sequelize
.
DATE
,
allowNull
:
false
,
defaultValue
:
Sequelize
.
NOW
},
//上传时间
}
},
association
:
[
{
type
:
"hasMany"
,
table1
:
"branch"
,
table2
:
"learningPower"
}
]
},
},
"党建质量"
:{
"党建质量"
:{
tableName
:
'partyQuality'
,
tableName
:
'partyQuality'
,
...
@@ -302,6 +343,9 @@ export const TablesConfig = {
...
@@ -302,6 +343,9 @@ export const TablesConfig = {
totalScore
:
{
type
:
Sequelize
.
INTEGER
,
allowNull
:
false
,
defaultValue
:
0
},
//总分
totalScore
:
{
type
:
Sequelize
.
INTEGER
,
allowNull
:
false
,
defaultValue
:
0
},
//总分
currentScore
:
{
type
:
Sequelize
.
INTEGER
,
allowNull
:
false
,
defaultValue
:
0
},
//当前得分
currentScore
:
{
type
:
Sequelize
.
INTEGER
,
allowNull
:
false
,
defaultValue
:
0
},
//当前得分
completionProgress
:
{
type
:
Sequelize
.
STRING
(
100
),
allowNull
:
false
}
//完成进度
completionProgress
:
{
type
:
Sequelize
.
STRING
(
100
),
allowNull
:
false
}
//完成进度
}
},
association
:
[
{
type
:
"hasMany"
,
table1
:
"branch"
,
table2
:
"partyQuality"
}
]
},
},
}
}
\ No newline at end of file
src/model/modelBind.ts
View file @
15b097ce
...
@@ -23,7 +23,8 @@ export async function initModel() {
...
@@ -23,7 +23,8 @@ export async function initModel() {
modelMap
[
tableName
].
findManyData
=
findManyDataBind
;
modelMap
[
tableName
].
findManyData
=
findManyDataBind
;
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
;
}
}
}
}
...
@@ -49,13 +50,13 @@ async function deleteOneBind(param) {
...
@@ -49,13 +50,13 @@ async function deleteOneBind(param) {
}
}
async
function
findOnceDataBind
(
param
)
{
async
function
findOnceDataBind
(
column
,
param
)
{
return
await
this
.
findOne
(
param
);
return
await
this
.
findOne
(
{
attribute
:
column
,
where
:
param
}
);
}
}
async
function
findManyDataBind
(
param
)
{
async
function
findManyDataBind
(
column
,
param
)
{
return
await
this
.
find
(
param
);
return
await
this
.
find
(
{
attribute
:
column
,
where
:
param
}
);
}
}
...
@@ -64,8 +65,8 @@ async function findDataCountBind(param) {
...
@@ -64,8 +65,8 @@ async function findDataCountBind(param) {
}
}
async
function
findDataToPageBind
(
param
,
skipCount
:
number
,
limit
:
number
)
{
async
function
findDataToPageBind
(
column
,
param
,
skipCount
:
number
,
limit
:
number
)
{
return
await
this
.
find
(
param
).
skip
(
skipCount
).
limit
(
limit
);
return
await
this
.
find
(
{
attribute
:
column
,
where
:
param
}
).
skip
(
skipCount
).
limit
(
limit
);
}
}
...
@@ -74,4 +75,14 @@ async function aggragateDataBind(param) {
...
@@ -74,4 +75,14 @@ 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
src/model/sqlModelBind.ts
View file @
15b097ce
...
@@ -9,7 +9,7 @@ let baseDB = {};
...
@@ -9,7 +9,7 @@ let baseDB = {};
export
async
function
initMysqlModel
()
{
export
async
function
initMysqlModel
()
{
for
(
let
tableNameCN
in
TablesConfig
)
{
for
(
let
tableNameCN
in
TablesConfig
)
{
let
{
tableName
,
schema
}
=
TablesConfig
[
tableNameCN
];
let
{
tableName
,
schema
,
association
}
=
TablesConfig
[
tableNameCN
];
let
schemaConf
=
{
let
schemaConf
=
{
freezeTableName
:
true
,
//true表示使用给定的表名,false表示模型名后加s作为表名
freezeTableName
:
true
,
//true表示使用给定的表名,false表示模型名后加s作为表名
...
@@ -17,10 +17,25 @@ export async function initMysqlModel() {
...
@@ -17,10 +17,25 @@ export async function initMysqlModel() {
};
};
let
model
=
mysqlDB
.
define
(
tableName
,
schema
,
schemaConf
);
let
model
=
mysqlDB
.
define
(
tableName
,
schema
,
schemaConf
);
baseDB
[
tableName
]
=
model
.
sync
({}).
then
();
baseDB
[
tableName
]
=
model
.
sync
({}).
then
();
association
.
forEach
(
item
=>
{
if
(
item
)
{
let
{
type
,
table1
,
table2
}
=
item
;
if
(
type
==
"hasOne"
)
{
table1
.
hasOne
(
table2
);
table2
.
belongsTo
(
table1
);
}
else
if
(
type
==
"hasMany"
)
{
table1
.
hasMany
(
table2
);
table2
.
belongsTo
(
table1
);
}
}
})
}
}
}
}
export
{
baseDB
};
export
{
baseDB
};
\ 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